From 44bf76527e59dafc46e2075605454bf23523a666 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 10 May 2023 12:00:23 +0200 Subject: Adding VisualScanStep and VisualScanPath tests. --- src/argaze.test/GazeFeatures.py | 90 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/argaze.test/GazeFeatures.py b/src/argaze.test/GazeFeatures.py index cbe6056..dd3c49b 100644 --- a/src/argaze.test/GazeFeatures.py +++ b/src/argaze.test/GazeFeatures.py @@ -209,6 +209,96 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase): self.assertEqual(ts_gaze_positions_dataframe["value"].dtype, 'object') self.assertEqual(ts_gaze_positions_dataframe["precision"].dtype, 'O') # Python object type +class TestVisualScanStepClass(unittest.TestCase): + """Test VisualScanStep class.""" + + def test_new(self): + """Test VisualScanStep creation.""" + + movements = GazeFeatures.TimeStampedGazeMovements() + + fixation = GazeFeatures.Fixation(random_gaze_positions(10)) + ts, _ = fixation.positions.first + movements[ts] = fixation + + saccade = GazeFeatures.Saccade(random_gaze_positions(2)) + ts, _ = saccade.positions.first + movements[ts] = saccade + + visual_scan_step = GazeFeatures.VisualScanStep(movements, 'Test') + + # Check visual scan step creation + self.assertEqual(len(visual_scan_step.movements), 2) + self.assertEqual(visual_scan_step.aoi, 'Test') + self.assertEqual(visual_scan_step.first_fixation, fixation) + self.assertEqual(visual_scan_step.last_saccade, saccade) + self.assertGreater(visual_scan_step.duration, 0) + + def test_error(self): + """Test VisualScanStep creation error.""" + + movements = GazeFeatures.TimeStampedGazeMovements() + + saccade = GazeFeatures.Saccade(random_gaze_positions(2)) + ts, _ = saccade.positions.first + movements[ts] = saccade + + fixation = GazeFeatures.Fixation(random_gaze_positions(10)) + ts, _ = fixation.positions.first + movements[ts] = fixation + + # Check that visual scan step creation fail + with self.assertRaises(GazeFeatures.VisualScanStepError): + + visual_scan_step = GazeFeatures.VisualScanStep(movements, 'Test') + +class TestVisualScanPathClass(unittest.TestCase): + """Test VisualScanPath class.""" + + def test_new(self): + """Test VisualScanPath creation.""" + + # Check visual scan step creation + visual_scan_path = GazeFeatures.VisualScanPath() + + self.assertEqual(len(visual_scan_path), 0) + + def test_append(self): + """Test VisualScanPath append methods.""" + + visual_scan_path = GazeFeatures.VisualScanPath() + + # Append fixation on A aoi + fixation = GazeFeatures.Fixation(random_gaze_positions(10)) + ts, _ = fixation.positions.first + + new_step = visual_scan_path.append_fixation(ts, fixation, 'A') + + # Check that no visual scan step have been created yet + self.assertEqual(len(visual_scan_path), 0) + self.assertEqual(new_step, None) + + # Append saccade + saccade = GazeFeatures.Saccade(random_gaze_positions(2)) + ts, _ = saccade.positions.first + + new_step = visual_scan_path.append_saccade(ts, saccade) + + # Check that no visual scan step have been created yet + self.assertEqual(len(visual_scan_path), 0) + self.assertEqual(new_step, None) + + # Append fixation on B aoi + fixation = GazeFeatures.Fixation(random_gaze_positions(10)) + ts, _ = fixation.positions.first + + new_step = visual_scan_path.append_fixation(ts, fixation, 'B') + + # Check a new visual scan step have been created + self.assertEqual(len(visual_scan_path), 1) + self.assertEqual(len(new_step.movements), 2) + self.assertEqual(new_step.aoi, 'A') + if __name__ == '__main__': unittest.main() \ No newline at end of file -- cgit v1.1