Skip to content

Commit 853a8c2

Browse files
committed
Add intro assignment - Simple Calculator
1 parent b231260 commit 853a8c2

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

0_intro/01_hello/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 👋 Intro - Simple Calculator
2+
3+
**Difficulty**: very easy
4+
**Time**: 5 minutes
5+
**Focus**: Setup verification
6+
7+
## 🎯 Zadanie
8+
Zaimplementuj dwie proste funkcje, żeby sprawdzić, że środowisko działa poprawnie.
9+
10+
## 📋 Wymagania
11+
- [ ] `add(2, 3)` zwraca `5`
12+
- [ ] `add(10, 5)` zwraca `15`
13+
- [ ] `multiply(2, 3)` zwraca `6`
14+
- [ ] `multiply(10, 5)` zwraca `50`
15+
- [ ] Funkcje działają z liczbami ujemnymi i zerem
16+
17+
## 🚀 Jak zacząć
18+
1. Otwórz `starter.py`
19+
2. Uruchom doctests: `python -m doctest starter.py -v`
20+
3. Zaimplementuj funkcje `add()` i `multiply()`
21+
4. Uruchom testy: `python -m pytest test_hello.py -v`
22+
5. Commit gdy wszystkie testy przechodzą ✅
23+
24+
## 💡 Podpowiedź
25+
- Sprawdź doctests w `starter.py` - pokazują expected behavior
26+
- `add(a, b)` powinno zwrócić sumę: `a + b`
27+
- `multiply(a, b)` powinno zwrócić iloczyn: `a * b`
28+
29+
## ✅ Success criteria
30+
Gdy uruchomisz:
31+
```bash
32+
python -m doctest starter.py -v
33+
python -m pytest test_hello.py -v
34+
```
35+
36+
Wszystkie testy powinny być zielone ✅
37+
38+
Jeśli wszystkie testy przeszły, Twoje środowisko działa poprawnie.
39+
🎉 Gratulacje!

0_intro/01_hello/starter.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
>>> add(2, 3)
3+
5
4+
5+
>>> add(10, 5)
6+
15
7+
8+
>>> multiply(2, 3)
9+
6
10+
11+
>>> multiply(10, 5)
12+
50
13+
14+
>>> add(0, 0)
15+
0
16+
17+
>>> multiply(1, 1)
18+
1
19+
"""
20+
21+
# %% About
22+
# - Name: Intro - Simple Calculator
23+
# - Difficulty: easy
24+
# - Lines: 4
25+
# - Focus: Setup verification
26+
27+
# %% Description
28+
"""
29+
Intro Exercise: Simple Calculator
30+
31+
Zaimplementuj dwie proste funkcje, żeby sprawdzić, że środowisko działa.
32+
"""
33+
34+
# %% Hints
35+
# - Funkcja add() powinna zwrócić sumę dwóch liczb
36+
# - Funkcja multiply() powinna zwrócić iloczyn dwóch liczb
37+
38+
# %% Run
39+
# - Terminal: `python -m doctest -f -v starter.py`
40+
# - Tests: `python -m pytest test_hello.py -v`
41+
42+
43+
def add(a, b):
44+
"""
45+
Add two numbers.
46+
47+
Args:
48+
a: First number
49+
b: Second number
50+
51+
Returns:
52+
Sum of a and b
53+
"""
54+
pass
55+
56+
57+
def multiply(a, b):
58+
"""
59+
Multiply two numbers.
60+
61+
Args:
62+
a: First number
63+
b: Second number
64+
65+
Returns:
66+
Product of a and b
67+
"""
68+
pass

0_intro/01_hello/test_hello.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Testy dla Intro - Simple Calculator
3+
"""
4+
5+
import pytest
6+
from starter import add, multiply
7+
8+
9+
class TestCalculator:
10+
"""Testy prostego kalkulatora"""
11+
12+
def test_add_positive_numbers(self):
13+
"""Test dodawania liczb dodatnich"""
14+
assert add(2, 3) == 5
15+
assert add(10, 5) == 15
16+
17+
def test_add_zero(self):
18+
"""Test dodawania zera"""
19+
assert add(0, 0) == 0
20+
assert add(5, 0) == 5
21+
assert add(0, 5) == 5
22+
23+
def test_add_negative_numbers(self):
24+
"""Test dodawania liczb ujemnych"""
25+
assert add(-1, -1) == -2
26+
assert add(-5, 3) == -2
27+
assert add(5, -3) == 2
28+
29+
def test_multiply_positive_numbers(self):
30+
"""Test mnożenia liczb dodatnich"""
31+
assert multiply(2, 3) == 6
32+
assert multiply(10, 5) == 50
33+
34+
def test_multiply_by_zero(self):
35+
"""Test mnożenia przez zero"""
36+
assert multiply(0, 0) == 0
37+
assert multiply(5, 0) == 0
38+
assert multiply(0, 5) == 0
39+
40+
def test_multiply_by_one(self):
41+
"""Test mnożenia przez jeden"""
42+
assert multiply(1, 1) == 1
43+
assert multiply(5, 1) == 5
44+
assert multiply(1, 5) == 5
45+
46+
def test_multiply_negative_numbers(self):
47+
"""Test mnożenia liczb ujemnych"""
48+
assert multiply(-2, 3) == -6
49+
assert multiply(-2, -3) == 6
50+
assert multiply(2, -3) == -6
51+
52+
53+
if __name__ == "__main__":
54+
pytest.main([__file__, "-v"])

0 commit comments

Comments
 (0)