Пример #1
0
    def test_morph(self):
        """check MorphStretch.morph()
        """
        morph = MorphStretch()

        # Stretch by 50%
        morph.stretch = 0.5
        xobj, yobj, xref, yref = morph(self.xobj, self.yobj, self.xref,
                self.yref)

        # Reference should be unchanged
        self.assertTrue(numpy.allclose(self.yref, yref))

        # Compare to new function. Note that due to interpolation, there will
        # be issues at the boundary of the step function. This will distort up
        # to two points in the interpolated function, and those points should
        # be off by at most 0.5.
        newstep = heaviside(xobj, 1.5, 3)
        res = sum(numpy.fabs(newstep - yobj))
        self.assertTrue(res < 1)

        # Stretch by -10%
        morph.stretch = -0.1
        xobj, yobj, xref, yref = morph(self.xobj, self.yobj, self.xref,
                self.yref)

        # Reference should be unchanged
        self.assertTrue(numpy.allclose(self.yref, yref))

        # Compare to new function. Note that due to interpolation, there will
        # be issues at the boundary of the step function. This will distort up
        # to two points in the interpolated function, and those points should
        # be off by at most 0.5.
        newstep = heaviside(xobj, 0.9, 1.8)
        res = sum(numpy.fabs(newstep - yobj))
        self.assertTrue(res < 1)
        return