Skip to content

Commit 9012c1c

Browse files
committed
final ouput from updating our math research project with cursor.
1 parent 893edfd commit 9012c1c

File tree

4 files changed

+107
-5
lines changed

4 files changed

+107
-5
lines changed

code/09-agentic-ai/math-research/math_research.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": 4,
15+
"execution_count": 10,
1616
"id": "6040bded7e982e0c",
1717
"metadata": {
1818
"ExecuteTime": {
@@ -26,11 +26,13 @@
2626
"outputs": [],
2727
"source": [
2828
"# Import our math functions.\n",
29-
"import mathf"
29+
"import mathf\n",
30+
"from itertools import islice"
3031
]
3132
},
3233
{
33-
"cell_type": "raw",
34+
"cell_type": "markdown",
35+
"id": "db59501c",
3436
"metadata": {
3537
"vscode": {
3638
"languageId": "raw"
@@ -83,8 +85,6 @@
8385
},
8486
"outputs": [],
8587
"source": [
86-
"from itertools import islice\n",
87-
"\n",
8888
"prime = 17\n",
8989
"all_fibs = mathf.fibonacci()\n",
9090
"fib_multiples_of_prime = mathf.multiples_of(all_fibs, prime)\n",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""Unit tests for the mathf library."""
2+
3+
import pytest
4+
from mathf import fibonacci, multiples_of
5+
6+
7+
class TestFibonacci:
8+
"""Tests for the fibonacci generator function."""
9+
10+
def test_fibonacci_first_ten_numbers(self):
11+
"""Test that fibonacci generates the correct first 10 numbers."""
12+
fib = fibonacci()
13+
expected = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
14+
actual = [next(fib) for _ in range(10)]
15+
assert actual == expected
16+
17+
def test_fibonacci_is_generator(self):
18+
"""Test that fibonacci returns a generator."""
19+
fib = fibonacci()
20+
assert hasattr(fib, '__next__')
21+
assert hasattr(fib, '__iter__')
22+
23+
def test_fibonacci_continues_correctly(self):
24+
"""Test that fibonacci continues correctly after first few numbers."""
25+
fib = fibonacci()
26+
# Skip first 5 numbers
27+
for _ in range(5):
28+
next(fib)
29+
# Test the next few
30+
assert next(fib) == 8
31+
assert next(fib) == 13
32+
assert next(fib) == 21
33+
34+
35+
class TestMultiplesOf:
36+
"""Tests for the multiples_of function."""
37+
38+
def test_multiples_of_basic_case(self):
39+
"""Test basic functionality with multiples of 2."""
40+
collection = [1, 2, 3, 4, 5, 6, 7, 8]
41+
result = list(multiples_of(collection, 2))
42+
assert result == [2, 4, 6, 8]
43+
44+
def test_multiples_of_three(self):
45+
"""Test with multiples of 3."""
46+
collection = [1, 2, 3, 6, 9, 10, 12, 15]
47+
result = list(multiples_of(collection, 3))
48+
assert result == [3, 6, 9, 12, 15]
49+
50+
def test_multiples_of_one(self):
51+
"""Test with multiples of 1 (all numbers)."""
52+
collection = [1, 2, 3, 4, 5]
53+
result = list(multiples_of(collection, 1))
54+
assert result == [1, 2, 3, 4, 5]
55+
56+
def test_multiples_of_empty_collection(self):
57+
"""Test with empty collection."""
58+
result = list(multiples_of([], 2))
59+
assert result == []
60+
61+
def test_multiples_of_no_matches(self):
62+
"""Test when no numbers are multiples."""
63+
collection = [1, 3, 5, 7]
64+
result = list(multiples_of(collection, 2))
65+
assert result == []
66+
67+
def test_multiples_of_zero_raises_error(self):
68+
"""Test that zero raises ValueError."""
69+
with pytest.raises(ValueError, match='Number must be positive'):
70+
list(multiples_of([1, 2, 3], 0))
71+
72+
def test_multiples_of_negative_raises_error(self):
73+
"""Test that negative numbers raise ValueError."""
74+
with pytest.raises(ValueError, match='Number must be positive'):
75+
list(multiples_of([1, 2, 3], -5))
76+
77+
def test_multiples_of_is_generator(self):
78+
"""Test that multiples_of returns a generator."""
79+
result = multiples_of([1, 2, 3, 4], 2)
80+
assert hasattr(result, '__next__')
81+
assert hasattr(result, '__iter__')
82+
83+
def test_multiples_of_with_large_numbers(self):
84+
"""Test with larger numbers."""
85+
collection = [100, 150, 200, 250, 300]
86+
result = list(multiples_of(collection, 50))
87+
assert result == [100, 150, 200, 250, 300]
88+
89+
def test_multiples_of_with_duplicates(self):
90+
"""Test that duplicates in collection are preserved."""
91+
collection = [2, 4, 2, 6, 4]
92+
result = list(multiples_of(collection, 2))
93+
assert result == [2, 4, 2, 6, 4]

requirements.piptools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
httpx
22
jupyterlab
3+
pytest

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ idna==3.10
6363
# httpx
6464
# jsonschema
6565
# requests
66+
iniconfig==2.1.0
67+
# via pytest
6668
ipykernel==6.30.0
6769
# via jupyterlab
6870
ipython==9.4.0
@@ -157,6 +159,7 @@ packaging==25.0
157159
# jupyterlab
158160
# jupyterlab-server
159161
# nbconvert
162+
# pytest
160163
pandocfilters==1.5.1
161164
# via nbconvert
162165
parso==0.8.4
@@ -165,6 +168,8 @@ pexpect==4.9.0
165168
# via ipython
166169
platformdirs==4.3.8
167170
# via jupyter-core
171+
pluggy==1.6.0
172+
# via pytest
168173
prometheus-client==0.22.1
169174
# via jupyter-server
170175
prompt-toolkit==3.0.51
@@ -184,6 +189,9 @@ pygments==2.19.2
184189
# ipython
185190
# ipython-pygments-lexers
186191
# nbconvert
192+
# pytest
193+
pytest==8.4.1
194+
# via -r requirements.piptools
187195
python-dateutil==2.9.0.post0
188196
# via
189197
# arrow

0 commit comments

Comments
 (0)