예제 #1
0
    def test_adding(self):
        summedPolynom = self.polynom1 + self.polynom2
        referncePolynom = Polynom([2, 1])
        self.assertEqual(summedPolynom.__repr__(), referncePolynom.__repr__())

        summedPolynom2 = self.polynom5 + self.polynom6 + self.polynom6
        referncePolynom2 = Polynom([0.7, 0.8])
        self.assertEqual(summedPolynom2.__repr__(), referncePolynom2.__repr__())
예제 #2
0
class TestPolynomFunction(unittest.TestCase):

    def setUp(self):
        self.polynom1 = Polynom([0, 1])  # x
        self.polynom2 = Polynom([2])     # 2
        self.polynom3 = Polynom([-2, 0, 1])  # x² - 2
        self.polynom4 = Polynom([-6, 11, -6, 1])

    def test_representation(self):
        self.assertEqual(self.polynom1.__repr__(), "0x^0 + 1x^1")
        self.assertEqual(self.polynom2.__repr__(), "2x^0")
        self.assertEqual(self.polynom3.__repr__(), "-2x^0 + 0x^1 + 1x^2")
        self.assertEqual(self.polynom4.__repr__(), "-6x^0 + 11x^1 + -6x^2 + 1x^3")

    def test_calculating_value(self):
        self.assertEqual(self.polynom1.calculate_at(1), 1)
        self.assertEqual(self.polynom1.calculate_at(-77), -77)

        self.assertEqual(self.polynom2.calculate_at(1), 2)
        self.assertEqual(self.polynom2.calculate_at(random.randint(-1000, 1000)), 2)

        self.assertEqual(self.polynom3.calculate_at(1), -1)

        self.assertEqual(self.polynom4.calculate_at(1), 0)
        self.assertEqual(self.polynom4.calculate_at(2), 0)
        self.assertEqual(self.polynom4.calculate_at(3), 0)
예제 #3
0
 def setUp(self):
     self.polynom1 = Polynom([0, 1])  # x
     self.polynom2 = Polynom([2])     # 2
     self.polynom3 = Polynom([-2, 0, 1])  # x² - 2
     self.polynom4 = Polynom([-6, 11, -6, 1])