Skip to content

Commit

Permalink
generators: Use updated canonical data parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored and Erik Schierboom committed May 24, 2018
1 parent d3019f1 commit 3fa323d
Show file tree
Hide file tree
Showing 112 changed files with 1,183 additions and 992 deletions.
4 changes: 2 additions & 2 deletions exercises/all-your-base/AllYourBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Number_15_bit_integer()
public void Empty_list()
{
var inputBase = 2;
var digits = new[] { };
var digits = new int[0];
var outputBase = 10;
var expected = new[] { 0 };
Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase));
Expand Down Expand Up @@ -138,7 +138,7 @@ public void Input_base_is_one()
public void Input_base_is_zero()
{
var inputBase = 0;
var digits = new[] { };
var digits = new int[0];
var outputBase = 10;
Assert.Throws<ArgumentException>(() => AllYourBase.Rebase(inputBase, digits, outputBase));
}
Expand Down
36 changes: 24 additions & 12 deletions exercises/anagram/AnagramTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,102 @@ public class AnagramTest
[Fact]
public void No_matches()
{
var candidates = new[] { "hello", "world", "zombies", "pants" };
var sut = new Anagram("diaper");
Assert.Empty(sut.Anagrams());
Assert.Empty(sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Detects_two_anagrams()
{
var candidates = new[] { "stream", "pigeon", "maters" };
var sut = new Anagram("master");
var expected = new[] { "stream", "maters" };
Assert.Equal(expected, sut.Anagrams());
Assert.Equal(expected, sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Does_not_detect_anagram_subsets()
{
var candidates = new[] { "dog", "goody" };
var sut = new Anagram("good");
Assert.Empty(sut.Anagrams());
Assert.Empty(sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Detects_anagram()
{
var candidates = new[] { "enlists", "google", "inlets", "banana" };
var sut = new Anagram("listen");
var expected = new[] { "inlets" };
Assert.Equal(expected, sut.Anagrams());
Assert.Equal(expected, sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Detects_three_anagrams()
{
var candidates = new[] { "gallery", "ballerina", "regally", "clergy", "largely", "leading" };
var sut = new Anagram("allergy");
var expected = new[] { "gallery", "regally", "largely" };
Assert.Equal(expected, sut.Anagrams());
Assert.Equal(expected, sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Does_not_detect_non_anagrams_with_identical_checksum()
{
var candidates = new[] { "last" };
var sut = new Anagram("mass");
Assert.Empty(sut.Anagrams());
Assert.Empty(sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Detects_anagrams_case_insensitively()
{
var candidates = new[] { "cashregister", "Carthorse", "radishes" };
var sut = new Anagram("Orchestra");
var expected = new[] { "Carthorse" };
Assert.Equal(expected, sut.Anagrams());
Assert.Equal(expected, sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Detects_anagrams_using_case_insensitive_subject()
{
var candidates = new[] { "cashregister", "carthorse", "radishes" };
var sut = new Anagram("Orchestra");
var expected = new[] { "carthorse" };
Assert.Equal(expected, sut.Anagrams());
Assert.Equal(expected, sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Detects_anagrams_using_case_insensitive_possible_matches()
{
var candidates = new[] { "cashregister", "Carthorse", "radishes" };
var sut = new Anagram("orchestra");
var expected = new[] { "Carthorse" };
Assert.Equal(expected, sut.Anagrams());
Assert.Equal(expected, sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Does_not_detect_a_anagram_if_the_original_word_is_repeated()
{
var candidates = new[] { "go Go GO" };
var sut = new Anagram("go");
Assert.Empty(sut.Anagrams());
Assert.Empty(sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Anagrams_must_use_all_letters_exactly_once()
{
var candidates = new[] { "patter" };
var sut = new Anagram("tapper");
Assert.Empty(sut.Anagrams());
Assert.Empty(sut.Anagrams(candidates));
}

[Fact(Skip = "Remove to run test")]
public void Capital_word_is_not_own_anagram()
{
var candidates = new[] { "Banana" };
var sut = new Anagram("BANANA");
Assert.Empty(sut.Anagrams());
Assert.Empty(sut.Anagrams(candidates));
}
}
7 changes: 1 addition & 6 deletions exercises/beer-song/BeerSong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

public static class BeerSong
{
public static string Verse(int number)
{
throw new NotImplementedException("You need to implement this function.");
}

public static string Verses(int begin, int end)
public static string Recite(int startBottles, int takeDown)
{
throw new NotImplementedException("You need to implement this function.");
}
Expand Down
338 changes: 330 additions & 8 deletions exercises/beer-song/BeerSongTest.cs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions exercises/beer-song/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public static string Verse(int number)
switch (number)
{
case 0:
return "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n";
return "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.";
case 1:
return "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n";
return "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.";
case 2:
return "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n";
return "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.";
default:
return string.Format("{0} bottles of beer on the wall, {0} bottles of beer.\nTake one down and pass it around, {1} bottles of beer on the wall.\n", number, number - 1);
return string.Format("{0} bottles of beer on the wall, {0} bottles of beer.\nTake one down and pass it around, {1} bottles of beer on the wall.", number, number - 1);
}
}

public static string Verses(int begin, int end)
=> string.Join("\n", Enumerable.Range(end, begin - end + 1).Reverse().Select(Verse));
public static string Recite(int startBottles, int takeDown)
=> string.Join("\n\n", Enumerable.Range(startBottles - takeDown + 1, takeDown).Reverse().Select(Verse));
}
22 changes: 11 additions & 11 deletions exercises/binary-search/BinarySearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,78 @@ 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());
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());
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());
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());
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());
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());
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());
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());
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());
Assert.Equal(-1, sut.Find(13));
}

[Fact(Skip = "Remove to run test")]
public void Nothing_is_included_in_an_empty_array()
{
var array = new[] { };
var array = new int[0];
var sut = new BinarySearch(array);
Assert.Equal(-1, sut.Find());
Assert.Equal(-1, sut.Find(1));
}
}
28 changes: 14 additions & 14 deletions exercises/book-store/BookStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,97 +8,97 @@ public class BookStoreTest
public void Only_a_single_book()
{
var basket = new[] { 1 };
Assert.Equal(800, BookStore.Total(basket));
Assert.Equal(8, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Two_of_the_same_book()
{
var basket = new[] { 2, 2 };
Assert.Equal(1600, BookStore.Total(basket));
Assert.Equal(16, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Empty_basket()
{
var basket = new[] { };
var basket = new int[0];
Assert.Equal(0, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Two_different_books()
{
var basket = new[] { 1, 2 };
Assert.Equal(1520, BookStore.Total(basket));
Assert.Equal(15.2, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Three_different_books()
{
var basket = new[] { 1, 2, 3 };
Assert.Equal(2160, BookStore.Total(basket));
Assert.Equal(21.6, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Four_different_books()
{
var basket = new[] { 1, 2, 3, 4 };
Assert.Equal(2560, BookStore.Total(basket));
Assert.Equal(25.6, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Five_different_books()
{
var basket = new[] { 1, 2, 3, 4, 5 };
Assert.Equal(3000, BookStore.Total(basket));
Assert.Equal(30, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Two_groups_of_four_is_cheaper_than_group_of_five_plus_group_of_three()
{
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5 };
Assert.Equal(5120, BookStore.Total(basket));
Assert.Equal(51.2, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Group_of_four_plus_group_of_two_is_cheaper_than_two_groups_of_three()
{
var basket = new[] { 1, 1, 2, 2, 3, 4 };
Assert.Equal(4080, BookStore.Total(basket));
Assert.Equal(40.8, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Two_each_of_first_4_books_and_1_copy_each_of_rest()
{
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5 };
Assert.Equal(5560, BookStore.Total(basket));
Assert.Equal(55.6, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Two_copies_of_each_book()
{
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
Assert.Equal(6000, BookStore.Total(basket));
Assert.Equal(60, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Three_copies_of_first_book_and_2_each_of_remaining()
{
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1 };
Assert.Equal(6800, BookStore.Total(basket));
Assert.Equal(68, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Three_each_of_first_2_books_and_2_each_of_remaining_books()
{
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2 };
Assert.Equal(7520, BookStore.Total(basket));
Assert.Equal(75.2, BookStore.Total(basket));
}

[Fact(Skip = "Remove to run test")]
public void Four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three()
{
var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5 };
Assert.Equal(10240, BookStore.Total(basket));
Assert.Equal(102.4, BookStore.Total(basket));
}
}
Loading

0 comments on commit 3fa323d

Please sign in to comment.