-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinearSystem_test.py
59 lines (50 loc) · 1.68 KB
/
LinearSystem_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import unittest
from LinearSystem import LinearSystem, NoSolutionError
from LinearEquation import LinearEquation
class TestLinearSystem(unittest.TestCase):
def test_solve_linear_system_simple(self):
solution = LinearSystem.from_strings(
'x=10',
).solve()
self.assertEqual(solution, LinearSystem.from_strings(
'x=10',
))
def test_solve_linear_system_2_terms(self):
solution = LinearSystem.from_strings(
'x-y-2=0',
'x+y-6=0'
).solve()
self.assertEqual(solution, LinearSystem.from_strings(
'x=4',
'y=2'
))
def test_solve_linear_system_3_terms(self):
solution = LinearSystem.from_strings(
'x-y+z-2=0',
'x+y+z-6=0',
'-x+y+z-4=0'
).solve()
self.assertEqual(solution, LinearSystem.from_strings(
'x=1',
'y=2',
'z=3',
))
def test_solve_linear_system_decimal_terms(self):
solution = LinearSystem.from_strings(
'5.262x+2.739y-9.878z+3.441=0',
'5.111x+6.358y+7.638z+2.152=0',
'2.016x-9.924y-1.367z+9.278=0',
'2.167x-13.543y-18.883z+10.567=0',
).solve()
self.assertEqual(solution, LinearSystem.from_strings(
'z=-0.082664',
'y=0.707151',
'x=-1.177202',
))
def test_solve_linear_system_parallel_lines(self):
self.assertRaises(NoSolutionError, lambda: LinearSystem.from_strings(
'x+y=0',
'x+y=1',
).solve())
if __name__ == '__main__':
unittest.main()