aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test
diff options
context:
space:
mode:
authorThéo de la Hogue2022-12-08 23:58:03 +0100
committerThéo de la Hogue2022-12-08 23:58:03 +0100
commit88a213a383cddeb0b5e4944fc8838ae428bceb47 (patch)
treec9cc5297531340879380ece1583bff79f1790b56 /src/argaze.test
parenta566491d0aacbc3a105c742608e7f15ae085f28e (diff)
downloadargaze-88a213a383cddeb0b5e4944fc8838ae428bceb47.zip
argaze-88a213a383cddeb0b5e4944fc8838ae428bceb47.tar.gz
argaze-88a213a383cddeb0b5e4944fc8838ae428bceb47.tar.bz2
argaze-88a213a383cddeb0b5e4944fc8838ae428bceb47.tar.xz
Adding and testing GazePosition overlap function.
Diffstat (limited to 'src/argaze.test')
-rw-r--r--src/argaze.test/GazeFeatures.py53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/argaze.test/GazeFeatures.py b/src/argaze.test/GazeFeatures.py
index dd0717c..d6abd12 100644
--- a/src/argaze.test/GazeFeatures.py
+++ b/src/argaze.test/GazeFeatures.py
@@ -43,29 +43,29 @@ class TestGazePositionClass(unittest.TestCase):
for v in empty_gaze_position:
self.assertEqual(v, 0)
- self.assertEqual(empty_gaze_position.accuracy, 0.)
+ self.assertEqual(empty_gaze_position.precision, 0.)
self.assertEqual(len(empty_gaze_position), 2)
self.assertEqual(empty_gaze_position.valid, True)
self.assertEqual(numpy.array(empty_gaze_position).shape, (2,))
# Check integer GazePosition
- int_gaze_position = GazeFeatures.GazePosition((123, 456), accuracy=55)
+ int_gaze_position = GazeFeatures.GazePosition((123, 456), precision=55)
self.assertEqual(int_gaze_position.value, (123, 456))
self.assertEqual(int_gaze_position[0], 123)
self.assertEqual(int_gaze_position[1], 456)
- self.assertEqual(int_gaze_position.accuracy, 55)
+ self.assertEqual(int_gaze_position.precision, 55)
self.assertEqual(len(int_gaze_position), 2)
self.assertEqual(int_gaze_position.valid, True)
self.assertEqual(numpy.array(empty_gaze_position).shape, (2,))
# Check float GazePosition
- float_gaze_position = GazeFeatures.GazePosition((1.23, 4.56), accuracy=5.5)
+ float_gaze_position = GazeFeatures.GazePosition((1.23, 4.56), precision=5.5)
self.assertEqual(float_gaze_position.value, (1.23, 4.56))
self.assertEqual(float_gaze_position[0], 1.23)
self.assertEqual(float_gaze_position[1], 4.56)
- self.assertEqual(float_gaze_position.accuracy, 5.5)
+ self.assertEqual(float_gaze_position.precision, 5.5)
self.assertEqual(len(float_gaze_position), 2)
self.assertEqual(float_gaze_position.valid, True)
self.assertEqual(numpy.array(empty_gaze_position).shape, (2,))
@@ -83,11 +83,30 @@ class TestGazePositionClass(unittest.TestCase):
self.assertNotEqual(gaze_position.value, (123, 456))
self.assertEqual(gaze_position.value, (0, 0))
+ def test_overlapping(self):
+ """Test GazePosition overlap method."""
+
+ gaze_position_A = GazeFeatures.GazePosition((0, 0), precision=10)
+ gaze_position_B = GazeFeatures.GazePosition((10, 0), precision=10)
+ gaze_position_C = GazeFeatures.GazePosition((5, 0), precision=5)
+ gaze_position_D = GazeFeatures.GazePosition((4, 0), precision=5)
+
+ self.assertFalse(gaze_position_A.overlap(gaze_position_B))
+ self.assertTrue(gaze_position_A.overlap(gaze_position_C))
+ self.assertFalse(gaze_position_A.overlap(gaze_position_C, both=True))
+
+ self.assertFalse(gaze_position_B.overlap(gaze_position_A))
+ self.assertTrue(gaze_position_B.overlap(gaze_position_C))
+ self.assertFalse(gaze_position_B.overlap(gaze_position_C, both=True))
+
+ self.assertFalse(gaze_position_C.overlap(gaze_position_A))
+ self.assertFalse(gaze_position_C.overlap(gaze_position_B))
+
def test___repr__(self):
"""Test GazePosition string representation."""
# Check empty GazePosition representation
- self.assertEqual(repr(GazeFeatures.GazePosition()), "{\"value\": [0, 0], \"accuracy\": 0.0}")
+ self.assertEqual(repr(GazeFeatures.GazePosition()), "{\"value\": [0, 0], \"precision\": 0.0}")
class TestUnvalidGazePositionClass(unittest.TestCase):
"""Test UnvalidGazePosition class."""
@@ -100,13 +119,13 @@ class TestUnvalidGazePositionClass(unittest.TestCase):
unvalid_gaze_position = GazeFeatures.UnvalidGazePosition()
self.assertEqual(unvalid_gaze_position.value, (None, None))
- self.assertEqual(unvalid_gaze_position.accuracy, None)
+ self.assertEqual(unvalid_gaze_position.precision, None)
self.assertEqual(unvalid_gaze_position.valid, False)
def test___repr__(self):
"""Test UnvalidGazePosition string representation."""
- self.assertEqual(repr(GazeFeatures.UnvalidGazePosition()), "{\"value\": [null, null], \"accuracy\": null}")
+ self.assertEqual(repr(GazeFeatures.UnvalidGazePosition()), "{\"value\": [null, null], \"precision\": null}")
class TestTimeStampedGazePositionsClass(unittest.TestCase):
"""Test TimeStampedGazePositions class."""
@@ -117,7 +136,7 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase):
ts_gaze_positions = GazeFeatures.TimeStampedGazePositions()
ts_gaze_positions[0] = GazeFeatures.GazePosition()
ts_gaze_positions[1] = GazeFeatures.UnvalidGazePosition()
- ts_gaze_positions[2] = {"value": (0, 0), "accuracy": 0.}
+ ts_gaze_positions[2] = {"value": (0, 0), "precision": 0.}
# Check GazePosition is correctly stored and accessible as a GazePosition
self.assertIsInstance(ts_gaze_positions[0], GazeFeatures.GazePosition)
@@ -127,7 +146,7 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase):
self.assertIsInstance(ts_gaze_positions[1], GazeFeatures.UnvalidGazePosition)
self.assertEqual(ts_gaze_positions[1].valid, False)
- # Check dict with "value" and "accuracy" keys is correctly stored and accessible as a GazePosition
+ # Check dict with "value" and "precision" keys is correctly stored and accessible as a GazePosition
self.assertIsInstance(ts_gaze_positions[2], GazeFeatures.GazePosition)
self.assertEqual(ts_gaze_positions[2].valid, True)
@@ -139,7 +158,7 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase):
# Check that dict with bad keys insertion fails
with self.assertRaises(AssertionError):
- ts_gaze_positions[4] = {"bad_key": (0, 0), "accuracy": 0.}
+ ts_gaze_positions[4] = {"bad_key": (0, 0), "precision": 0.}
# Check final lenght
self.assertEqual(len(ts_gaze_positions), 3)
@@ -153,11 +172,11 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase):
ts_gaze_positions[0] = GazeFeatures.GazePosition()
- self.assertEqual(repr(ts_gaze_positions), "{\"0\": {\"value\": [0, 0], \"accuracy\": 0.0}}")
+ self.assertEqual(repr(ts_gaze_positions), "{\"0\": {\"value\": [0, 0], \"precision\": 0.0}}")
ts_gaze_positions[0] = GazeFeatures.UnvalidGazePosition()
- self.assertEqual(repr(ts_gaze_positions), "{\"0\": {\"value\": [null, null], \"accuracy\": null}}")
+ self.assertEqual(repr(ts_gaze_positions), "{\"0\": {\"value\": [null, null], \"precision\": null}}")
def test_as_dataframe(self):
"""Test inherited as_dataframe method."""
@@ -170,10 +189,10 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase):
self.assertEqual(ts_gaze_positions_dataframe.columns.size, 2)
self.assertEqual(ts_gaze_positions_dataframe.columns[0], "value")
- self.assertEqual(ts_gaze_positions_dataframe.columns[1], "accuracy")
+ self.assertEqual(ts_gaze_positions_dataframe.columns[1], "precision")
self.assertEqual(ts_gaze_positions_dataframe["value"].dtype, 'object')
- self.assertEqual(ts_gaze_positions_dataframe["accuracy"].dtype, 'float64')
+ self.assertEqual(ts_gaze_positions_dataframe["precision"].dtype, 'float64')
# Check unvalid position conversion
ts_gaze_positions = GazeFeatures.TimeStampedGazePositions()
@@ -185,10 +204,10 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase):
self.assertEqual(ts_gaze_positions_dataframe.columns.size, 2)
self.assertEqual(ts_gaze_positions_dataframe.columns[0], "value")
- self.assertEqual(ts_gaze_positions_dataframe.columns[1], "accuracy")
+ self.assertEqual(ts_gaze_positions_dataframe.columns[1], "precision")
self.assertEqual(ts_gaze_positions_dataframe["value"].dtype, 'object')
- self.assertEqual(ts_gaze_positions_dataframe["accuracy"].dtype, 'O') # Python object type
+ self.assertEqual(ts_gaze_positions_dataframe["precision"].dtype, 'O') # Python object type
if __name__ == '__main__':