Skip to content

Commit a9b5897

Browse files
committed
Configuration du fichier de test pour les classes et les fonctions lambda
1 parent ce8ff99 commit a9b5897

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

.github/workflows/publish.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ jobs:
2626
run: |
2727
python -m pip install --upgrade pip
2828
pip install -r requirements.txt
29-
pip install pytest
3029
31-
- name: Run tests
30+
- name: Run unit tests
3231
run: |
33-
pytest
32+
python -m unittest discover -s tests -p 'test_*.py'
3433
3534
publish:
3635
name: Build and Publish to PyPI

tests/test_visual.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
from unittest.mock import patch
3+
from visual import Point, Vector, distance, a, b, perm, milieu, average
4+
5+
class TestVisualLibrary(unittest.TestCase):
6+
7+
def test_point_operations(self):
8+
p = Point(3, 4, 'A')
9+
self.assertEqual(p.x, 3)
10+
self.assertEqual(p.y, 4)
11+
self.assertEqual(str(p), 'A')
12+
self.assertEqual(p, Point(3, 4))
13+
14+
def test_vector_operations(self):
15+
v1 = Vector(x=3, y=4)
16+
v2 = Vector(x=1, y=2)
17+
self.assertEqual(v1 + v2, Vector(x=4, y=6))
18+
self.assertEqual(v1 - v2, Vector(x=2, y=2))
19+
self.assertEqual(v1 * 2, Vector(x=6, y=8))
20+
self.assertEqual(v1 / 2, Vector(x=1.5, y=2.0))
21+
22+
def test_distance(self):
23+
p1 = Point(0, 0)
24+
p2 = Point(3, 4)
25+
self.assertEqual(distance(p1, p2), 5)
26+
27+
def test_milieu(self):
28+
p1 = Point(0, 0)
29+
p2 = Point(2, 2)
30+
self.assertEqual(milieu(p1, p2), Point(1, 1))
31+
32+
def test_average(self):
33+
self.assertEqual(average([1, 2, 3]), 2)
34+
35+
def test_slope_and_intercept(self):
36+
p1 = Point(1, 2)
37+
p2 = Point(3, 6)
38+
self.assertEqual(a(p1, p2), 2)
39+
self.assertEqual(b(2, p1), 0)
40+
41+
def test_perm(self):
42+
self.assertEqual(perm(5, 2), 20.0)
43+
44+
if __name__ == '__main__':
45+
unittest.main()

0 commit comments

Comments
 (0)