generated from CambridgeEngineering/PartIA-Flood-Warning-System
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_utils.py
57 lines (44 loc) · 1.34 KB
/
test_utils.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Unit test for the utils module"""
import floodsystem.utils
def test_sort():
"""Test sort container by specific index"""
a = (10, 3, 3)
b = (5, 1, -1)
c = (1, -3, 4)
list0 = (a, b, c)
# Test sort on 1st entry
list1 = floodsystem.utils.sorted_by_key(list0, 0)
assert list1[0] == c
assert list1[1] == b
assert list1[2] == a
# Test sort on 2nd entry
list1 = floodsystem.utils.sorted_by_key(list0, 1)
assert list1[0] == c
assert list1[1] == b
assert list1[2] == a
# Test sort on 3rd entry
list1 = floodsystem.utils.sorted_by_key(list0, 2)
assert list1[0] == b
assert list1[1] == a
assert list1[2] == c
def test_reverse_sort():
"""Test sort container by specific index (reverse)"""
a = (10, 3, 3)
b = (5, 1, -1)
c = (1, -3, 4)
list0 = (a, b, c)
# Test sort on 1st entry
list1 = floodsystem.utils.sorted_by_key(list0, 0, reverse=True)
assert list1[0] == a
assert list1[1] == b
assert list1[2] == c
# Test sort on 2nd entry
list1 = floodsystem.utils.sorted_by_key(list0, 1, reverse=True)
assert list1[0] == a
assert list1[1] == b
assert list1[2] == c
# Test sort on 3rd entry
list1 = floodsystem.utils.sorted_by_key(list0, 2, reverse=True)
assert list1[0] == c
assert list1[1] == a
assert list1[2] == b