1
exercism fetch csharp binary-search

BinarySearchTest.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// This file was auto-generated based on version 1.1.0 of the canonical data.

using Xunit;

public class BinarySearchTest
{
    [Fact]
    public void Finds_a_value_in_an_array_with_one_element()
    {
        var array = new[] { 6 };
        var sut = new BinarySearch(array);
        Assert.Equal(0, sut.Find(6));
    }

    [Fact(Skip = "Remove to run test")]
    public void Finds_a_value_in_the_middle_of_an_array()
    {
        var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
        var sut = new BinarySearch(array);
        Assert.Equal(3, sut.Find(6));
    }

    [Fact(Skip = "Remove to run test")]
    public void Finds_a_value_at_the_beginning_of_an_array()
    {
        var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
        var sut = new BinarySearch(array);
        Assert.Equal(0, sut.Find(1));
    }

    [Fact(Skip = "Remove to run test")]
    public void Finds_a_value_at_the_end_of_an_array()
    {
        var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
        var sut = new BinarySearch(array);
        Assert.Equal(6, sut.Find(11));
    }

    [Fact(Skip = "Remove to run test")]
    public void Finds_a_value_in_an_array_of_odd_length()
    {
        var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634 };
        var sut = new BinarySearch(array);
        Assert.Equal(9, sut.Find(144));
    }

    [Fact(Skip = "Remove to run test")]
    public void Finds_a_value_in_an_array_of_even_length()
    {
        var array = new[] { 1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 };
        var sut = new BinarySearch(array);
        Assert.Equal(5, sut.Find(21));
    }

    [Fact(Skip = "Remove to run test")]
    public void Identifies_that_a_value_is_not_included_in_the_array()
    {
        var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
        var sut = new BinarySearch(array);
        Assert.Equal(-1, sut.Find(7));
    }

    [Fact(Skip = "Remove to run test")]
    public void A_value_smaller_than_the_arrays_smallest_value_is_not_included()
    {
        var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
        var sut = new BinarySearch(array);
        Assert.Equal(-1, sut.Find(0));
    }

    [Fact(Skip = "Remove to run test")]
    public void A_value_larger_than_the_arrays_largest_value_is_not_included()
    {
        var array = new[] { 1, 3, 4, 6, 8, 9, 11 };
        var sut = new BinarySearch(array);
        Assert.Equal(-1, sut.Find(13));
    }

    [Fact(Skip = "Remove to run test")]
    public void Nothing_is_included_in_an_empty_array()
    {
        var array = new int[0];
        var sut = new BinarySearch(array);
        Assert.Equal(-1, sut.Find(1));
    }
}