@@ -3,81 +3,80 @@ const testing = std.testing;
33
44const binary_search = @import ("binary_search.zig" );
55const binarySearch = binary_search .binarySearch ;
6- const SearchError = binary_search .SearchError ;
76
87test "finds a value in an array with one element" {
9- const expected : usize = 0 ;
8+ const expected : ? usize = 0 ;
109 const array = [_ ]i4 {6 };
11- const actual = try binarySearch (i4 , 6 , & array );
10+ const actual = binarySearch (i4 , 6 , & array );
1211 try testing .expectEqual (expected , actual );
1312}
1413
1514test "finds a value in the middle of an array" {
16- const expected : usize = 3 ;
15+ const expected : ? usize = 3 ;
1716 const array = [_ ]u4 { 1 , 3 , 4 , 6 , 8 , 9 , 11 };
18- const actual = try binarySearch (u4 , 6 , & array );
17+ const actual = binarySearch (u4 , 6 , & array );
1918 try testing .expectEqual (expected , actual );
2019}
2120
2221test "finds a value at the beginning of an array" {
23- const expected : usize = 0 ;
22+ const expected : ? usize = 0 ;
2423 const array = [_ ]i8 { 1 , 3 , 4 , 6 , 8 , 9 , 11 };
25- const actual = try binarySearch (i8 , 1 , & array );
24+ const actual = binarySearch (i8 , 1 , & array );
2625 try testing .expectEqual (expected , actual );
2726}
2827
2928test "finds a value at the end of an array" {
30- const expected : usize = 6 ;
29+ const expected : ? usize = 6 ;
3130 const array = [_ ]u8 { 1 , 3 , 4 , 6 , 8 , 9 , 11 };
32- const actual = try binarySearch (u8 , 11 , & array );
31+ const actual = binarySearch (u8 , 11 , & array );
3332 try testing .expectEqual (expected , actual );
3433}
3534
3635test "finds a value in an array of odd length" {
37- const expected : usize = 5 ;
36+ const expected : ? usize = 5 ;
3837 const array = [_ ]i16 { 1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 634 };
39- const actual = try binarySearch (i16 , 21 , & array );
38+ const actual = binarySearch (i16 , 21 , & array );
4039 try testing .expectEqual (expected , actual );
4140}
4241
4342test "finds a value in an array of even length" {
44- const expected : usize = 5 ;
43+ const expected : ? usize = 5 ;
4544 const array = [_ ]u16 { 1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 };
46- const actual = try binarySearch (u16 , 21 , & array );
45+ const actual = binarySearch (u16 , 21 , & array );
4746 try testing .expectEqual (expected , actual );
4847}
4948
5049test "identifies that a value is not included in the array" {
51- const expected = SearchError . ValueAbsent ;
50+ const expected : ? usize = null ;
5251 const array = [_ ]i32 { 1 , 3 , 4 , 6 , 8 , 9 , 11 };
5352 const actual = binarySearch (i32 , 7 , & array );
54- try testing .expectError (expected , actual );
53+ try testing .expectEqual (expected , actual );
5554}
5655
5756test "a value smaller than the array's smallest value is not found" {
58- const expected = SearchError . ValueAbsent ;
57+ const expected : ? usize = null ;
5958 const array = [_ ]u32 { 1 , 3 , 4 , 6 , 8 , 9 , 11 };
6059 const actual = binarySearch (u32 , 0 , & array );
61- try testing .expectError (expected , actual );
60+ try testing .expectEqual (expected , actual );
6261}
6362
6463test "a value larger than the array's largest value is not found" {
65- const expected = SearchError . ValueAbsent ;
64+ const expected : ? usize = null ;
6665 const array = [_ ]i64 { 1 , 3 , 4 , 6 , 8 , 9 , 11 };
6766 const actual = binarySearch (i64 , 13 , & array );
68- try testing .expectError (expected , actual );
67+ try testing .expectEqual (expected , actual );
6968}
7069
7170test "nothing is found in an empty array" {
72- const expected = SearchError . EmptyBuffer ;
71+ const expected : ? usize = null ;
7372 const array = [_ ]u64 {};
7473 const actual = binarySearch (u64 , 13 , & array );
75- try testing .expectError (expected , actual );
74+ try testing .expectEqual (expected , actual );
7675}
7776
7877test "nothing is found when the left and right bounds cross" {
79- const expected = SearchError . ValueAbsent ;
78+ const expected : ? usize = null ;
8079 const array = [_ ]isize { 1 , 2 };
8180 const actual = binarySearch (isize , 13 , & array );
82- try testing .expectError (expected , actual );
81+ try testing .expectEqual (expected , actual );
8382}
0 commit comments