예제 #1
0
파일: test_curve.py 프로젝트: ant6/beprof
 def test_rescale_integer_array(self):
     c = Curve([[0, 0], [5, 5], [10, 10]], dtype=np.int)
     # should raise: TypeError: ufunc 'divide' output (typecode 'd') could not be coerced to provided output
     # parameter (typecode 'l') according to the casting rule ''same_kind''
     with self.assertRaises(TypeError):
         c.rescale(1.5, allow_cast=False)
     # floor division
     c.rescale(1.5, allow_cast=True)
     self.assertTrue(np.array_equal(c.y, [0, 3, 6]))
예제 #2
0
class TestCurveRescale(unittest.TestCase):
    def setUp(self):
        # two the same Curves - one for modification/testing,
        # one for comparison (unmodified)
        self.compare_curve = Curve([[0, 0], [5, 5], [10, 10]])
        self.test_curve = Curve([[0.0, 0], [5, 5], [10, 10]])

    def test_rescale_by_one(self):
        self.test_curve.rescale(factor=1)
        assert np.array_equal(self.compare_curve, self.test_curve)

    def test_rescale_by_negative_one(self):
        self.test_curve.rescale(factor=-1)
        assert np.array_equal(self.compare_curve.x, self.test_curve.x)
        assert np.array_equal(self.compare_curve.y, (self.test_curve.y * -1))

    def test_rescale_by_zero(self):
        # post.y should contain some nans and infs
        self.test_curve.rescale(factor=0)
        assert np.array_equal(self.compare_curve.x, self.test_curve.x)
        assert np.isnan(self.test_curve.y[0])
        assert np.isinf(self.test_curve.y[1])
        assert np.isinf(self.test_curve.y[2])
예제 #3
0
파일: test_curve.py 프로젝트: ant6/beprof
class TestCurveRescale(TestCase):
    """
    Testing Curve.rescale()
    """
    def setUp(self):
        # two the same Curves - one for modification/testing,
        # one for comparison (unmodified)
        self.compare_curve = Curve([[0, 0], [5, 5], [10, 10]])
        self.test_curve = Curve([[0.0, 0], [5, 5], [10, 10]])

    def test_rescale_by_one(self):
        self.test_curve.rescale(factor=1)
        self.assertTrue(np.array_equal(self.compare_curve, self.test_curve))

    def test_rescale_by_negative_one(self):
        self.test_curve.rescale(factor=-1)
        self.assertTrue(np.array_equal(self.compare_curve.x, self.test_curve.x))
        self.assertTrue(np.array_equal(self.compare_curve.y, (self.test_curve.y * -1)))

    def test_rescale_by_zero(self):
        # post.y should contain some nans and infs
        self.test_curve.rescale(factor=0)
        self.assertTrue(np.array_equal(self.compare_curve.x, self.test_curve.x))
        self.assertTrue(np.isnan(self.test_curve.y[0]))
        self.assertTrue(np.isinf(self.test_curve.y[1]))
        self.assertTrue(np.isinf(self.test_curve.y[2]))

    def test_rescale_integer_array(self):
        c = Curve([[0, 0], [5, 5], [10, 10]], dtype=np.int)
        # should raise: TypeError: ufunc 'divide' output (typecode 'd') could not be coerced to provided output
        # parameter (typecode 'l') according to the casting rule ''same_kind''
        with self.assertRaises(TypeError):
            c.rescale(1.5, allow_cast=False)
        # floor division
        c.rescale(1.5, allow_cast=True)
        self.assertTrue(np.array_equal(c.y, [0, 3, 6]))