예제 #1
0
    def test_int_against_float(self):
        nm = NumberArrayMeta("float32")
        values = [1, 2, 3]
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value

        nm = NumberArrayMeta("float64")
        values = [1, 2, 3]
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value
예제 #2
0
    def test_float_against_float32(self):
        nm = NumberArrayMeta("float32")
        values = [1.2, 3.4, 5.6]
        response = nm.validate(values)

        for i, value in enumerate(response):
            self.assertAlmostEqual(values[i], response[i], places=5)
예제 #3
0
    def test_float_against_float64(self):
        nm = NumberArrayMeta("float64")
        values = [1.2, 3.4, 5.6]
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value
예제 #4
0
    def test_numpy_array(self):
        nm = NumberArrayMeta("float64")
        values = np.array([1.2, 3.4, 5.6])
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value
예제 #5
0
 def test_none_validates(self):
     nm = NumberArrayMeta("int32")
     assert list(nm.validate(None)) == []
예제 #6
0
 def test_null_element_zero(self):
     nm = NumberArrayMeta("float64")
     actual = nm.validate([1.2, None, 1.3])
     assert actual[0] == 1.2
     assert np.isnan(actual[1])
     assert actual[2] == 1.3
예제 #7
0
 def test_float_against_int_floors(self):
     nm = NumberArrayMeta("int32")
     actual = list(nm.validate([1.2, 34, 56]))
     expected = [1, 34, 56]
     assert actual == expected
예제 #8
0
    def test_numpy_array_wrong_number_type_raises(self):
        nm = NumberArrayMeta("int32")
        values = np.array([1.2, 3.4, 5.6])

        with self.assertRaises(AssertionError):
            nm.validate(values)
예제 #9
0
    def test_numpy_array_wrong_type_raises(self):
        nm = NumberArrayMeta("float64")
        values = "[1.2, 3.4, 5.6]"

        with self.assertRaises(ValueError):
            nm.validate(values)