@@ -4,59 +4,66 @@ interface
4
4
uses
5
5
DUnitX.TestFramework;
6
6
7
+ const
8
+ CanonicalVersion = ' 1.1.0' ;
9
+
7
10
type
8
11
9
12
[TestFixture]
10
13
TBinarySearchTest = class (TObject)
11
14
public
12
15
[Test]
13
- // [Ignore('Comment the "[Ignore]" statement to run the test')]
14
- procedure Should_return_minus_one_when_an_empty_array_is_searched ;
16
+ // [Ignore('Comment the "[Ignore]" statement to run the test')]
17
+ procedure Finds_a_value_in_an_array_with_one_element ;
15
18
16
19
[Test]
17
20
[Ignore]
18
- procedure Should_be_able_to_find_a_value_in_a_single_element_array_with_one_access ;
21
+ procedure Finds_a_value_in_the_middle_of_an_array ;
19
22
20
23
[Test]
21
24
[Ignore]
22
- procedure Should_return_minus_one_if_a_value_is_less_than_the_element_in_a_single_element_array ;
25
+ procedure Finds_a_value_at_the_beginning_of_an_array ;
23
26
24
27
[Test]
25
28
[Ignore]
26
- procedure Should_return_minus_one_if_a_value_is_greater_than_the_element_in_a_single_element_array ;
29
+ procedure Finds_a_value_at_the_end_of_an_array ;
27
30
28
31
[Test]
29
32
[Ignore]
30
- procedure Should_find_an_element_in_a_longer_array ;
33
+ procedure Finds_a_value_in_an_array_of_odd_length ;
31
34
32
35
[Test]
33
36
[Ignore]
34
- procedure Should_find_elements_at_the_beginning_of_an_array ;
37
+ procedure Finds_a_value_in_an_array_of_even_length ;
35
38
36
39
[Test]
37
40
[Ignore]
38
- procedure Should_find_elements_at_the_end_of_an_array ;
41
+ procedure Identifies_that_a_value_is_not_included_in_the_array ;
39
42
40
43
[Test]
41
44
[Ignore]
42
- procedure Should_return_minus_one_if_a_value_is_less_than_all_elements_in_a_long_array ;
45
+ procedure A_value_smaller_than_the_arrays_smallest_value_is_not_included ;
43
46
44
47
[Test]
45
48
[Ignore]
46
- procedure Should_return_minus_one_if_a_value_is_greater_than_all_elements_in_a_long_array ;
49
+ procedure A_value_larger_than_the_arrays_largest_value_is_not_included ;
50
+
51
+ [Test]
52
+ [Ignore]
53
+ procedure Nothing_is_included_in_an_empty_array ;
47
54
end ;
48
55
49
56
implementation
50
57
uses System.Generics.Collections, uBinarySearch;
51
58
52
- procedure TBinarySearchTest.Should_return_minus_one_when_an_empty_array_is_searched ;
59
+ procedure TBinarySearchTest.Nothing_is_included_in_an_empty_array ;
53
60
var input: TArray<Integer>;
54
61
begin
55
62
SetLength(input, 0 );
56
63
Assert.AreEqual(-1 , BinarySearch.Search(input, 6 ));
57
64
end ;
58
65
59
- procedure TBinarySearchTest.Should_be_able_to_find_a_value_in_a_single_element_array_with_one_access ;
66
+ procedure TBinarySearchTest.Finds_a_value_in_an_array_with_one_element ;
60
67
var input: TArray<integer>;
61
68
begin
62
69
SetLength(input, 1 );
@@ -65,67 +72,76 @@ procedure TBinarySearchTest.Should_be_able_to_find_a_value_in_a_single_element_a
65
72
Assert.AreEqual(0 , BinarySearch.Search(input, 6 ));
66
73
end ;
67
74
68
- procedure TBinarySearchTest.Should_return_minus_one_if_a_value_is_less_than_the_element_in_a_single_element_array ;
69
- var input: TArray <integer>;
75
+ procedure TBinarySearchTest.Finds_a_value_in_the_middle_of_an_array ;
76
+ var inputList: TList <integer>;
70
77
begin
71
- SetLength(input, 1 ) ;
72
- input[ 0 ] := 94 ;
78
+ inputList := TList<integer>.Create ;
79
+ inputList.AddRange([ 1 , 3 , 4 , 6 , 8 , 9 , 11 ]) ;
73
80
74
- Assert.AreEqual(- 1 , BinarySearch.Search(input , 6 ));
81
+ Assert.AreEqual(3 , BinarySearch.Search(inputList.ToArray , 6 ));
75
82
end ;
76
83
77
- procedure TBinarySearchTest.Should_return_minus_one_if_a_value_is_greater_than_the_element_in_a_single_element_array ;
78
- var input: TArray <integer>;
84
+ procedure TBinarySearchTest.Finds_a_value_at_the_beginning_of_an_array ;
85
+ var inputList: TList <integer>;
79
86
begin
80
- SetLength(input, 1 );
81
- input[0 ] := 94 ;
87
+ inputList := TList<integer>.Create;
88
+ inputList.AddRange([1 , 3 , 4 , 6 , 8 , 9 , 11 ]);
89
+
90
+ Assert.AreEqual(0 , BinarySearch.Search(inputList.ToArray, 1 ));
91
+ end ;
92
+
93
+ procedure TBinarySearchTest.Finds_a_value_at_the_end_of_an_array ;
94
+ var inputList: TList<integer>;
95
+ begin
96
+ inputList := TList<integer>.Create;
97
+ inputList.AddRange([1 , 3 , 4 , 6 , 8 , 9 , 11 ]);
82
98
83
- Assert.AreEqual(- 1 , BinarySearch.Search(input, 602 ));
99
+ Assert.AreEqual(6 , BinarySearch.Search(inputList.ToArray, 11 ));
84
100
end ;
85
101
86
- procedure TBinarySearchTest.Should_find_an_element_in_a_longer_array ;
102
+ procedure TBinarySearchTest.Finds_a_value_in_an_array_of_odd_length ;
87
103
var inputList: TList<integer>;
88
104
begin
89
105
inputList := TList<integer>.Create;
90
- inputList.AddRange([6 , 67 , 123 , 345 , 456 , 457 , 490 , 2002 , 54321 , 54322 ]);
106
+ inputList.AddRange([1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 , 634 ]);
91
107
92
- Assert.AreEqual(7 , BinarySearch.Search(inputList.ToArray, 2002 ));
108
+ Assert.AreEqual(9 , BinarySearch.Search(inputList.ToArray, 144 ));
93
109
end ;
94
110
95
- procedure TBinarySearchTest.Should_find_elements_at_the_beginning_of_an_array ;
111
+ procedure TBinarySearchTest.Finds_a_value_in_an_array_of_even_length ;
96
112
var inputList: TList<integer>;
97
113
begin
98
114
inputList := TList<integer>.Create;
99
- inputList.AddRange([6 , 67 , 123 , 345 , 456 , 457 , 490 , 2002 , 54321 , 54322 ]);
115
+ inputList.AddRange([1 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 377 ]);
100
116
101
- Assert.AreEqual(0 , BinarySearch.Search(inputList.ToArray, 6 ));
117
+ Assert.AreEqual(5 , BinarySearch.Search(inputList.ToArray, 21 ));
102
118
end ;
103
119
104
- procedure TBinarySearchTest.Should_find_elements_at_the_end_of_an_array ;
120
+ procedure TBinarySearchTest.Identifies_that_a_value_is_not_included_in_the_array ;
105
121
var inputList: TList<integer>;
106
122
begin
107
123
inputList := TList<integer>.Create;
108
- inputList.AddRange([6 , 67 , 123 , 345 , 456 , 457 , 490 , 2002 , 54321 , 54322 ]);
124
+ inputList.AddRange([1 , 3 , 4 , 6 , 8 , 9 , 11 ]);
109
125
110
- Assert.AreEqual(9 , BinarySearch.Search(inputList.ToArray, 54322 ));
126
+ Assert.AreEqual(- 1 , BinarySearch.Search(inputList.ToArray, 7 ));
111
127
end ;
112
128
113
- procedure TBinarySearchTest.Should_return_minus_one_if_a_value_is_less_than_all_elements_in_a_long_array ;
129
+ procedure TBinarySearchTest.A_value_larger_than_the_arrays_largest_value_is_not_included ;
114
130
var inputList: TList<integer>;
115
131
begin
116
132
inputList := TList<integer>.Create;
117
- inputList.AddRange([6 , 67 , 123 , 345 , 456 , 457 , 490 , 2002 , 54321 , 54322 ]);
133
+ inputList.AddRange([1 , 3 , 4 , 6 , 8 , 9 , 11 ]);
118
134
119
- Assert.AreEqual(-1 , BinarySearch.Search(inputList.ToArray, 2 ));
135
+ Assert.AreEqual(-1 , BinarySearch.Search(inputList.ToArray, 13 ));
120
136
end ;
121
137
122
- procedure TBinarySearchTest.Should_return_minus_one_if_a_value_is_greater_than_all_elements_in_a_long_array ;
138
+ procedure TBinarySearchTest.A_value_smaller_than_the_arrays_smallest_value_is_not_included ;
123
139
var inputList: TList<integer>;
124
140
begin
125
141
inputList := TList<integer>.Create;
126
- inputList.AddRange([6 , 67 , 123 , 345 , 456 , 457 , 490 , 2002 , 54321 , 54322 ]);
142
+ inputList.AddRange([1 , 3 , 4 , 6 , 8 , 9 , 11 ]);
127
143
128
- Assert.AreEqual(-1 , BinarySearch.Search(inputList.ToArray, 54323 ));
144
+ Assert.AreEqual(-1 , BinarySearch.Search(inputList.ToArray, 0 ));
129
145
end ;
130
146
131
147
initialization
0 commit comments