diff options
Diffstat (limited to 'src/argaze.test')
-rw-r--r-- | src/argaze.test/GazeFeatures.py | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/src/argaze.test/GazeFeatures.py b/src/argaze.test/GazeFeatures.py index ac0f0cc..4681dbc 100644 --- a/src/argaze.test/GazeFeatures.py +++ b/src/argaze.test/GazeFeatures.py @@ -351,6 +351,26 @@ class TestAOIScanStepClass(unittest.TestCase): aoi_scan_step = GazeFeatures.AOIScanStep(movements, 'Test') +def build_aoi_scan_path(expected_aois, aoi_path): + """Build AOI Scan path""" + + aoi_scan_path = GazeFeatures.AOIScanPath(expected_aois) + + # Append a hidden last step to allow last given step creation + aoi_path.append(aoi_path[-2]) + + for aoi in aoi_path: + + fixation = GazeFeatures.Fixation(random_gaze_positions(10)) + ts, _ = fixation.positions.first + aoi_scan_path.append_fixation(ts, fixation, aoi) + + saccade = GazeFeatures.Saccade(random_gaze_positions(2)) + ts, _ = saccade.positions.first + aoi_scan_path.append_saccade(ts, saccade) + + return aoi_scan_path + class TestAOIScanPathClass(unittest.TestCase): """Test AOIScanPath class.""" @@ -431,64 +451,40 @@ class TestAOIScanPathClass(unittest.TestCase): new_step = aoi_scan_path.append_fixation(ts, fixation, 'Shu') - def test_transition_matrix(self): - """Test AOIScanPath transition_matrix features.""" - - aoi_scan_path = GazeFeatures.AOIScanPath(['Foo', 'Bar', 'Shu']) + def test_letter_index_and_string_reprentation(self): + """Test AOIScanPath letter index and string representation feature.""" - # First step on Bar aoi - fixation = GazeFeatures.Fixation(random_gaze_positions(10)) - ts, _ = fixation.positions.first - aoi_scan_path.append_fixation(ts, fixation, 'Bar') + aoi_scan_path = build_aoi_scan_path(['Foo', 'Bar', 'Shu'], ['Bar', 'Shu', 'Foo', 'Bar']) - saccade = GazeFeatures.Saccade(random_gaze_positions(2)) - ts, _ = saccade.positions.first - no_step_yet = aoi_scan_path.append_saccade(ts, saccade) + # Check first step + self.assertEqual(aoi_scan_path[0].aoi, 'Bar') + self.assertEqual(aoi_scan_path[0].letter, 'A') - # Second step on Shu aoi - fixation = GazeFeatures.Fixation(random_gaze_positions(10)) - ts, _ = fixation.positions.first - step_1 = aoi_scan_path.append_fixation(ts, fixation, 'Shu') + # Check second step + self.assertEqual(aoi_scan_path[1].aoi, 'Shu') + self.assertEqual(aoi_scan_path[1].letter, 'B') - saccade = GazeFeatures.Saccade(random_gaze_positions(2)) - ts, _ = saccade.positions.first - aoi_scan_path.append_saccade(ts, saccade) + # Check thrird step + self.assertEqual(aoi_scan_path[2].aoi, 'Foo') + self.assertEqual(aoi_scan_path[2].letter, 'C') - # Check first step once second step ends - self.assertEqual(step_1.aoi, 'Bar') - self.assertEqual(step_1.letter, 'A') - - # Third step on Foo aoi - fixation = GazeFeatures.Fixation(random_gaze_positions(10)) - ts, _ = fixation.positions.first - step_2 = aoi_scan_path.append_fixation(ts, fixation, 'Foo') - - saccade = GazeFeatures.Saccade(random_gaze_positions(2)) - ts, _ = saccade.positions.first - aoi_scan_path.append_saccade(ts, saccade) - - # Check second step once third step ends - self.assertEqual(step_2.aoi, 'Shu') - self.assertEqual(step_2.letter, 'B') - - # Last step on Bar aoi - fixation = GazeFeatures.Fixation(random_gaze_positions(10)) - ts, _ = fixation.positions.first - step_3 = aoi_scan_path.append_fixation(ts, fixation, 'Bar') - - saccade = GazeFeatures.Saccade(random_gaze_positions(2)) - ts, _ = saccade.positions.first - aoi_scan_path.append_saccade(ts, saccade) - - # Check thrird step once last step ends - self.assertEqual(step_3.aoi, 'Foo') - self.assertEqual(step_3.letter, 'C') + # Check fourth step + self.assertEqual(aoi_scan_path[3].aoi, 'Bar') + self.assertEqual(aoi_scan_path[3].letter, 'A') # Check letter affectation self.assertEqual(aoi_scan_path.get_letter_aoi('A'), 'Bar') self.assertEqual(aoi_scan_path.get_letter_aoi('B'), 'Shu') self.assertEqual(aoi_scan_path.get_letter_aoi('C'), 'Foo') + # Check string representation + self.assertEqual(str(aoi_scan_path), 'ABCA') + + def test_transition_matrix(self): + """Test AOIScanPath transition matrix feature.""" + + aoi_scan_path = build_aoi_scan_path(['Foo', 'Bar', 'Shu'], ['Bar', 'Shu', 'Foo']) + # Check transition matrix ([destination][departure]) self.assertEqual(aoi_scan_path.transition_matrix['Foo']['Foo'], 0) self.assertEqual(aoi_scan_path.transition_matrix['Bar']['Bar'], 0) @@ -503,6 +499,18 @@ class TestAOIScanPathClass(unittest.TestCase): self.assertEqual(aoi_scan_path.transition_matrix['Shu']['Foo'], 0) self.assertEqual(aoi_scan_path.transition_matrix['Shu']['Bar'], 1) + def test_transition_matrix(self): + """Test AOIScanPath fixations count feature.""" + + aoi_scan_path = build_aoi_scan_path(['Foo', 'Bar', 'Shu'], ['Bar', 'Shu', 'Foo']) + + # Check fixations count + scan_fixations_count, aoi_fixations_count = aoi_scan_path.fixations_count() + + self.assertEqual(scan_fixations_count, 3) + self.assertEqual(aoi_fixations_count['Foo'], 1) + self.assertEqual(aoi_fixations_count['Bar'], 1) + self.assertEqual(aoi_fixations_count['Shu'], 1) if __name__ == '__main__': |