Commit 5e6bebbc authored by rmapaah's avatar rmapaah

Issue #13: pytest added

Tests added to check precondition for the data
To check that the data has at least 4 columns and 4 rows.
parent a4a41563
......@@ -6,12 +6,32 @@ import numpy as np
# from numpy.linalg import svd
def pivot_calibration(matrices4x4):
def add(number1, number2):
return number1 + number2
def pivot_calibration(matricesNx4x4):
"""
The function receive [N, 4, 4] matrices.
Performs Pivot Calibration and returns Residual Error.
1. matricesNx4x4 and moving must be numpy array
2. matricesNx4x4 and moving should have 4 columns
3. matricesNx4x4 and moving should have at least 4 rows
:param matricesNx4x4: point set, N x 4 x 4 ndarray
:returns: residual_error
:raises: TypeError, ValueError
"""
if not isinstance(matricesNx4x4, np.ndarray):
raise TypeError("matricesNx4x4 is not a numpy array'")
if not matricesNx4x4.shape[1] == 4: # pylint: disable=literal-comparison
raise ValueError("matricesNx4x4 should have 4 columns per matrix")
if not matricesNx4x4.shape[0] == 4: # pylint: disable=literal-comparison
raise ValueError("matricesNx4x4 should have 4 rows per matrix")
number_of_matrices = len(matrices4x4)
number_of_matrices = len(matricesNx4x4)
size_a = 3 * number_of_matrices, 6
a_values = np.zeros(size_a, dtype=np.float64)
......@@ -23,19 +43,19 @@ def pivot_calibration(matrices4x4):
b_values = np.zeros(size_b, dtype=np.float64)
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]
b_values[i * 3 + 2, 0] = -1 * matrices4x4[i, 2, 3]
a_values[i * 3 + 0, 0] = matrices4x4[i, 0, 0]
a_values[i * 3 + 1, 0] = matrices4x4[i, 1, 0]
a_values[i * 3 + 2, 0] = matrices4x4[i, 2, 0]
a_values[i * 3 + 0, 1] = matrices4x4[i, 0, 1]
a_values[i * 3 + 1, 1] = matrices4x4[i, 1, 1]
a_values[i * 3 + 2, 1] = matrices4x4[i, 2, 1]
a_values[i * 3 + 0, 2] = matrices4x4[i, 0, 2]
a_values[i * 3 + 1, 2] = matrices4x4[i, 1, 2]
a_values[i * 3 + 2, 2] = matrices4x4[i, 2, 2]
b_values[i * 3 + 0, 0] = -1 * matricesNx4x4[i, 0, 3]
b_values[i * 3 + 1, 0] = -1 * matricesNx4x4[i, 1, 3]
b_values[i * 3 + 2, 0] = -1 * matricesNx4x4[i, 2, 3]
a_values[i * 3 + 0, 0] = matricesNx4x4[i, 0, 0]
a_values[i * 3 + 1, 0] = matricesNx4x4[i, 1, 0]
a_values[i * 3 + 2, 0] = matricesNx4x4[i, 2, 0]
a_values[i * 3 + 0, 1] = matricesNx4x4[i, 0, 1]
a_values[i * 3 + 1, 1] = matricesNx4x4[i, 1, 1]
a_values[i * 3 + 2, 1] = matricesNx4x4[i, 2, 1]
a_values[i * 3 + 0, 2] = matricesNx4x4[i, 0, 2]
a_values[i * 3 + 1, 2] = matricesNx4x4[i, 1, 2]
a_values[i * 3 + 2, 2] = matricesNx4x4[i, 2, 2]
a_values[i * 3 + 0, 3] = -1
a_values[i * 3 + 1, 3] = 0
......
# -*- coding: utf-8 -*-
# import six
import numpy as np
import pytest
import sksurgerycore.algorithms.pivot as p
def test_empty_matrices4x4():
with pytest.raises(TypeError):
p.pivot_calibration(None)
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))
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