wild-mathing/tests.py
2026-01-17 00:16:14 +03:00

45 lines
No EOL
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import unittest
from algo import gauss_method
class TestGaussMethod(unittest.TestCase):
def test_2x2_unique_solution(self):
"""Простейшая 2x2 система с уникальным решением"""
coef = [[1, 1],
[2, 3]]
free_mem = [5, 11]
result = gauss_method(coef, free_mem)
expected = [4.0, 1.0]
for r, e in zip(result, expected):
self.assertAlmostEqual(r, e, places=7)
def test_2x2_another(self):
"""Ещё одна 2x2 система"""
coef = [[2, 1],
[4, 3]]
free_mem = [5, 11]
result = gauss_method(coef, free_mem)
expected = [2.0, 1.0]
for r, e in zip(result, expected):
self.assertAlmostEqual(r, e, places=7)
def test_3x3_unique_solution(self):
"""3x3 система с уникальным решением"""
coef = [[1, 1, 1],
[2, 3, 1],
[1, 2, 3]]
free_mem = [6, 11, 14]
result = gauss_method(coef, free_mem)
expected = [1.0, 2.0, 3.0]
for r, e in zip(result, expected):
self.assertAlmostEqual(r, e, places=7)
def test_degenerate_system(self):
"""Вырожденная система должна выбросить исключение"""
coef = [[1, 1],
[2, 2]]
free_mem = [2, 4]
with self.assertRaises(ValueError):
gauss_method(coef, free_mem)
if __name__ == "__main__":
unittest.main()