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