You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/exercise_1.rst
+22-6Lines changed: 22 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,32 @@ Exercise #1: Vector addition
5
5
A. Preparation
6
6
---------------
7
7
8
-
1. Install ``py.test``:: ``pip install pytest``
8
+
1. Install ``py.test``: ``$ pip install pytest``
9
9
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.
11
11
12
12
13
-
B. Vector unary ``-``
14
-
---------------------
13
+
B. Vector negation
14
+
------------------
15
15
16
16
1. Go to ``exercises/vector`` directory
17
17
18
-
2. Run the tests: ``py.test``
18
+
2. Run test for unary ``-`` with the ``-x`` option to stop at first error or failure:
19
19
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.
0 commit comments