summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/network_packetTest.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/network_packetTest.py b/tests/network_packetTest.py
new file mode 100644
index 0000000..c5bb709
--- /dev/null
+++ b/tests/network_packetTest.py
@@ -0,0 +1,52 @@
+import unittest
+
+from collections import namedtuple
+
+Request = namedtuple("Request", ["arrived_at", "time_to_process"])
+Response = namedtuple("Response", ["was_dropped", "started_at"])
+
+import sources.network_packet
+from sources.network_packet import process_requests
+
+
+class MyTestCase(unittest.TestCase):
+ def test(self):
+ buffer_max_size = 1
+ buf = sources.network_packet.Buffer(buffer_max_size)
+ requests = []
+ responses = process_requests(requests, buf)
+ self.assertEqual(0, len(responses))
+
+ def test1(self):
+ buffer_max_size = 1
+ buf = sources.network_packet.Buffer(buffer_max_size)
+ requests = [Request(0, 1)]
+ responses = process_requests(requests, buf)
+ self.assertEqual(1, len(responses))
+ self.assertFalse(responses[0].was_dropped)
+ self.assertEqual(0, responses[0].started_at)
+
+ def test2(self):
+ buffer_max_size = 1
+ buf = sources.network_packet.Buffer(buffer_max_size)
+ requests = [Request(0, 1), Request(0, 1)]
+ responses = process_requests(requests, buf)
+ self.assertEqual(2, len(responses))
+ self.assertFalse(responses[0].was_dropped)
+ self.assertEqual(0, responses[0].started_at)
+ self.assertTrue(responses[1].was_dropped)
+
+ def test3(self):
+ buffer_max_size = 1
+ buf = sources.network_packet.Buffer(buffer_max_size)
+ requests = [Request(0, 1), Request(1, 1)]
+ responses = process_requests(requests, buf)
+ self.assertEqual(2, len(responses))
+ self.assertFalse(responses[0].was_dropped)
+ self.assertEqual(0, responses[0].started_at)
+ self.assertFalse(responses[1].was_dropped)
+ self.assertEqual(1, responses[1].started_at)
+
+
+if __name__ == '__main__':
+ unittest.main()