def test_sample2d_invalid_function_called(self): # invalid function type with self.assertRaises( TypeError, msg= "Type error was not raised when a string was (invalidly) supplied for the function." ): sample2d("blah", (1, 2, 3), (1, 2, 3))
def test_sample2d_invalid_range_type(self): # invalid type for x with self.assertRaises(TypeError, msg="Type error was not raised when a string was (invalidly) supplied for the x range."): sample2d(fn2d, "blah", (1, 2, 3)) # invalid type for y with self.assertRaises(TypeError, msg="Type error was not raised when a string was (invalidly) supplied for the y range."): sample2d(fn2d, (1, 2, 3), "blah")
def test_sample2d_invalid_range_samples(self): # number of samples < 1 for x with self.assertRaises(ValueError, msg="A ValueError was not raised when the number of x samples was < 1."): sample2d(fn2d, (10, 8, 0), (1, 2, 3)) # number of samples < 1 for y with self.assertRaises(ValueError, msg="A ValueError was not raised when the number of y samples was < 1."): sample2d(fn2d, (1, 2, 3), (10, 8, 0))
def test_sample2d_invalid_range_minmax(self): # min range > max range for x with self.assertRaises(ValueError, msg="A ValueError was not raised when the min x range was larger than the max x range."): sample2d(fn2d, (10, 8, 100), (1, 2, 3)) # min range > max range for y with self.assertRaises(ValueError, msg="A ValueError was not raised when the min y range was larger than the max y range."): sample2d(fn2d, (1, 2, 3), (10, 8, 100))
def test_sample2d_invalid_range_length(self): # tuple too short for x with self.assertRaises(ValueError, msg="Passing a range tuple for x with too few values did not raise a ValueError."): sample2d(fn2d, (1, 2), (1, 2, 3)) # tuple too short for y with self.assertRaises(ValueError, msg="Passing a range tuple for y with too few values did not raise a ValueError."): sample2d(fn2d, (1, 2, 3), (1, 2))
def test_sample2d_sample(self): rx = [1.0, 1.5, 2.0] ry = [2.0, 2.5, 3.0] rs = empty((3, 3)) for i in range(3): for j in range(3): rs[i][j] = rx[i] * rx[i] + 0.5 * ry[j] tx, ty, ts = sample2d(fn2d, (1.0, 2.0, 3), (2.0, 3.0, 3)) for i in range(3): self.assertEqual(tx[i], rx[i], "X point [{}] is incorrect.".format(i)) self.assertEqual(ty[i], ry[i], "Y point [{}] is incorrect.".format(i)) for j in range(3): self.assertEqual( ts[i][j], rs[i][j], "Sample point [{}, {}] is incorrect.".format(i, j))