Created
March 14, 2023 23:17
-
-
Save tfmoraes/cd67cc7771864687c43e56a59747bca5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from unittest.mock import MagicMock | |
import invesalius.i18n as i18n | |
_ = i18n.InstallLanguage('en') | |
from invesalius.data.geometry import * | |
class TestBox(unittest.TestCase): | |
def test_SetX(self): | |
box = Box() | |
box.SetX(1, 4) | |
self.assertEqual(box.xi, 1) | |
self.assertEqual(box.xf, 4) | |
self.assertEqual(box.size_x, 4) | |
def test_SetY(self): | |
box = Box() | |
box.SetY(2, 5) | |
self.assertEqual(box.yi, 2) | |
self.assertEqual(box.yf, 5) | |
self.assertEqual(box.size_y, 5) | |
def test_SetZ(self): | |
box = Box() | |
box.SetZ(3, 6) | |
self.assertEqual(box.zi, 3) | |
self.assertEqual(box.zf, 6) | |
self.assertEqual(box.size_z, 6) | |
def test_set_spacing(self): | |
box = Box() | |
box.SetX(1, 4) | |
box.SetY(2, 5) | |
box.SetZ(3, 6) | |
box.SetSpacing(2, 3, 4) | |
self.assertEqual(box.xi, 2) | |
self.assertEqual(box.xf, 8) | |
self.assertEqual(box.yi, 6) | |
self.assertEqual(box.yf, 15) | |
self.assertEqual(box.zi, 12) | |
self.assertEqual(box.zf, 24) | |
self.assertEqual(box.size_x, 8) | |
self.assertEqual(box.size_y, 15) | |
self.assertEqual(box.size_z, 24) | |
self.assertEqual(box.xs, 2) | |
self.assertEqual(box.ys, 3) | |
self.assertEqual(box.zs, 4) | |
self.assertFalse(box.first_run) | |
def test_make_matrix(self): | |
box = Box() | |
box.SetX(2, 8) | |
box.SetY(4, 10) | |
box.SetZ(6, 12) | |
box.SetSpacing(1, 1, 1) | |
box.MakeMatrix() | |
self.assertEqual(box.sagital[const.SAGITAL_LEFT], [[2, 3.5, 6], [2, 3.5, 12]]) | |
self.assertEqual( | |
box.sagital[const.SAGITAL_RIGHT], [[2, 10.5, 6], [2, 10.5, 12]] | |
) | |
self.assertEqual(box.sagital[const.SAGITAL_BOTTOM], [[2, 4, 5.5], [2, 10, 5.5]]) | |
self.assertEqual( | |
box.sagital[const.SAGITAL_UPPER], [[2, 4, 12.5], [2, 10, 12.5]] | |
) | |
self.assertEqual(box.coronal[const.CORONAL_BOTTOM], [[2, 4, 5.5], [8, 10, 5.5]]) | |
self.assertEqual( | |
box.coronal[const.CORONAL_UPPER], [[2, 4, 12.5], [8, 10, 12.5]] | |
) | |
self.assertEqual(box.coronal[const.CORONAL_LEFT], [[1.5, 4, 6], [1.5, 10, 12]]) | |
self.assertEqual(box.coronal[const.CORONAL_RIGHT], [[8.5, 4, 6], [8.5, 10, 12]]) | |
self.assertEqual(box.axial[const.AXIAL_BOTTOM], [[2, 3.5, 6], [8, 3.5, 12]]) | |
self.assertEqual(box.axial[const.AXIAL_UPPER], [[2, 10.5, 6], [8, 10.5, 12]]) | |
self.assertEqual(box.axial[const.AXIAL_LEFT], [[1.5, 4, 6], [1.5, 10, 12]]) | |
self.assertEqual(box.axial[const.AXIAL_RIGHT], [[8.5, 4, 6], [8.5, 10, 12]]) | |
class TestDrawCrop2DRetangle(unittest.TestCase): | |
def test_init(self): | |
draw_crop = DrawCrop2DRetangle() | |
self.assertIsNone(draw_crop.viewer) | |
self.assertEqual(draw_crop.points_in_display, {}) | |
self.assertIsNone(draw_crop.box) | |
self.assertFalse(draw_crop.mouse_pressed) | |
self.assertIsNone(draw_crop.canvas) | |
self.assertIsNone(draw_crop.status_move) | |
self.assertIsNone(draw_crop.crop_pan) | |
self.assertEqual(draw_crop.last_x, 0) | |
self.assertEqual(draw_crop.last_y, 0) | |
self.assertEqual(draw_crop.last_z, 0) | |
self.assertEqual(draw_crop.layer, 0) | |
def setUp(self): | |
self.mock_status_move = MagicMock() | |
self.obj_under_test = DrawCrop2DRetangle() | |
self.obj_under_test.status_move = self.mock_status_move | |
self.my_class = DrawCrop2DRetangle() | |
def test_release_left_sets_status_move_to_none(self): | |
self.obj_under_test.ReleaseLeft() | |
self.assertIsNone(self.obj_under_test.status_move) | |
def test_LeftPressed(self): | |
self.assertFalse(self.my_class.mouse_pressed) | |
self.my_class.LeftPressed(10, 20) | |
self.assertTrue(self.my_class.mouse_pressed) | |
if __name__ == "__main__": | |
unittest.main() | |
""" | |
Testing started at 20:14 ... | |
Launching unittests with arguments python -m unittest /Users/jnzca/Desktop/invesalius3/invesalius/data/test_geometry.py in /Users/jnzca/Desktop/invesalius3/invesalius/data | |
Ran 8 tests in 0.004s | |
OK | |
Process finished with exit code 0 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment