Wattsy2020 / 314-Project

Group work assignment for CSIT314
0 stars 0 forks source link

Use Test Driven Development to test the Tool #4

Open Wattsy2020 opened 4 years ago

Wattsy2020 commented 4 years ago

Throughout the process of developing the functionality outlined in #2 and #3 we need to be using test driven development to test the modules we are creating.

An example of which is the following code which tests the assert_matrix_equals(x, y, delta) function.

def test_assert_matrix_equals():
    dims = randrange(1, 100), randrange(1, 100)
    A = np.random.random_sample(dims)
    B = A - randrange(1, 500)
    try:
        assert_matrix_equals(A, B)
    except:
        pass # test passed, assert_matrix should through exception
    else:
        raise AssertionError("assert_matrix_equals claims two unequal matrices are equal")

The first three lines create the random test data A and B, B is a different matrix to A as each value has something greater than 1 subtracted from it. As A and B are not equal assert_matrix_equals should throw an exception, which it does hence test passed.