Commit 31fb166b authored by rmapaah's avatar rmapaah

Issue #13: test code added

Test code added to verify the dimensions of matrices after creation and after modification.
parent 6cfd1d6d
......@@ -32,12 +32,24 @@ def pivot_calibration(matrices4x4):
size_a = 3 * number_of_matrices, 6
a_values = np.zeros(size_a, dtype=np.float64)
if not a_values.shape[1] == 6: # pylint: disable=literal-comparison
raise ValueError("a_values should have 6 columns per matrix")
size_x = 6, 1
x_values = np.zeros(size_x, dtype=np.float64)
if not x_values.shape[0] == 6: # pylint: disable=literal-comparison
raise ValueError("x_values should have 6 rows per matrix")
if not x_values.shape[1] == 1: # pylint: disable=literal-comparison
raise ValueError("x_values should have 1 columns per matrix")
size_b = 3 * number_of_matrices, 1
b_values = np.zeros(size_b, dtype=np.float64)
if not b_values.shape[1] == 1: # pylint: disable=literal-comparison
raise ValueError("b_values should have 1 columns per matrix")
for i in range(number_of_matrices):
b_values[i * 3 + 0, 0] = -1 * matrices4x4[i, 0, 3]
b_values[i * 3 + 1, 0] = -1 * matrices4x4[i, 1, 3]
......@@ -63,6 +75,12 @@ def pivot_calibration(matrices4x4):
a_values[i * 3 + 1, 5] = 0
a_values[i * 3 + 2, 5] = -1
if not a_values.shape[1] == 6: # pylint: disable=literal-comparison
raise ValueError("a_values should have 6 columns per matrix")
if not b_values.shape[1] == 1: # pylint: disable=literal-comparison
raise ValueError("b_values should have 1 columns per matrix")
# To calculate Singular Value Decomposition
u_values, s_values, v_values = np.linalg.svd(a_values, full_matrices=False)
......
......@@ -8,11 +8,13 @@ from glob import glob
def test_empty_matrices4x4():
with pytest.raises(TypeError):
p.pivot_calibration(None)
def test_range_le_six():
with pytest.raises(SystemExit):
file_names = glob('tests/algorithms/PivotCalibration/1378476416922755200.txt')
arrays = [np.loadtxt(f) for f in file_names]
......@@ -23,23 +25,22 @@ def test_range_le_six():
def test_four_columns_matrices4x4():
with pytest.raises(ValueError):
p.pivot_calibration(np.arange(2, 11, dtype=float).reshape(3, 3))
def test_four_rows_matrices4x4():
with pytest.raises(ValueError):
p.pivot_calibration(np.arange(2, 11, dtype=float).reshape(3, 3))
def test_return_value():
file_names = glob('tests/algorithms/PivotCalibration/*')
arrays = [np.loadtxt(f) for f in file_names]
matrices = np.concatenate(arrays)
numberOf4x4Matrices = int(matrices.size/16)
matrices4x4 = matrices.reshape(numberOf4x4Matrices, 4, 4)
assert 1.8385 == round(p.pivot_calibration(matrices4x4), 4)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment