Browse Source

added Utility tests for new Utility functions

Stefano Acquaviti 6 năm trước cách đây
mục cha
commit
0dd121c4bd
1 tập tin đã thay đổi với 45 bổ sung1 xóa
  1. 45 1
      code/Test/test_Utility.py

+ 45 - 1
code/Test/test_Utility.py

@@ -56,7 +56,10 @@ class TestUtility(unittest.TestCase):
         self.assertIn(Utility.get_rnd_os(), Utility.platforms)
 
     def test_check_platform_valid(self):
-        Utility.check_platform("linux")
+        try:
+            Utility.check_platform("linux")
+        except SystemExit:
+            self.fail()
 
     def test_check_platform_invalid(self):
         with self.assertRaises(SystemExit):
@@ -191,3 +194,44 @@ class TestUtility(unittest.TestCase):
     def test_get_bytes_from_file_hex(self):
         result = Utility.get_bytes_from_file(TestLibrary.test_resource_dir+"/HexTestFile.txt")
         self.assertEqual(result, b'\xab\xcd\xef\xff\x10\xff\xaa\xab')
+
+    def test_handle_most_used_outputs_empty(self):
+        self.assertIsNone(Utility.handle_most_used_outputs([]))
+
+    def test_handle_most_used_outputs_one(self):
+        test_input = "SomeTest"
+        self.assertEqual(Utility.handle_most_used_outputs(test_input), test_input)
+
+    def test_handle_most_used_outputs_one_list(self):
+        test_input = ["SomeTest"]
+        self.assertEqual(Utility.handle_most_used_outputs(test_input), test_input[0])
+
+    def test_handle_most_used_outputs_list_sorted(self):
+        test_input = [0, 1, 2, 3, 4]
+        self.assertEqual(Utility.handle_most_used_outputs(test_input), 0)
+
+    def test_handle_most_used_outputs_list_unsorted(self):
+        test_input = [2, 4, 0, 1, 3]
+        self.assertEqual(Utility.handle_most_used_outputs(test_input), 0)
+
+    def test_rreplace_not_in_string(self):
+        self.assertEqual(Utility.rreplace("testateststring", "nonexisting", "correct", 1), "testateststring")
+
+    def test_rreplace_zero(self):
+        self.assertEqual(Utility.rreplace("testateststring", "test", "correct", 0), "testateststring")
+
+    def test_rreplace_one(self):
+        self.assertEqual(Utility.rreplace("testateststring", "test", "correct", 1), "testacorrectstring")
+
+    def test_rreplace_two(self):
+        self.assertEqual(Utility.rreplace("testateststring", "test", "correct", 2), "correctacorrectstring")
+
+    def test_check_payload_len_exceeded(self):
+        with self.assertRaises(SystemExit):
+            Utility.check_payload_len(10, 5)
+
+    def test_check_payload_len_valid(self):
+        try:
+            Utility.check_payload_len(5, 10)
+        except SystemExit:
+            self.fail()