Skip to content

Commit 0cee4a7

Browse files
binary-search: add generator
1 parent f29b16e commit 0cee4a7

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using Xunit;
3+
4+
public class {{testClass}}
5+
{
6+
{{for test in tests}}
7+
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}]
8+
public void {{test.testMethod}}()
9+
{
10+
Assert.Equal({{if test.expected.error}}-1{{else}}{{test.expected}}{{end}}, {{testedClass}}.{{test.testedMethod}}({{test.input.array}}, {{test.input.value}}));
11+
}
12+
{{end}}
13+
}

exercises/practice/binary-search/BinarySearchTests.cs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,88 +6,66 @@ public class BinarySearchTests
66
[Fact]
77
public void Finds_a_value_in_an_array_with_one_element()
88
{
9-
var array = new[] { 6 };
10-
var value = 6;
11-
Assert.Equal(0, BinarySearch.Find(array, value));
9+
Assert.Equal(0, BinarySearch.Find([6], 6));
1210
}
1311

1412
[Fact(Skip = "Remove this Skip property to run this test")]
1513
public void Finds_a_value_in_the_middle_of_an_array()
1614
{
17-
var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
18-
var value = 6;
19-
Assert.Equal(3, BinarySearch.Find(array, value));
15+
Assert.Equal(3, BinarySearch.Find([1, 3, 4, 6, 8, 9, 11], 6));
2016
}
2117

2218
[Fact(Skip = "Remove this Skip property to run this test")]
2319
public void Finds_a_value_at_the_beginning_of_an_array()
2420
{
25-
var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
26-
var value = 1;
27-
Assert.Equal(0, BinarySearch.Find(array, value));
21+
Assert.Equal(0, BinarySearch.Find([1, 3, 4, 6, 8, 9, 11], 1));
2822
}
2923

3024
[Fact(Skip = "Remove this Skip property to run this test")]
3125
public void Finds_a_value_at_the_end_of_an_array()
3226
{
33-
var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
34-
var value = 11;
35-
Assert.Equal(6, BinarySearch.Find(array, value));
27+
Assert.Equal(6, BinarySearch.Find([1, 3, 4, 6, 8, 9, 11], 11));
3628
}
3729

3830
[Fact(Skip = "Remove this Skip property to run this test")]
3931
public void Finds_a_value_in_an_array_of_odd_length()
4032
{
41-
var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634 };
42-
var value = 144;
43-
Assert.Equal(9, BinarySearch.Find(array, value));
33+
Assert.Equal(9, BinarySearch.Find([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], 144));
4434
}
4535

4636
[Fact(Skip = "Remove this Skip property to run this test")]
4737
public void Finds_a_value_in_an_array_of_even_length()
4838
{
49-
var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 };
50-
var value = 21;
51-
Assert.Equal(5, BinarySearch.Find(array, value));
39+
Assert.Equal(5, BinarySearch.Find([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21));
5240
}
5341

5442
[Fact(Skip = "Remove this Skip property to run this test")]
5543
public void Identifies_that_a_value_is_not_included_in_the_array()
5644
{
57-
var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
58-
var value = 7;
59-
Assert.Equal(-1, BinarySearch.Find(array, value));
45+
Assert.Equal(-1, BinarySearch.Find([1, 3, 4, 6, 8, 9, 11], 7));
6046
}
6147

6248
[Fact(Skip = "Remove this Skip property to run this test")]
63-
public void A_value_smaller_than_the_arrays_smallest_value_is_not_found()
49+
public void A_value_smaller_than_the_array_s_smallest_value_is_not_found()
6450
{
65-
var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
66-
var value = 0;
67-
Assert.Equal(-1, BinarySearch.Find(array, value));
51+
Assert.Equal(-1, BinarySearch.Find([1, 3, 4, 6, 8, 9, 11], 0));
6852
}
6953

7054
[Fact(Skip = "Remove this Skip property to run this test")]
71-
public void A_value_larger_than_the_arrays_largest_value_is_not_found()
55+
public void A_value_larger_than_the_array_s_largest_value_is_not_found()
7256
{
73-
var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
74-
var value = 13;
75-
Assert.Equal(-1, BinarySearch.Find(array, value));
57+
Assert.Equal(-1, BinarySearch.Find([1, 3, 4, 6, 8, 9, 11], 13));
7658
}
7759

7860
[Fact(Skip = "Remove this Skip property to run this test")]
7961
public void Nothing_is_found_in_an_empty_array()
8062
{
81-
var array = Array.Empty<int>();
82-
var value = 1;
83-
Assert.Equal(-1, BinarySearch.Find(array, value));
63+
Assert.Equal(-1, BinarySearch.Find([], 1));
8464
}
8565

8666
[Fact(Skip = "Remove this Skip property to run this test")]
8767
public void Nothing_is_found_when_the_left_and_right_bounds_cross()
8868
{
89-
var array = new[] { 1, 2 };
90-
var value = 0;
91-
Assert.Equal(-1, BinarySearch.Find(array, value));
69+
Assert.Equal(-1, BinarySearch.Find([1, 2], 0));
9270
}
9371
}

0 commit comments

Comments
 (0)