test_pivot.py 2.11 KB
Newer Older
rmapaah's avatar
rmapaah committed
1 2 3 4 5 6
#  -*- coding: utf-8 -*-

# import six
import numpy as np
import pytest
import sksurgerycore.algorithms.pivot as p
7
from glob import glob
rmapaah's avatar
rmapaah committed
8 9 10


def test_empty_matrices4x4():
rmapaah's avatar
rmapaah committed
11

rmapaah's avatar
rmapaah committed
12 13 14 15
    with pytest.raises(TypeError):
        p.pivot_calibration(None)


rmapaah's avatar
rmapaah committed
16
def test_rank_lt_six():
rmapaah's avatar
rmapaah committed
17

18
    with pytest.raises(ValueError):
19
        file_names = glob('tests/data/PivotCalibration/1378476416922755200.txt')
rmapaah's avatar
rmapaah committed
20 21 22 23 24 25 26
        arrays = [np.loadtxt(f) for f in file_names]
        matrices = np.concatenate(arrays)
        numberOf4x4Matrices = int(matrices.size/16)
        matrices4x4 = matrices.reshape(numberOf4x4Matrices, 4, 4)
        p.pivot_calibration(matrices4x4)


rmapaah's avatar
rmapaah committed
27
def test_four_columns_matrices4x4():
rmapaah's avatar
rmapaah committed
28

rmapaah's avatar
rmapaah committed
29 30 31
    with pytest.raises(ValueError):
        p.pivot_calibration(np.arange(2, 11, dtype=float).reshape(3, 3))

32

rmapaah's avatar
rmapaah committed
33
def test_four_rows_matrices4x4():
rmapaah's avatar
rmapaah committed
34

rmapaah's avatar
rmapaah committed
35 36 37
    with pytest.raises(ValueError):
        p.pivot_calibration(np.arange(2, 11, dtype=float).reshape(3, 3))

38 39

def test_return_value():
rmapaah's avatar
rmapaah committed
40

41
    file_names = glob('tests/data/PivotCalibration/*')
42 43 44 45
    arrays = [np.loadtxt(f) for f in file_names]
    matrices = np.concatenate(arrays)
    numberOf4x4Matrices = int(matrices.size/16)
    matrices4x4 = matrices.reshape(numberOf4x4Matrices, 4, 4)
46
    x_values, residual_error =p.pivot_calibration(matrices4x4)
47
    assert 1.838 == round(residual_error, 3)
48 49 50
    assert -14.476 == round(x_values[0, 0], 3)
    assert 395.143 == round(x_values[1, 0], 3)
    assert -7.558 == round(x_values[2, 0], 3)
51 52
    assert -805.285 == round(x_values[3, 0], 3)
    assert -85.448 == round(x_values[4, 0], 3)
53
    assert -2112.066 == round(x_values[5, 0], 3)
54 55 56 57 58 59 60


def test_rank_if_condition():

    # This test will be checking a specific if condition.
    # But at the moment I dont know what data I need
    # To get proper s_values to cover that if condition.
61
    with pytest.raises(ValueError):
62 63 64 65 66 67 68
        file_names = glob('tests/data/test_case_data.txt')
        arrays = [np.loadtxt(f) for f in file_names]
        matrices = np.concatenate(arrays)
        numberOf4x4Matrices = int(matrices.size/16)
        matrices4x4 = matrices.reshape(numberOf4x4Matrices, 4, 4)
        p.pivot_calibration(matrices4x4)

69