Skip to content

Commit e8246de

Browse files
committed
exercise #1 done~
1 parent 1fb7433 commit e8246de

File tree

3 files changed

+23
-81
lines changed

3 files changed

+23
-81
lines changed

docs/exercise_1.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,32 @@ Exercise #1: Vector addition
55
A. Preparation
66
---------------
77

8-
1. Install ``py.test``:: ``pip install pytest``
8+
1. Install ``py.test``: ``$ pip install pytest``
99

10-
2. Clone or download repo at https://github.com/fluentpython/pythonic-api
10+
2. Clone repo at https://github.com/fluentpython/pythonic-api. You can also download a ``.zip`` file with the repository.
1111

1212

13-
B. Vector unary ``-``
14-
---------------------
13+
B. Vector negation
14+
------------------
1515

1616
1. Go to ``exercises/vector`` directory
1717

18-
2. Run the tests: ``py.test``
18+
2. Run test for unary ``-`` with the ``-x`` option to stop at first error or failure:
1919

20-
3. Open the ``vector/vector.py``.
20+
.. code-block:: shell
21+
22+
$ py.test -x test_vector_neg.py
23+
24+
3. Edit ``vector.py`` to implement a ``__neg__`` method for unary negation. That method should return a new ``Vector`` instance with each component negated. See ``test_vector_neg.py`` for the expected behavior.
25+
26+
27+
C. Vector addition
28+
------------------
29+
30+
1. Run tests for vector addition ``+`` with the ``-x`` option to stop at first error or failure:
31+
32+
.. code-block:: shell
33+
34+
$ py.test -x test_vector_add.py
35+
36+
2. Edit ``vector.py`` to implement a ``__add__`` method for vector addition. That method should return a new ``Vector`` instance with each component of ``self`` added to the corresponding component of ``other``. See ``test_vector_add.py`` for the expected behaviors.

docs/inspiration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ With ``py.test``:
7171

7272
.. literalinclude:: ../exercises/vector/test_vector_neg.py
7373

74+
.. literalinclude:: ../exercises/vector/test_vector_add.py
7475

7576
With ``unittest``:
7677

exercises/vector/vector.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)