def test_construction(self): the_dict = {'X': {'Coefs': [0, 1, 2]}, 'Y': {'Coefs': [0, 2, 4]}, 'Z': {'Coefs': [0, 3, 6]}} item1 = generic_arrayable_construction_test( self, blocks.XYZPolyType, the_dict, numpy.array([[0, 1, 2], [0, 2, 4], [0, 3, 6]])) item2 = blocks.XYZPolyType(X=[0, 1, 2], Y=[0, 2, 4], Z=[0, 3, 6]) with self.subTest(msg='Comparing from dict construction with alternate construction'): self.assertEqual(item1.to_dict(), item2.to_dict())
def test_derivative(self): item = blocks.XYZPolyType(X=[0, 1, 2], Y=[0, 2, 4], Z=[0, 3, 6]) dcoef = [numpy.array([1, 4]), 2*numpy.array([1, 4]), 3*numpy.array([1, 4])] calc_dcoefs = item.derivative(der_order=1, return_poly=False) self.assertTrue(numpy.all(item.derivative_eval(1, 1) == numpy.array([5, 10, 15]))) self.assertTrue(numpy.all(dcoef[0] == calc_dcoefs[0]) and numpy.all(dcoef[1] == calc_dcoefs[1]) and numpy.all(dcoef[2] == calc_dcoefs[2]), '{}\n{}'.format(dcoef, calc_dcoefs)) item2 = item.derivative(der_order=2, return_poly=True) self.assertTrue(numpy.all(item2.X.Coefs == numpy.array([4, ])) and numpy.all(item2.Y.Coefs == numpy.array([8, ])) and numpy.all(item2.Z.Coefs == numpy.array([12, ])) )
def test_eval(self): item = blocks.XYZPolyType(X=[0, 1, 2], Y=[0, 2, 4], Z=[0, 3, 6]) t = numpy.array([0, 1]) out = numpy.array([[0, 0, 0], [3, 6, 9]]) self.assertTrue(numpy.all(item(t) == out))