4
4
5
5
# For importing from different folders
6
6
# OBS: This is supposed to be done with automated testing, hence relative to folder we want to import from
7
- # sys.path.append('Algorithms/other')
7
+ sys .path .append ('Algorithms/other' )
8
8
9
9
# If run from local:
10
- sys .path .append ('../../Algorithms/other' )
10
+ # sys.path.append('../../Algorithms/other')
11
11
12
- from binarysearch import binarysearch_iterative , binarysearch_recursive
12
+ from interval_scheduling import interval_scheduling
13
13
14
14
15
- class test_binarysearch (unittest .TestCase ):
15
+ class test_intervalscheduling (unittest .TestCase ):
16
16
17
17
def setUp (self ):
18
18
# test cases we wish to run
19
- self .L1 = [1 , 3 , 5 , 8 , 10 , 12 ]
20
- self .L1_target = 5
21
- self .L1_correct = True , 2
19
+ self .R1 = [(0 , 5 ), (3 , 6 ),(5 , 10 )]
20
+ self .R1_correct = [(0 ,5 ), (5 ,10 )]
22
21
23
- self .L2 = [1 , 3 , 5 , 8 , 10 , 12 ]
24
- self .L2_target = 6
25
- self .L2_correct = False , None
22
+ self .R2 = []
23
+ self .R2_correct = []
26
24
27
- self .L3 = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ]
28
- self .L3_target = 1
29
- self .L3_correct = True , (0 + len (self .L3 )- 1 )// 2
25
+ self .R3 = [(0 , 3 ), (3 ,6 ), (6 ,9 ), (9 , 10 )]
26
+ self .R3_correct = [(0 , 3 ), (3 ,6 ), (6 ,9 ), (9 , 10 )]
30
27
31
- self .L4 = [1 , 3 , 6 , 11 , 16 , 21 , 25 , 27 ]
32
- self .L4_target = 27
33
- self .L4_correct = True , len (self .L4 )- 1
28
+ self .R4 = [(1 , 3 ), (0 , 2 ), (1 , 4 ), (2 , 5 )]
29
+ self .R4_correct = [(0 ,2 ), (2 ,5 )]
34
30
35
- self .L5 = [1 , 3 , 6 , 11 , 16 , 21 , 27 ]
36
- self .L5_target = 1
37
- self .L5_correct = True , 0
31
+ self .R5 = [(0 ,3 )]
32
+ self .R5_correct = [(0 ,3 )]
38
33
39
- self .L6 = []
40
- self .L6_target = 10
41
- self .L6_correct = False , None
42
34
43
- self .L7 = [11 ,12 ,15 ,19 ,23 ,41 ,173 ,298 ]
44
- self .L7_target = 12
45
- self .L7_correct = True , 1
35
+ def test_intervalscheduling_basic (self ):
36
+ O = []
37
+ O = interval_scheduling (self .R1 , O )
38
+ self .assertEqual (O , self .R1_correct )
46
39
40
+ def test_intervalscheduling_empty (self ):
41
+ O = []
42
+ O = interval_scheduling (self .R2 , O )
43
+ self .assertEqual (O , self .R2_correct )
47
44
48
- def test_binarysearch_basic (self ):
49
- L1_result_iterative = binarysearch_iterative (self .L1 , self .L1_target )
50
- L1_result_recursive = binarysearch_recursive (self .L1 , self .L1_target , 0 , len (self .L1 )- 1 )
45
+ def test_intervalscheduling_take_all (self ):
46
+ O = []
47
+ O = interval_scheduling (self .R3 , O )
48
+ self .assertEqual (O , self .R3_correct )
51
49
52
- self .assertEqual (L1_result_iterative , self .L1_correct )
53
- self .assertEqual (L1_result_recursive , self .L1_correct )
50
+ def test_intervalscheduling_unsorted (self ):
51
+ O = []
52
+ O = interval_scheduling (self .R4 , O )
53
+ self .assertEqual (O , self .R4_correct )
54
54
55
- def test_binarysearch_nonexistant (self ):
56
- L2_result_iterative = binarysearch_iterative (self .L2 , self .L2_target )
57
- L2_result_recursive = binarysearch_recursive (self .L2 , self .L2_target , 0 , len (self .L1 )- 1 )
58
-
59
- self .assertEqual (L2_result_iterative , self .L2_correct )
60
- self .assertEqual (L2_result_recursive , self .L2_correct )
61
-
62
- def test_binarysearch_identical (self ):
63
- L3_result_iterative = binarysearch_iterative (self .L3 , self .L3_target )
64
- L3_result_recursive = binarysearch_recursive (self .L3 , self .L3_target , 0 , len (self .L3 ) - 1 )
65
-
66
- self .assertEqual (L3_result_iterative , self .L3_correct )
67
- self .assertEqual (L3_result_recursive , self .L3_correct )
68
-
69
- def test_binarysearch_lastvalue (self ):
70
- L4_result_iterative = binarysearch_iterative (self .L4 , self .L4_target )
71
- L4_result_recursive = binarysearch_recursive (self .L4 , self .L4_target , 0 , len (self .L4 ) - 1 )
72
-
73
- self .assertEqual (L4_result_iterative , self .L4_correct )
74
- self .assertEqual (L4_result_recursive , self .L4_correct )
75
-
76
- def test_binarysearch_firstvalue (self ):
77
- L5_result_iterative = binarysearch_iterative (self .L5 , self .L5_target )
78
- L5_result_recursive = binarysearch_recursive (self .L5 , self .L5_target , 0 , len (self .L5 ) - 1 )
79
-
80
- self .assertEqual (L5_result_iterative , self .L5_correct )
81
- self .assertEqual (L5_result_recursive , self .L5_correct )
82
-
83
- def test_binarysearch_empty (self ):
84
- L6_result_iterative = binarysearch_iterative (self .L6 , self .L6_target )
85
- L6_result_recursive = binarysearch_recursive (self .L6 , self .L6_target , 0 , len (self .L6 ) - 1 )
86
-
87
- self .assertEqual (L6_result_iterative , self .L6_correct )
88
- self .assertEqual (L6_result_recursive , self .L6_correct )
89
-
90
- def test_binarysearch_standard (self ):
91
- L7_result_iterative = binarysearch_iterative (self .L7 , self .L7_target )
92
- L7_result_recursive = binarysearch_recursive (self .L7 , self .L7_target , 0 , len (self .L7 ) - 1 )
93
-
94
- self .assertEqual (L7_result_iterative , self .L7_correct )
95
- self .assertEqual (L7_result_recursive , self .L7_correct )
55
+ def test_intervalscheduling_one_element (self ):
56
+ O = []
57
+ O = interval_scheduling (self .R5 , O )
58
+ self .assertEqual (O , self .R5_correct )
96
59
97
60
98
61
if __name__ == '__main__' :
99
- print ("Running sorting tests:" )
62
+ print ("Running Interval Scheduling tests:" )
100
63
unittest .main ()
0 commit comments