Skip to content

Commit 3eaada2

Browse files
committed
fix tests and such
1 parent db52c33 commit 3eaada2

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ repos:
1212
- flake8-import-order
1313
args:
1414
- "-j8"
15-
- "--ignore=E203,E501,P103"
15+
- "--ignore=E203,E501,P103,D105"
1616
- "--docstring-convention=numpy"
1717
- "--import-order-style=edited"

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ a pull request. You can check the status of the GH actions (a separate window wi
99
be inserted in the PR screen) to see how your implementation is doing. Remember what
1010
you learned from the style assignment, readability still counts.
1111

12+
When you are finished with *both* tasks, create a new PR and ping the instructors
13+
(@opensourcecourse/instructors).
1214

1315
# Task 1: Fun with classes (5 pts)
1416

@@ -23,22 +25,22 @@ For task 2 we will create a 1D array object patterned after numpy's
2325
disregard efficiency. Start by looking at task_1.py and fill in the implementation to meet the
2426
following requirements:
2527

26-
27-
1. Implement the `__init__` to take a Sequence (tuple, lists, etc.) as the first input argument.
28+
1. Implement the `__init__` to optionally take a Sequence (tuple, lists, etc.) as the first input argument.
29+
If no input is provided use an empty list as input.
2830

2931
2. Ensure each element is a basic numeric type (float, int, complex, None) else raise InvalidEntryError.
3032

3133
3. Implement the `__str__` and `__repr__` methods. If the len < 10 'Array1D[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]'
3234
showing each element. If it is greater than 10 `Array1D[...]`
3335

3436
4. Make sure the Array1D implements the Sequence protocol. Specifically, it should be iterable,
35-
indexible, membership checks should work, and slicing should return Array1D instances with a
37+
indexible, membership checks should work, and slicing should return Array1D instances with
3638
a subset of data.
3739

3840
5. Implement operators: add, subtract, true divide, floor divide, power. Each one should work
3941
with an array of equal size, an array of size 1, or a single number. This should work if
4042
the array or the number is first. (hint: `__add__` and `__radd__` are both needed). If the
41-
array's are not compatible, a IncompatibleArrayOperationError should be raised.
43+
arrays are not compatible, a IncompatibleArrayOperationError should be raised.
4244

4345
You can see how your implementation is performing by running `pytest test_task_1.py` after installing
4446
pytest.

test_task_2.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import sys
88
from operator import add, floordiv, mul, pow, sub, truediv
99

10-
import pandas as pd
1110
import pytest
1211

1312
from task_2 import Array1D, IncompatibleArrayOperationError, InvalidEntryError
@@ -28,7 +27,7 @@ def array_input(request):
2827
return request.param
2928

3029

31-
def test_numpy_not_in_loaded_modules(self):
30+
def test_numpy_not_in_loaded_modules():
3231
"""Numpy should not be in the imported modules."""
3332
assert "numpy" not in sys.modules
3433

@@ -83,7 +82,7 @@ def test_slice(self):
8382
array = Array1D(array_inp)
8483
array_slice = array[1:-2]
8584
assert isinstance(array_slice, Array1D)
86-
assert list(array_slice) == array_inp[1:-2]
85+
assert list(array_slice) == list(array_inp[1:-2])
8786

8887

8988
class TestRepresentation:
@@ -113,7 +112,10 @@ def test_self_operations(self, array_input):
113112
for op in self.operators:
114113
result = op(array, array)
115114
for el1, el2 in zip(result, array):
116-
assert el1 == op(el2, el2)
115+
try:
116+
assert el1 == op(el2, el2)
117+
except (ZeroDivisionError, TypeError):
118+
assert el1 is None
117119

118120
def test_uneven_array_raises(self, array_input):
119121
"""Arrays of different lengths should not be compatible."""
@@ -133,6 +135,6 @@ def test_one_null_broadcast(self, array_input):
133135
null_array = Array1D([None])
134136
for op in self.operators:
135137
result1 = op(array, null_array)
136-
assert all([pd.isnull(x) for x in result1])
138+
assert all([x is None for x in result1])
137139
result2 = op(null_array, array)
138-
assert all([pd.isnull(x) for x in result2])
140+
assert all([x is None for x in result2])

0 commit comments

Comments
 (0)