diff options
author | Théo de la Hogue | 2022-11-16 11:17:51 +0100 |
---|---|---|
committer | Théo de la Hogue | 2022-11-16 11:17:51 +0100 |
commit | d0846c8a5a5ab7a66eeb79c2caee5bf87a98c4be (patch) | |
tree | 8033d9c38be032d727bd617dc8fb4e8f17b9f94f /src/argaze.test/DataStructures.py | |
parent | eb5bf6508231d50f79090c43e7237cb9735eb7d8 (diff) | |
download | argaze-d0846c8a5a5ab7a66eeb79c2caee5bf87a98c4be.zip argaze-d0846c8a5a5ab7a66eeb79c2caee5bf87a98c4be.tar.gz argaze-d0846c8a5a5ab7a66eeb79c2caee5bf87a98c4be.tar.bz2 argaze-d0846c8a5a5ab7a66eeb79c2caee5bf87a98c4be.tar.xz |
Adding unitary tests.
Diffstat (limited to 'src/argaze.test/DataStructures.py')
-rw-r--r-- | src/argaze.test/DataStructures.py | 54 |
1 files changed, 54 insertions, 0 deletions
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 |