Пример #1
0
    def test_construction(self):
        the_dict = {'Coefs': [0, 1, 2]}
        item1 = generic_arrayable_construction_test(self, blocks.Poly1DType, the_dict, numpy.array([1, 2, 3]))

        item2 = blocks.Poly1DType(Coefs=[0, 1, 2])
        with self.subTest(msg='Comparing from dict construction with alternate construction'):
            self.assertEqual(item1.to_dict(), item2.to_dict())
Пример #2
0
 def test_derivative(self):
     item = blocks.Poly1DType(Coefs=[0, 1, 2])
     dcoef = numpy.array([1, 4])
     calc_dcoefs = item.derivative(der_order=1, return_poly=False)
     self.assertEqual(item.derivative_eval(1, 1), 5)
     self.assertTrue(numpy.all(dcoef == calc_dcoefs), '{}\n{}'.format(dcoef, calc_dcoefs))
     item2 = item.derivative(der_order=2, return_poly=True)
     self.assertTrue(numpy.all(item2.Coefs == numpy.array([4, ])))
Пример #3
0
 def test_shift(self):
     array1 = numpy.array([1, 2, 1], dtype=numpy.float64)
     array2 = numpy.array([0, 0, 1], dtype=numpy.float64)
     array3 = numpy.array([1, 4, 4], dtype=numpy.float64)
     array4 = array2*array3
     with self.subTest(msg='Testing polynomial shift'):
         item = blocks.Poly1DType(Coefs=array1)
         shift = item.shift(1, alpha=1, return_poly=False)
         self.assertTrue(
             numpy.all(shift == array2), msg='calculated {}\nexpected {}'.format(shift, array2))
     with self.subTest(msg="Testing polynomial scale"):
         item = blocks.Poly1DType(Coefs=array1)
         scale = item.shift(0, alpha=2, return_poly=False)
         self.assertTrue(
             numpy.all(scale == array3), msg='calculated {}\nexpected {}'.format(scale, array3))
     with self.subTest(msg="Shift and scale"):
         item = blocks.Poly1DType(Coefs=array1)
         shift_scale = item.shift(1, alpha=2, return_poly=False)
         self.assertTrue(
             numpy.all(shift_scale == array4), msg='calculated {}\nexpected {}'.format(shift_scale, array4))
Пример #4
0
 def test_eval(self):
     item = blocks.Poly1DType(Coefs=[0, 1, 2])
     self.assertEqual(item(1), 3)