44
55
66class BinarySearchTests (unittest .TestCase ):
7-
87 def test_finds_value_in_array_with_one_element (self ):
9- self .assertEqual (0 , binary_search ([6 ], 6 ))
8+ self .assertEqual (binary_search ([6 ], 6 ), 0 )
109
1110 def test_finds_value_in_middle_of_array (self ):
12- self .assertEqual (3 , binary_search ([1 , 3 , 4 , 6 , 8 , 9 , 11 ], 6 ))
11+ self .assertEqual (binary_search ([1 , 3 , 4 , 6 , 8 , 9 , 11 ], 6 ), 3 )
1312
1413 def test_finds_value_at_beginning_of_array (self ):
15- self .assertEqual (0 , binary_search ([1 , 3 , 4 , 6 , 8 , 9 , 11 ], 1 ))
14+ self .assertEqual (binary_search ([1 , 3 , 4 , 6 , 8 , 9 , 11 ], 1 ), 0 )
1615
1716 def test_finds_value_at_end_of_array (self ):
18- self .assertEqual (6 , binary_search ([1 , 3 , 4 , 6 , 8 , 9 , 11 ], 11 ))
17+ self .assertEqual (binary_search ([1 , 3 , 4 , 6 , 8 , 9 , 11 ], 11 ), 6 )
1918
2019 def test_finds_value_in_array_of_odd_length (self ):
21- self .assertEqual (9 , binary_search (
22- [1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 634 ], 144 ))
20+ self .assertEqual (
21+ binary_search ([1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 634 ],
22+ 144 ), 9 )
2323
2424 def test_finds_value_in_array_of_even_length (self ):
25- self .assertEqual (5 , binary_search (
26- [1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 ], 21 ))
25+ self .assertEqual (
26+ binary_search ([1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 ], 21 ),
27+ 5 )
2728
2829 def test_identifies_value_missing (self ):
2930 self .assertRaises (ValueError , binary_search , [1 , 3 , 4 , 6 , 8 , 9 , 11 ], 7 )
@@ -32,7 +33,8 @@ def test_value_smaller_than_arrays_minimum(self):
3233 self .assertRaises (ValueError , binary_search , [1 , 3 , 4 , 6 , 8 , 9 , 11 ], 0 )
3334
3435 def test_value_larger_than_arrays_maximum (self ):
35- self .assertRaises (ValueError , binary_search , [1 , 3 , 4 , 6 , 8 , 9 , 11 ], 13 )
36+ self .assertRaises (ValueError , binary_search , [1 , 3 , 4 , 6 , 8 , 9 , 11 ],
37+ 13 )
3638
3739 def test_empty_array (self ):
3840 self .assertRaises (ValueError , binary_search , [], 1 )
0 commit comments