-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sort_by_priority.py
30 lines (25 loc) · 1.44 KB
/
test_sort_by_priority.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from arrayutilities import Arr
import unittest
class TestSortByPriority(unittest.TestCase):
def test_sort_by_priority_empty_array(self):
input_array = []
expected_result = []
result = Arr.sort_by_priority(input_array)
self.assertEqual(result, expected_result, "Should return an empty array for an empty input array")
def test_sort_by_priority_single_element(self):
input_array = [{'priority': 2}]
expected_result = [{'priority': 2}]
result = Arr.sort_by_priority(input_array)
self.assertEqual(result, expected_result, "Should return the same array for a single element array")
def test_sort_by_priority_no_priority_key(self):
input_array = [{'name': 'John'}, {'age': 25}]
expected_result = [{'name': 'John'}, {'age': 25}]
result = Arr.sort_by_priority(input_array)
self.assertEqual(result, expected_result, "Should return the same array when priority key is missing")
def test_sort_by_priority_multiple_elements(self):
input_array = [{'name': 'John', 'priority': 2}, {'name': 'Alice', 'priority': 1}, {'name': 'Bob', 'priority': 3}]
expected_result = [{'name': 'Alice', 'priority': 1}, {'name': 'John', 'priority': 2}, {'name': 'Bob', 'priority': 3}]
result = Arr.sort_by_priority(input_array)
self.assertEqual(result, expected_result, "Should sort the array based on priority")
if __name__ == '__main__':
unittest.main()