diff options
-rw-r--r-- | README.md | 26 | ||||
-rw-r--r-- | src/argaze.test/DataStructures.py | 54 | ||||
-rw-r--r-- | src/argaze.test/GazeFeatures.py | 20 |
3 files changed, 97 insertions, 3 deletions
@@ -20,13 +20,13 @@ Consider that all inline commands below needs to be executed into ArGaze root fo pip install build ``` -- Then, build argaze package: +- Then, build ArGaze package: ``` python -m build ``` -- Then, install argaze package (replace VERSION by what has been built into dist folder): +- Then, install ArGaze package (replace VERSION by what has been built into dist folder): ``` pip install ./dist/argaze-VERSION.whl @@ -71,4 +71,24 @@ pdoc -o ./doc ./src/argaze/ ``` pdoc ./src/argaze/ - ```
\ No newline at end of file + ``` + +## Test + +ArGaze package unitary tests are based on *unittest* module. +Test files tree structure is mirroring the file tree structure of src/argaze folder. + +To run all unitary tests: + +``` +python -m unittest discover ./src/argaze.test "*.py" +``` + +To run only submodule unitary tests: + +``` +python -m unittest discover ./src/argaze.test/SUBMODULE "*.py" +``` + +.. note:: Verbose mode + *Use -v option to get more details.* diff --git a/src/argaze.test/DataStructures.py b/src/argaze.test/DataStructures.py new file mode 100644 index 0000000..cab3a31 --- /dev/null +++ b/src/argaze.test/DataStructures.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +import unittest + +from argaze import DataStructures + +class TestTimeStampedBufferClass(unittest.TestCase): + """Test TimeStampedBuffer class.""" + + def test_new(self): + """Test TimeStampedBuffer creation.""" + + # Check TimeStampedBuffer length after creation + self.assertEqual(len(DataStructures.TimeStampedBuffer()), 0) + self.assertEqual(len(DataStructures.TimeStampedBuffer({0: ""})), 1) + self.assertEqual(len(DataStructures.TimeStampedBuffer({0.1: ""})), 1) + self.assertEqual(len(DataStructures.TimeStampedBuffer({0: "A", 1: "B"})), 2) + + # Check TimeStampedBuffer keys after creation + self.assertEqual(list(DataStructures.TimeStampedBuffer().keys()), []) + self.assertEqual(list(DataStructures.TimeStampedBuffer({0: ""}).keys()), [0]) + self.assertEqual(list(DataStructures.TimeStampedBuffer({0.1: ""}).keys()), [0.1]) + self.assertEqual(list(DataStructures.TimeStampedBuffer({0: "A", 1: "B"}).keys()), [0, 1]) + + # Check TimeStampedBuffer items after creation + self.assertEqual(list(DataStructures.TimeStampedBuffer().items()), []) + self.assertEqual(list(DataStructures.TimeStampedBuffer({0: ""}).items()), [(0, "")]) + self.assertEqual(list(DataStructures.TimeStampedBuffer({0.1: ""}).items()), [(0.1, "")]) + self.assertEqual(list(DataStructures.TimeStampedBuffer({0: "A", 1: "B"}).items()), [(0, "A"), (1, "B")]) + + # Check that TimeStampedBuffer creation fails when keys are not numbers + with self.assertRaises(AssertionError): + + DataStructures.TimeStampedBuffer({"first": ""}) + + def test_str(self): + """Test TimeStampedBuffer string representation.""" + + self.assertEqual(str(DataStructures.TimeStampedBuffer()), "{}") + self.assertEqual(str(DataStructures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}") + self.assertEqual(str(DataStructures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}") + + def test_append(self): + """Test TimeStampedBuffer append method.""" + + ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B"}) + ts_buffer_next = DataStructures.TimeStampedBuffer({2: "C", 3: "D"}) + + self.assertEqual(len(ts_buffer.append(ts_buffer_next)), 4) + self.assertEqual(list(ts_buffer.append(ts_buffer_next).keys()), [0, 1, 2, 3]) + +if __name__ == '__main__': + + unittest.main()
\ No newline at end of file diff --git a/src/argaze.test/GazeFeatures.py b/src/argaze.test/GazeFeatures.py new file mode 100644 index 0000000..692b6cf --- /dev/null +++ b/src/argaze.test/GazeFeatures.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import unittest + +from argaze import GazeFeatures + +class TestGazePositionClass(unittest.TestCase): + """Test GazePosition class.""" + + def test_new(self): + """Test GazePosition creation.""" + + # Check empty GazePosition + empty_gaze_position = GazeFeatures.GazePosition() + self.assertEqual(empty_gaze_position.value, (0, 0)) + self.assertEqual(empty_gaze_position.accuracy, 0.) + +if __name__ == '__main__': + + unittest.main()
\ No newline at end of file |