From 3fa323d61d9f2c1b64e8f6a3c55c7e928f7645ca Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 16 May 2018 21:38:36 +0200 Subject: [PATCH] generators: Use updated canonical data parsing --- exercises/all-your-base/AllYourBaseTest.cs | 4 +- exercises/anagram/AnagramTest.cs | 36 +- exercises/beer-song/BeerSong.cs | 7 +- exercises/beer-song/BeerSongTest.cs | 338 +++++++++++++++++- exercises/beer-song/Example.cs | 12 +- exercises/binary-search/BinarySearchTest.cs | 22 +- exercises/book-store/BookStoreTest.cs | 28 +- exercises/bowling/BowlingTest.cs | 95 +++-- exercises/bracket-push/BracketPushTest.cs | 2 +- exercises/clock/ClockTest.cs | 18 +- .../CollatzConjectureTest.cs | 2 +- .../complex-numbers/ComplexNumbersTest.cs | 29 +- exercises/connect/ConnectTest.cs | 2 +- exercises/crypto-square/CryptoSquareTest.cs | 2 +- .../DifferenceOfSquaresTest.cs | 2 +- exercises/dominoes/DominoesTest.cs | 50 +-- exercises/etl/Etl.cs | 2 +- exercises/etl/EtlTest.cs | 8 +- exercises/etl/Example.cs | 2 +- exercises/flatten-array/FlattenArrayTest.cs | 26 +- exercises/food-chain/FoodChainTest.cs | 2 +- exercises/gigasecond/GigasecondTest.cs | 2 +- exercises/grains/GrainsTest.cs | 2 +- exercises/hamming/HammingTest.cs | 2 +- exercises/hello-world/HelloWorldTest.cs | 2 +- exercises/house/Example.cs | 4 +- exercises/house/HouseTest.cs | 239 ++----------- exercises/isbn-verifier/IsbnVerifierTest.cs | 16 +- exercises/isogram/IsogramTest.cs | 2 +- .../KindergartenGardenTest.cs | 2 +- .../LargestSeriesProductTest.cs | 2 +- exercises/leap/LeapTest.cs | 2 +- exercises/luhn/LuhnTest.cs | 2 +- exercises/minesweeper/MinesweeperTest.cs | 63 ++-- exercises/nth-prime/NthPrimeTest.cs | 2 +- .../nucleotide-count/NucleotideCountTest.cs | 2 +- exercises/ocr-numbers/OcrNumbersTest.cs | 70 ++-- exercises/pangram/PangramTest.cs | 2 +- .../pascals-triangle/PascalsTriangleTest.cs | 2 +- .../perfect-numbers/PerfectNumbersTest.cs | 2 +- exercises/phone-number/PhoneNumberTest.cs | 20 +- exercises/pig-latin/PigLatinTest.cs | 2 +- exercises/poker/PokerTest.cs | 2 +- exercises/prime-factors/PrimeFactorsTest.cs | 2 +- exercises/queen-attack/QueenAttackTest.cs | 2 +- .../rail-fence-cipher/RailFenceCipherTest.cs | 2 +- exercises/raindrops/RaindropsTest.cs | 2 +- exercises/reverse-string/ReverseStringTest.cs | 2 +- .../rna-transcription/RnaTranscriptionTest.cs | 2 +- exercises/roman-numerals/RomanNumeralsTest.cs | 8 +- .../rotational-cipher/RotationalCipherTest.cs | 2 +- .../RunLengthEncodingTest.cs | 2 +- exercises/saddle-points/SaddlePointsTest.cs | 22 +- exercises/say/SayTest.cs | 2 +- exercises/scrabble-score/ScrabbleScoreTest.cs | 2 +- .../secret-handshake/SecretHandshakeTest.cs | 2 +- exercises/sieve/SieveTest.cs | 2 +- exercises/space-age/SpaceAgeTest.cs | 2 +- .../sum-of-multiples/SumOfMultiplesTest.cs | 2 +- exercises/tournament/Example.cs | 22 +- exercises/tournament/TournamentTest.cs | 196 +++++----- exercises/transpose/TransposeTest.cs | 146 +++----- exercises/triangle/TriangleTest.cs | 2 +- exercises/two-bucket/TwoBucketTest.cs | 2 +- exercises/two-fer/TwoFerTest.cs | 2 +- exercises/word-count/Example.cs | 2 +- exercises/word-count/WordCount.cs | 2 +- exercises/word-count/WordCountTest.cs | 24 +- exercises/wordy/WordyTest.cs | 2 +- exercises/yacht/Example.cs | 7 +- exercises/yacht/YachtTest.cs | 8 +- generators/Exercises/AllYourBase.cs | 1 + generators/Exercises/Alphametics.cs | 7 +- generators/Exercises/BeerSong.cs | 3 + generators/Exercises/BinarySearch.cs | 1 + generators/Exercises/BookStore.cs | 2 + generators/Exercises/Bowling.cs | 35 +- generators/Exercises/BracketPush.cs | 2 +- generators/Exercises/Clock.cs | 9 +- generators/Exercises/ComplexNumbers.cs | 29 +- generators/Exercises/Connect.cs | 12 +- generators/Exercises/Dominoes.cs | 4 +- generators/Exercises/Etl.cs | 42 +-- generators/Exercises/FlattenArray.cs | 22 +- generators/Exercises/Gigasecond.cs | 8 +- generators/Exercises/Grains.cs | 2 +- generators/Exercises/Hamming.cs | 2 +- generators/Exercises/KindergartenGarden.cs | 6 +- generators/Exercises/Meetup.cs | 12 +- generators/Exercises/Minesweeper.cs | 18 +- generators/Exercises/OcrNumbers.cs | 15 +- generators/Exercises/PascalsTriangle.cs | 8 - generators/Exercises/QueenAttack.cs | 6 +- generators/Exercises/RobotSimulator.cs | 12 +- generators/Exercises/SaddlePoints.cs | 4 +- generators/Exercises/Say.cs | 2 +- generators/Exercises/Sublist.cs | 9 +- generators/Exercises/SumOfMultiples.cs | 11 +- generators/Exercises/Tournament.cs | 30 +- generators/Exercises/Transpose.cs | 4 +- generators/Exercises/Triangle.cs | 4 +- generators/Exercises/TwelveDays.cs | 6 +- generators/Exercises/TwoBucket.cs | 10 +- generators/Exercises/TwoFer.cs | 13 +- generators/Exercises/Yacht.cs | 22 +- generators/Input/CanonicalData.cs | 2 +- generators/Input/CanonicalDataCase.cs | 63 +--- generators/Input/CanonicalDataCaseParser.cs | 64 +++- generators/Input/CanonicalDataParser.cs | 6 +- generators/Input/ConvertHelper.cs | 20 ++ generators/Output/TestMethodBodyData.cs | 25 +- generators/Output/ValueFormatter.cs | 16 +- 112 files changed, 1183 insertions(+), 992 deletions(-) diff --git a/exercises/all-your-base/AllYourBaseTest.cs b/exercises/all-your-base/AllYourBaseTest.cs index 12592e0cb8..abfaf4e897 100644 --- a/exercises/all-your-base/AllYourBaseTest.cs +++ b/exercises/all-your-base/AllYourBaseTest.cs @@ -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)); @@ -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(() => AllYourBase.Rebase(inputBase, digits, outputBase)); } diff --git a/exercises/anagram/AnagramTest.cs b/exercises/anagram/AnagramTest.cs index 521c0d27b6..5b6e4f7b7c 100644 --- a/exercises/anagram/AnagramTest.cs +++ b/exercises/anagram/AnagramTest.cs @@ -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)); } } \ No newline at end of file diff --git a/exercises/beer-song/BeerSong.cs b/exercises/beer-song/BeerSong.cs index 02b55bfc75..4d3387965c 100644 --- a/exercises/beer-song/BeerSong.cs +++ b/exercises/beer-song/BeerSong.cs @@ -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."); } diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index a1d4e39965..c19f76bc3b 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -7,56 +7,378 @@ public class BeerSongTest [Fact] public void First_generic_verse() { - var expected = new[] { "99 bottles of beer on the wall, 99 bottles of beer.", "Take one down and pass it around, 98 bottles of beer on the wall." }; + var expected = + "99 bottles of beer on the wall, 99 bottles of beer.\n" + + "Take one down and pass it around, 98 bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(99, 1)); } [Fact(Skip = "Remove to run test")] public void Last_generic_verse() { - var expected = new[] { "3 bottles of beer on the wall, 3 bottles of beer.", "Take one down and pass it around, 2 bottles of beer on the wall." }; + var expected = + "3 bottles of beer on the wall, 3 bottles of beer.\n" + + "Take one down and pass it around, 2 bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(3, 1)); } [Fact(Skip = "Remove to run test")] public void Verse_with_2_bottles() { - var expected = new[] { "2 bottles of beer on the wall, 2 bottles of beer.", "Take one down and pass it around, 1 bottle of beer on the wall." }; + var expected = + "2 bottles of beer on the wall, 2 bottles of beer.\n" + + "Take one down and pass it around, 1 bottle of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(2, 1)); } [Fact(Skip = "Remove to run test")] public void Verse_with_1_bottle() { - var expected = new[] { "1 bottle of beer on the wall, 1 bottle of beer.", "Take it down and pass it around, no more bottles of beer on the wall." }; + var expected = + "1 bottle of beer on the wall, 1 bottle of beer.\n" + + "Take it down and pass it around, no more bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(1, 1)); } [Fact(Skip = "Remove to run test")] public void Verse_with_0_bottles() { - var expected = new[] { "No more bottles of beer on the wall, no more bottles of beer.", "Go to the store and buy some more, 99 bottles of beer on the wall." }; + var expected = + "No more bottles of beer on the wall, no more bottles of beer.\n" + + "Go to the store and buy some more, 99 bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(0, 1)); } [Fact(Skip = "Remove to run test")] public void First_two_verses() { - var expected = new[] { "99 bottles of beer on the wall, 99 bottles of beer.", "Take one down and pass it around, 98 bottles of beer on the wall.", "", "98 bottles of beer on the wall, 98 bottles of beer.", "Take one down and pass it around, 97 bottles of beer on the wall." }; + var expected = + "99 bottles of beer on the wall, 99 bottles of beer.\n" + + "Take one down and pass it around, 98 bottles of beer on the wall.\n" + + "\n" + + "98 bottles of beer on the wall, 98 bottles of beer.\n" + + "Take one down and pass it around, 97 bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(99, 2)); } [Fact(Skip = "Remove to run test")] public void Last_three_verses() { - var expected = new[] { "2 bottles of beer on the wall, 2 bottles of beer.", "Take one down and pass it around, 1 bottle of beer on the wall.", "", "1 bottle of beer on the wall, 1 bottle of beer.", "Take it down and pass it around, no more bottles of beer on the wall.", "", "No more bottles of beer on the wall, no more bottles of beer.", "Go to the store and buy some more, 99 bottles of beer on the wall." }; + var expected = + "2 bottles of beer on the wall, 2 bottles of beer.\n" + + "Take one down and pass it around, 1 bottle of beer on the wall.\n" + + "\n" + + "1 bottle of beer on the wall, 1 bottle of beer.\n" + + "Take it down and pass it around, no more bottles of beer on the wall.\n" + + "\n" + + "No more bottles of beer on the wall, no more bottles of beer.\n" + + "Go to the store and buy some more, 99 bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(2, 3)); } [Fact(Skip = "Remove to run test")] public void All_verses() { - var expected = new[] { "99 bottles of beer on the wall, 99 bottles of beer.", "Take one down and pass it around, 98 bottles of beer on the wall.", "", "98 bottles of beer on the wall, 98 bottles of beer.", "Take one down and pass it around, 97 bottles of beer on the wall.", "", "97 bottles of beer on the wall, 97 bottles of beer.", "Take one down and pass it around, 96 bottles of beer on the wall.", "", "96 bottles of beer on the wall, 96 bottles of beer.", "Take one down and pass it around, 95 bottles of beer on the wall.", "", "95 bottles of beer on the wall, 95 bottles of beer.", "Take one down and pass it around, 94 bottles of beer on the wall.", "", "94 bottles of beer on the wall, 94 bottles of beer.", "Take one down and pass it around, 93 bottles of beer on the wall.", "", "93 bottles of beer on the wall, 93 bottles of beer.", "Take one down and pass it around, 92 bottles of beer on the wall.", "", "92 bottles of beer on the wall, 92 bottles of beer.", "Take one down and pass it around, 91 bottles of beer on the wall.", "", "91 bottles of beer on the wall, 91 bottles of beer.", "Take one down and pass it around, 90 bottles of beer on the wall.", "", "90 bottles of beer on the wall, 90 bottles of beer.", "Take one down and pass it around, 89 bottles of beer on the wall.", "", "89 bottles of beer on the wall, 89 bottles of beer.", "Take one down and pass it around, 88 bottles of beer on the wall.", "", "88 bottles of beer on the wall, 88 bottles of beer.", "Take one down and pass it around, 87 bottles of beer on the wall.", "", "87 bottles of beer on the wall, 87 bottles of beer.", "Take one down and pass it around, 86 bottles of beer on the wall.", "", "86 bottles of beer on the wall, 86 bottles of beer.", "Take one down and pass it around, 85 bottles of beer on the wall.", "", "85 bottles of beer on the wall, 85 bottles of beer.", "Take one down and pass it around, 84 bottles of beer on the wall.", "", "84 bottles of beer on the wall, 84 bottles of beer.", "Take one down and pass it around, 83 bottles of beer on the wall.", "", "83 bottles of beer on the wall, 83 bottles of beer.", "Take one down and pass it around, 82 bottles of beer on the wall.", "", "82 bottles of beer on the wall, 82 bottles of beer.", "Take one down and pass it around, 81 bottles of beer on the wall.", "", "81 bottles of beer on the wall, 81 bottles of beer.", "Take one down and pass it around, 80 bottles of beer on the wall.", "", "80 bottles of beer on the wall, 80 bottles of beer.", "Take one down and pass it around, 79 bottles of beer on the wall.", "", "79 bottles of beer on the wall, 79 bottles of beer.", "Take one down and pass it around, 78 bottles of beer on the wall.", "", "78 bottles of beer on the wall, 78 bottles of beer.", "Take one down and pass it around, 77 bottles of beer on the wall.", "", "77 bottles of beer on the wall, 77 bottles of beer.", "Take one down and pass it around, 76 bottles of beer on the wall.", "", "76 bottles of beer on the wall, 76 bottles of beer.", "Take one down and pass it around, 75 bottles of beer on the wall.", "", "75 bottles of beer on the wall, 75 bottles of beer.", "Take one down and pass it around, 74 bottles of beer on the wall.", "", "74 bottles of beer on the wall, 74 bottles of beer.", "Take one down and pass it around, 73 bottles of beer on the wall.", "", "73 bottles of beer on the wall, 73 bottles of beer.", "Take one down and pass it around, 72 bottles of beer on the wall.", "", "72 bottles of beer on the wall, 72 bottles of beer.", "Take one down and pass it around, 71 bottles of beer on the wall.", "", "71 bottles of beer on the wall, 71 bottles of beer.", "Take one down and pass it around, 70 bottles of beer on the wall.", "", "70 bottles of beer on the wall, 70 bottles of beer.", "Take one down and pass it around, 69 bottles of beer on the wall.", "", "69 bottles of beer on the wall, 69 bottles of beer.", "Take one down and pass it around, 68 bottles of beer on the wall.", "", "68 bottles of beer on the wall, 68 bottles of beer.", "Take one down and pass it around, 67 bottles of beer on the wall.", "", "67 bottles of beer on the wall, 67 bottles of beer.", "Take one down and pass it around, 66 bottles of beer on the wall.", "", "66 bottles of beer on the wall, 66 bottles of beer.", "Take one down and pass it around, 65 bottles of beer on the wall.", "", "65 bottles of beer on the wall, 65 bottles of beer.", "Take one down and pass it around, 64 bottles of beer on the wall.", "", "64 bottles of beer on the wall, 64 bottles of beer.", "Take one down and pass it around, 63 bottles of beer on the wall.", "", "63 bottles of beer on the wall, 63 bottles of beer.", "Take one down and pass it around, 62 bottles of beer on the wall.", "", "62 bottles of beer on the wall, 62 bottles of beer.", "Take one down and pass it around, 61 bottles of beer on the wall.", "", "61 bottles of beer on the wall, 61 bottles of beer.", "Take one down and pass it around, 60 bottles of beer on the wall.", "", "60 bottles of beer on the wall, 60 bottles of beer.", "Take one down and pass it around, 59 bottles of beer on the wall.", "", "59 bottles of beer on the wall, 59 bottles of beer.", "Take one down and pass it around, 58 bottles of beer on the wall.", "", "58 bottles of beer on the wall, 58 bottles of beer.", "Take one down and pass it around, 57 bottles of beer on the wall.", "", "57 bottles of beer on the wall, 57 bottles of beer.", "Take one down and pass it around, 56 bottles of beer on the wall.", "", "56 bottles of beer on the wall, 56 bottles of beer.", "Take one down and pass it around, 55 bottles of beer on the wall.", "", "55 bottles of beer on the wall, 55 bottles of beer.", "Take one down and pass it around, 54 bottles of beer on the wall.", "", "54 bottles of beer on the wall, 54 bottles of beer.", "Take one down and pass it around, 53 bottles of beer on the wall.", "", "53 bottles of beer on the wall, 53 bottles of beer.", "Take one down and pass it around, 52 bottles of beer on the wall.", "", "52 bottles of beer on the wall, 52 bottles of beer.", "Take one down and pass it around, 51 bottles of beer on the wall.", "", "51 bottles of beer on the wall, 51 bottles of beer.", "Take one down and pass it around, 50 bottles of beer on the wall.", "", "50 bottles of beer on the wall, 50 bottles of beer.", "Take one down and pass it around, 49 bottles of beer on the wall.", "", "49 bottles of beer on the wall, 49 bottles of beer.", "Take one down and pass it around, 48 bottles of beer on the wall.", "", "48 bottles of beer on the wall, 48 bottles of beer.", "Take one down and pass it around, 47 bottles of beer on the wall.", "", "47 bottles of beer on the wall, 47 bottles of beer.", "Take one down and pass it around, 46 bottles of beer on the wall.", "", "46 bottles of beer on the wall, 46 bottles of beer.", "Take one down and pass it around, 45 bottles of beer on the wall.", "", "45 bottles of beer on the wall, 45 bottles of beer.", "Take one down and pass it around, 44 bottles of beer on the wall.", "", "44 bottles of beer on the wall, 44 bottles of beer.", "Take one down and pass it around, 43 bottles of beer on the wall.", "", "43 bottles of beer on the wall, 43 bottles of beer.", "Take one down and pass it around, 42 bottles of beer on the wall.", "", "42 bottles of beer on the wall, 42 bottles of beer.", "Take one down and pass it around, 41 bottles of beer on the wall.", "", "41 bottles of beer on the wall, 41 bottles of beer.", "Take one down and pass it around, 40 bottles of beer on the wall.", "", "40 bottles of beer on the wall, 40 bottles of beer.", "Take one down and pass it around, 39 bottles of beer on the wall.", "", "39 bottles of beer on the wall, 39 bottles of beer.", "Take one down and pass it around, 38 bottles of beer on the wall.", "", "38 bottles of beer on the wall, 38 bottles of beer.", "Take one down and pass it around, 37 bottles of beer on the wall.", "", "37 bottles of beer on the wall, 37 bottles of beer.", "Take one down and pass it around, 36 bottles of beer on the wall.", "", "36 bottles of beer on the wall, 36 bottles of beer.", "Take one down and pass it around, 35 bottles of beer on the wall.", "", "35 bottles of beer on the wall, 35 bottles of beer.", "Take one down and pass it around, 34 bottles of beer on the wall.", "", "34 bottles of beer on the wall, 34 bottles of beer.", "Take one down and pass it around, 33 bottles of beer on the wall.", "", "33 bottles of beer on the wall, 33 bottles of beer.", "Take one down and pass it around, 32 bottles of beer on the wall.", "", "32 bottles of beer on the wall, 32 bottles of beer.", "Take one down and pass it around, 31 bottles of beer on the wall.", "", "31 bottles of beer on the wall, 31 bottles of beer.", "Take one down and pass it around, 30 bottles of beer on the wall.", "", "30 bottles of beer on the wall, 30 bottles of beer.", "Take one down and pass it around, 29 bottles of beer on the wall.", "", "29 bottles of beer on the wall, 29 bottles of beer.", "Take one down and pass it around, 28 bottles of beer on the wall.", "", "28 bottles of beer on the wall, 28 bottles of beer.", "Take one down and pass it around, 27 bottles of beer on the wall.", "", "27 bottles of beer on the wall, 27 bottles of beer.", "Take one down and pass it around, 26 bottles of beer on the wall.", "", "26 bottles of beer on the wall, 26 bottles of beer.", "Take one down and pass it around, 25 bottles of beer on the wall.", "", "25 bottles of beer on the wall, 25 bottles of beer.", "Take one down and pass it around, 24 bottles of beer on the wall.", "", "24 bottles of beer on the wall, 24 bottles of beer.", "Take one down and pass it around, 23 bottles of beer on the wall.", "", "23 bottles of beer on the wall, 23 bottles of beer.", "Take one down and pass it around, 22 bottles of beer on the wall.", "", "22 bottles of beer on the wall, 22 bottles of beer.", "Take one down and pass it around, 21 bottles of beer on the wall.", "", "21 bottles of beer on the wall, 21 bottles of beer.", "Take one down and pass it around, 20 bottles of beer on the wall.", "", "20 bottles of beer on the wall, 20 bottles of beer.", "Take one down and pass it around, 19 bottles of beer on the wall.", "", "19 bottles of beer on the wall, 19 bottles of beer.", "Take one down and pass it around, 18 bottles of beer on the wall.", "", "18 bottles of beer on the wall, 18 bottles of beer.", "Take one down and pass it around, 17 bottles of beer on the wall.", "", "17 bottles of beer on the wall, 17 bottles of beer.", "Take one down and pass it around, 16 bottles of beer on the wall.", "", "16 bottles of beer on the wall, 16 bottles of beer.", "Take one down and pass it around, 15 bottles of beer on the wall.", "", "15 bottles of beer on the wall, 15 bottles of beer.", "Take one down and pass it around, 14 bottles of beer on the wall.", "", "14 bottles of beer on the wall, 14 bottles of beer.", "Take one down and pass it around, 13 bottles of beer on the wall.", "", "13 bottles of beer on the wall, 13 bottles of beer.", "Take one down and pass it around, 12 bottles of beer on the wall.", "", "12 bottles of beer on the wall, 12 bottles of beer.", "Take one down and pass it around, 11 bottles of beer on the wall.", "", "11 bottles of beer on the wall, 11 bottles of beer.", "Take one down and pass it around, 10 bottles of beer on the wall.", "", "10 bottles of beer on the wall, 10 bottles of beer.", "Take one down and pass it around, 9 bottles of beer on the wall.", "", "9 bottles of beer on the wall, 9 bottles of beer.", "Take one down and pass it around, 8 bottles of beer on the wall.", "", "8 bottles of beer on the wall, 8 bottles of beer.", "Take one down and pass it around, 7 bottles of beer on the wall.", "", "7 bottles of beer on the wall, 7 bottles of beer.", "Take one down and pass it around, 6 bottles of beer on the wall.", "", "6 bottles of beer on the wall, 6 bottles of beer.", "Take one down and pass it around, 5 bottles of beer on the wall.", "", "5 bottles of beer on the wall, 5 bottles of beer.", "Take one down and pass it around, 4 bottles of beer on the wall.", "", "4 bottles of beer on the wall, 4 bottles of beer.", "Take one down and pass it around, 3 bottles of beer on the wall.", "", "3 bottles of beer on the wall, 3 bottles of beer.", "Take one down and pass it around, 2 bottles of beer on the wall.", "", "2 bottles of beer on the wall, 2 bottles of beer.", "Take one down and pass it around, 1 bottle of beer on the wall.", "", "1 bottle of beer on the wall, 1 bottle of beer.", "Take it down and pass it around, no more bottles of beer on the wall.", "", "No more bottles of beer on the wall, no more bottles of beer.", "Go to the store and buy some more, 99 bottles of beer on the wall." }; + var expected = + "99 bottles of beer on the wall, 99 bottles of beer.\n" + + "Take one down and pass it around, 98 bottles of beer on the wall.\n" + + "\n" + + "98 bottles of beer on the wall, 98 bottles of beer.\n" + + "Take one down and pass it around, 97 bottles of beer on the wall.\n" + + "\n" + + "97 bottles of beer on the wall, 97 bottles of beer.\n" + + "Take one down and pass it around, 96 bottles of beer on the wall.\n" + + "\n" + + "96 bottles of beer on the wall, 96 bottles of beer.\n" + + "Take one down and pass it around, 95 bottles of beer on the wall.\n" + + "\n" + + "95 bottles of beer on the wall, 95 bottles of beer.\n" + + "Take one down and pass it around, 94 bottles of beer on the wall.\n" + + "\n" + + "94 bottles of beer on the wall, 94 bottles of beer.\n" + + "Take one down and pass it around, 93 bottles of beer on the wall.\n" + + "\n" + + "93 bottles of beer on the wall, 93 bottles of beer.\n" + + "Take one down and pass it around, 92 bottles of beer on the wall.\n" + + "\n" + + "92 bottles of beer on the wall, 92 bottles of beer.\n" + + "Take one down and pass it around, 91 bottles of beer on the wall.\n" + + "\n" + + "91 bottles of beer on the wall, 91 bottles of beer.\n" + + "Take one down and pass it around, 90 bottles of beer on the wall.\n" + + "\n" + + "90 bottles of beer on the wall, 90 bottles of beer.\n" + + "Take one down and pass it around, 89 bottles of beer on the wall.\n" + + "\n" + + "89 bottles of beer on the wall, 89 bottles of beer.\n" + + "Take one down and pass it around, 88 bottles of beer on the wall.\n" + + "\n" + + "88 bottles of beer on the wall, 88 bottles of beer.\n" + + "Take one down and pass it around, 87 bottles of beer on the wall.\n" + + "\n" + + "87 bottles of beer on the wall, 87 bottles of beer.\n" + + "Take one down and pass it around, 86 bottles of beer on the wall.\n" + + "\n" + + "86 bottles of beer on the wall, 86 bottles of beer.\n" + + "Take one down and pass it around, 85 bottles of beer on the wall.\n" + + "\n" + + "85 bottles of beer on the wall, 85 bottles of beer.\n" + + "Take one down and pass it around, 84 bottles of beer on the wall.\n" + + "\n" + + "84 bottles of beer on the wall, 84 bottles of beer.\n" + + "Take one down and pass it around, 83 bottles of beer on the wall.\n" + + "\n" + + "83 bottles of beer on the wall, 83 bottles of beer.\n" + + "Take one down and pass it around, 82 bottles of beer on the wall.\n" + + "\n" + + "82 bottles of beer on the wall, 82 bottles of beer.\n" + + "Take one down and pass it around, 81 bottles of beer on the wall.\n" + + "\n" + + "81 bottles of beer on the wall, 81 bottles of beer.\n" + + "Take one down and pass it around, 80 bottles of beer on the wall.\n" + + "\n" + + "80 bottles of beer on the wall, 80 bottles of beer.\n" + + "Take one down and pass it around, 79 bottles of beer on the wall.\n" + + "\n" + + "79 bottles of beer on the wall, 79 bottles of beer.\n" + + "Take one down and pass it around, 78 bottles of beer on the wall.\n" + + "\n" + + "78 bottles of beer on the wall, 78 bottles of beer.\n" + + "Take one down and pass it around, 77 bottles of beer on the wall.\n" + + "\n" + + "77 bottles of beer on the wall, 77 bottles of beer.\n" + + "Take one down and pass it around, 76 bottles of beer on the wall.\n" + + "\n" + + "76 bottles of beer on the wall, 76 bottles of beer.\n" + + "Take one down and pass it around, 75 bottles of beer on the wall.\n" + + "\n" + + "75 bottles of beer on the wall, 75 bottles of beer.\n" + + "Take one down and pass it around, 74 bottles of beer on the wall.\n" + + "\n" + + "74 bottles of beer on the wall, 74 bottles of beer.\n" + + "Take one down and pass it around, 73 bottles of beer on the wall.\n" + + "\n" + + "73 bottles of beer on the wall, 73 bottles of beer.\n" + + "Take one down and pass it around, 72 bottles of beer on the wall.\n" + + "\n" + + "72 bottles of beer on the wall, 72 bottles of beer.\n" + + "Take one down and pass it around, 71 bottles of beer on the wall.\n" + + "\n" + + "71 bottles of beer on the wall, 71 bottles of beer.\n" + + "Take one down and pass it around, 70 bottles of beer on the wall.\n" + + "\n" + + "70 bottles of beer on the wall, 70 bottles of beer.\n" + + "Take one down and pass it around, 69 bottles of beer on the wall.\n" + + "\n" + + "69 bottles of beer on the wall, 69 bottles of beer.\n" + + "Take one down and pass it around, 68 bottles of beer on the wall.\n" + + "\n" + + "68 bottles of beer on the wall, 68 bottles of beer.\n" + + "Take one down and pass it around, 67 bottles of beer on the wall.\n" + + "\n" + + "67 bottles of beer on the wall, 67 bottles of beer.\n" + + "Take one down and pass it around, 66 bottles of beer on the wall.\n" + + "\n" + + "66 bottles of beer on the wall, 66 bottles of beer.\n" + + "Take one down and pass it around, 65 bottles of beer on the wall.\n" + + "\n" + + "65 bottles of beer on the wall, 65 bottles of beer.\n" + + "Take one down and pass it around, 64 bottles of beer on the wall.\n" + + "\n" + + "64 bottles of beer on the wall, 64 bottles of beer.\n" + + "Take one down and pass it around, 63 bottles of beer on the wall.\n" + + "\n" + + "63 bottles of beer on the wall, 63 bottles of beer.\n" + + "Take one down and pass it around, 62 bottles of beer on the wall.\n" + + "\n" + + "62 bottles of beer on the wall, 62 bottles of beer.\n" + + "Take one down and pass it around, 61 bottles of beer on the wall.\n" + + "\n" + + "61 bottles of beer on the wall, 61 bottles of beer.\n" + + "Take one down and pass it around, 60 bottles of beer on the wall.\n" + + "\n" + + "60 bottles of beer on the wall, 60 bottles of beer.\n" + + "Take one down and pass it around, 59 bottles of beer on the wall.\n" + + "\n" + + "59 bottles of beer on the wall, 59 bottles of beer.\n" + + "Take one down and pass it around, 58 bottles of beer on the wall.\n" + + "\n" + + "58 bottles of beer on the wall, 58 bottles of beer.\n" + + "Take one down and pass it around, 57 bottles of beer on the wall.\n" + + "\n" + + "57 bottles of beer on the wall, 57 bottles of beer.\n" + + "Take one down and pass it around, 56 bottles of beer on the wall.\n" + + "\n" + + "56 bottles of beer on the wall, 56 bottles of beer.\n" + + "Take one down and pass it around, 55 bottles of beer on the wall.\n" + + "\n" + + "55 bottles of beer on the wall, 55 bottles of beer.\n" + + "Take one down and pass it around, 54 bottles of beer on the wall.\n" + + "\n" + + "54 bottles of beer on the wall, 54 bottles of beer.\n" + + "Take one down and pass it around, 53 bottles of beer on the wall.\n" + + "\n" + + "53 bottles of beer on the wall, 53 bottles of beer.\n" + + "Take one down and pass it around, 52 bottles of beer on the wall.\n" + + "\n" + + "52 bottles of beer on the wall, 52 bottles of beer.\n" + + "Take one down and pass it around, 51 bottles of beer on the wall.\n" + + "\n" + + "51 bottles of beer on the wall, 51 bottles of beer.\n" + + "Take one down and pass it around, 50 bottles of beer on the wall.\n" + + "\n" + + "50 bottles of beer on the wall, 50 bottles of beer.\n" + + "Take one down and pass it around, 49 bottles of beer on the wall.\n" + + "\n" + + "49 bottles of beer on the wall, 49 bottles of beer.\n" + + "Take one down and pass it around, 48 bottles of beer on the wall.\n" + + "\n" + + "48 bottles of beer on the wall, 48 bottles of beer.\n" + + "Take one down and pass it around, 47 bottles of beer on the wall.\n" + + "\n" + + "47 bottles of beer on the wall, 47 bottles of beer.\n" + + "Take one down and pass it around, 46 bottles of beer on the wall.\n" + + "\n" + + "46 bottles of beer on the wall, 46 bottles of beer.\n" + + "Take one down and pass it around, 45 bottles of beer on the wall.\n" + + "\n" + + "45 bottles of beer on the wall, 45 bottles of beer.\n" + + "Take one down and pass it around, 44 bottles of beer on the wall.\n" + + "\n" + + "44 bottles of beer on the wall, 44 bottles of beer.\n" + + "Take one down and pass it around, 43 bottles of beer on the wall.\n" + + "\n" + + "43 bottles of beer on the wall, 43 bottles of beer.\n" + + "Take one down and pass it around, 42 bottles of beer on the wall.\n" + + "\n" + + "42 bottles of beer on the wall, 42 bottles of beer.\n" + + "Take one down and pass it around, 41 bottles of beer on the wall.\n" + + "\n" + + "41 bottles of beer on the wall, 41 bottles of beer.\n" + + "Take one down and pass it around, 40 bottles of beer on the wall.\n" + + "\n" + + "40 bottles of beer on the wall, 40 bottles of beer.\n" + + "Take one down and pass it around, 39 bottles of beer on the wall.\n" + + "\n" + + "39 bottles of beer on the wall, 39 bottles of beer.\n" + + "Take one down and pass it around, 38 bottles of beer on the wall.\n" + + "\n" + + "38 bottles of beer on the wall, 38 bottles of beer.\n" + + "Take one down and pass it around, 37 bottles of beer on the wall.\n" + + "\n" + + "37 bottles of beer on the wall, 37 bottles of beer.\n" + + "Take one down and pass it around, 36 bottles of beer on the wall.\n" + + "\n" + + "36 bottles of beer on the wall, 36 bottles of beer.\n" + + "Take one down and pass it around, 35 bottles of beer on the wall.\n" + + "\n" + + "35 bottles of beer on the wall, 35 bottles of beer.\n" + + "Take one down and pass it around, 34 bottles of beer on the wall.\n" + + "\n" + + "34 bottles of beer on the wall, 34 bottles of beer.\n" + + "Take one down and pass it around, 33 bottles of beer on the wall.\n" + + "\n" + + "33 bottles of beer on the wall, 33 bottles of beer.\n" + + "Take one down and pass it around, 32 bottles of beer on the wall.\n" + + "\n" + + "32 bottles of beer on the wall, 32 bottles of beer.\n" + + "Take one down and pass it around, 31 bottles of beer on the wall.\n" + + "\n" + + "31 bottles of beer on the wall, 31 bottles of beer.\n" + + "Take one down and pass it around, 30 bottles of beer on the wall.\n" + + "\n" + + "30 bottles of beer on the wall, 30 bottles of beer.\n" + + "Take one down and pass it around, 29 bottles of beer on the wall.\n" + + "\n" + + "29 bottles of beer on the wall, 29 bottles of beer.\n" + + "Take one down and pass it around, 28 bottles of beer on the wall.\n" + + "\n" + + "28 bottles of beer on the wall, 28 bottles of beer.\n" + + "Take one down and pass it around, 27 bottles of beer on the wall.\n" + + "\n" + + "27 bottles of beer on the wall, 27 bottles of beer.\n" + + "Take one down and pass it around, 26 bottles of beer on the wall.\n" + + "\n" + + "26 bottles of beer on the wall, 26 bottles of beer.\n" + + "Take one down and pass it around, 25 bottles of beer on the wall.\n" + + "\n" + + "25 bottles of beer on the wall, 25 bottles of beer.\n" + + "Take one down and pass it around, 24 bottles of beer on the wall.\n" + + "\n" + + "24 bottles of beer on the wall, 24 bottles of beer.\n" + + "Take one down and pass it around, 23 bottles of beer on the wall.\n" + + "\n" + + "23 bottles of beer on the wall, 23 bottles of beer.\n" + + "Take one down and pass it around, 22 bottles of beer on the wall.\n" + + "\n" + + "22 bottles of beer on the wall, 22 bottles of beer.\n" + + "Take one down and pass it around, 21 bottles of beer on the wall.\n" + + "\n" + + "21 bottles of beer on the wall, 21 bottles of beer.\n" + + "Take one down and pass it around, 20 bottles of beer on the wall.\n" + + "\n" + + "20 bottles of beer on the wall, 20 bottles of beer.\n" + + "Take one down and pass it around, 19 bottles of beer on the wall.\n" + + "\n" + + "19 bottles of beer on the wall, 19 bottles of beer.\n" + + "Take one down and pass it around, 18 bottles of beer on the wall.\n" + + "\n" + + "18 bottles of beer on the wall, 18 bottles of beer.\n" + + "Take one down and pass it around, 17 bottles of beer on the wall.\n" + + "\n" + + "17 bottles of beer on the wall, 17 bottles of beer.\n" + + "Take one down and pass it around, 16 bottles of beer on the wall.\n" + + "\n" + + "16 bottles of beer on the wall, 16 bottles of beer.\n" + + "Take one down and pass it around, 15 bottles of beer on the wall.\n" + + "\n" + + "15 bottles of beer on the wall, 15 bottles of beer.\n" + + "Take one down and pass it around, 14 bottles of beer on the wall.\n" + + "\n" + + "14 bottles of beer on the wall, 14 bottles of beer.\n" + + "Take one down and pass it around, 13 bottles of beer on the wall.\n" + + "\n" + + "13 bottles of beer on the wall, 13 bottles of beer.\n" + + "Take one down and pass it around, 12 bottles of beer on the wall.\n" + + "\n" + + "12 bottles of beer on the wall, 12 bottles of beer.\n" + + "Take one down and pass it around, 11 bottles of beer on the wall.\n" + + "\n" + + "11 bottles of beer on the wall, 11 bottles of beer.\n" + + "Take one down and pass it around, 10 bottles of beer on the wall.\n" + + "\n" + + "10 bottles of beer on the wall, 10 bottles of beer.\n" + + "Take one down and pass it around, 9 bottles of beer on the wall.\n" + + "\n" + + "9 bottles of beer on the wall, 9 bottles of beer.\n" + + "Take one down and pass it around, 8 bottles of beer on the wall.\n" + + "\n" + + "8 bottles of beer on the wall, 8 bottles of beer.\n" + + "Take one down and pass it around, 7 bottles of beer on the wall.\n" + + "\n" + + "7 bottles of beer on the wall, 7 bottles of beer.\n" + + "Take one down and pass it around, 6 bottles of beer on the wall.\n" + + "\n" + + "6 bottles of beer on the wall, 6 bottles of beer.\n" + + "Take one down and pass it around, 5 bottles of beer on the wall.\n" + + "\n" + + "5 bottles of beer on the wall, 5 bottles of beer.\n" + + "Take one down and pass it around, 4 bottles of beer on the wall.\n" + + "\n" + + "4 bottles of beer on the wall, 4 bottles of beer.\n" + + "Take one down and pass it around, 3 bottles of beer on the wall.\n" + + "\n" + + "3 bottles of beer on the wall, 3 bottles of beer.\n" + + "Take one down and pass it around, 2 bottles of beer on the wall.\n" + + "\n" + + "2 bottles of beer on the wall, 2 bottles of beer.\n" + + "Take one down and pass it around, 1 bottle of beer on the wall.\n" + + "\n" + + "1 bottle of beer on the wall, 1 bottle of beer.\n" + + "Take it down and pass it around, no more bottles of beer on the wall.\n" + + "\n" + + "No more bottles of beer on the wall, no more bottles of beer.\n" + + "Go to the store and buy some more, 99 bottles of beer on the wall."; Assert.Equal(expected, BeerSong.Recite(99, 100)); } } \ No newline at end of file diff --git a/exercises/beer-song/Example.cs b/exercises/beer-song/Example.cs index 80bf7a78e1..444e7e70ab 100644 --- a/exercises/beer-song/Example.cs +++ b/exercises/beer-song/Example.cs @@ -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)); } \ No newline at end of file diff --git a/exercises/binary-search/BinarySearchTest.cs b/exercises/binary-search/BinarySearchTest.cs index 5907b3742c..0a8c69597e 100644 --- a/exercises/binary-search/BinarySearchTest.cs +++ b/exercises/binary-search/BinarySearchTest.cs @@ -9,7 +9,7 @@ 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")] @@ -17,7 +17,7 @@ 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")] @@ -25,7 +25,7 @@ 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")] @@ -33,7 +33,7 @@ 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")] @@ -41,7 +41,7 @@ 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")] @@ -49,7 +49,7 @@ 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")] @@ -57,7 +57,7 @@ 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")] @@ -65,7 +65,7 @@ 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")] @@ -73,14 +73,14 @@ 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)); } } \ No newline at end of file diff --git a/exercises/book-store/BookStoreTest.cs b/exercises/book-store/BookStoreTest.cs index 8f8770d60d..c6332e5edd 100644 --- a/exercises/book-store/BookStoreTest.cs +++ b/exercises/book-store/BookStoreTest.cs @@ -8,20 +8,20 @@ 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)); } @@ -29,76 +29,76 @@ public void Empty_basket() 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)); } } \ No newline at end of file diff --git a/exercises/bowling/BowlingTest.cs b/exercises/bowling/BowlingTest.cs index 875548ece3..e936ffd8e4 100644 --- a/exercises/bowling/BowlingTest.cs +++ b/exercises/bowling/BowlingTest.cs @@ -10,182 +10,220 @@ public class BowlingTest public void Should_be_able_to_score_a_game_with_all_zeros() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(0, actual); } [Fact(Skip = "Remove to run test")] public void Should_be_able_to_score_a_game_with_no_strikes_or_spares() { var sut = new BowlingGame(); + var previousRolls = new [] { 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(90, actual); } [Fact(Skip = "Remove to run test")] public void A_spare_followed_by_zeros_is_worth_ten_points() { var sut = new BowlingGame(); + var previousRolls = new [] { 6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(10, actual); } [Fact(Skip = "Remove to run test")] public void Points_scored_in_the_roll_after_a_spare_are_counted_twice() { var sut = new BowlingGame(); + var previousRolls = new [] { 6, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(16, actual); } [Fact(Skip = "Remove to run test")] public void Consecutive_spares_each_get_a_one_roll_bonus() { var sut = new BowlingGame(); + var previousRolls = new [] { 5, 5, 3, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(31, actual); } [Fact(Skip = "Remove to run test")] public void A_spare_in_the_last_frame_gets_a_one_roll_bonus_that_is_counted_once() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 7 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(17, actual); } [Fact(Skip = "Remove to run test")] public void A_strike_earns_ten_points_in_a_frame_with_a_single_roll() { var sut = new BowlingGame(); + var previousRolls = new [] { 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(10, actual); } [Fact(Skip = "Remove to run test")] public void Points_scored_in_the_two_rolls_after_a_strike_are_counted_twice_as_a_bonus() { var sut = new BowlingGame(); + var previousRolls = new [] { 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(26, actual); } [Fact(Skip = "Remove to run test")] public void Consecutive_strikes_each_get_the_two_roll_bonus() { var sut = new BowlingGame(); + var previousRolls = new [] { 10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(81, actual); } [Fact(Skip = "Remove to run test")] public void A_strike_in_the_last_frame_gets_a_two_roll_bonus_that_is_counted_once() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 1 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(18, actual); } [Fact(Skip = "Remove to run test")] public void Rolling_a_spare_with_the_two_roll_bonus_does_not_get_a_bonus_roll() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 7, 3 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(20, actual); } [Fact(Skip = "Remove to run test")] public void Strikes_with_the_two_roll_bonus_do_not_get_bonus_rolls() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(30, actual); } [Fact(Skip = "Remove to run test")] public void A_strike_with_the_one_roll_bonus_after_a_spare_in_the_last_frame_does_not_get_a_bonus() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 10 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(20, actual); } [Fact(Skip = "Remove to run test")] public void All_strikes_is_a_perfect_game() { var sut = new BowlingGame(); + var previousRolls = new [] { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(300, actual); } [Fact(Skip = "Remove to run test")] public void Rolls_cannot_score_negative_points() { var sut = new BowlingGame(); + var previousRolls = new int[0]; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(-1)); } [Fact(Skip = "Remove to run test")] public void A_roll_cannot_score_more_than_10_points() { var sut = new BowlingGame(); + var previousRolls = new int[0]; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(11)); } [Fact(Skip = "Remove to run test")] public void Two_rolls_in_a_frame_cannot_score_more_than_10_points() { var sut = new BowlingGame(); + var previousRolls = new [] { 5 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(6)); } [Fact(Skip = "Remove to run test")] public void Bonus_roll_after_a_strike_in_the_last_frame_cannot_score_more_than_10_points() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(11)); } [Fact(Skip = "Remove to run test")] public void Two_bonus_rolls_after_a_strike_in_the_last_frame_cannot_score_more_than_10_points() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(6)); } [Fact(Skip = "Remove to run test")] public void Two_bonus_rolls_after_a_strike_in_the_last_frame_can_score_more_than_10_points_if_one_is_a_strike() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 6 }; DoRoll(previousRolls, sut); - Assert.Throws(() => sut.Score()); + var actual = sut.Score(); + Assert.Equal(26, actual); } [Fact(Skip = "Remove to run test")] public void The_second_bonus_rolls_after_a_strike_in_the_last_frame_cannot_be_a_strike_if_the_first_one_is_not_a_strike() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(10)); } [Fact(Skip = "Remove to run test")] public void Second_bonus_roll_after_a_strike_in_the_last_frame_cannot_score_more_than_10_points() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(11)); } [Fact(Skip = "Remove to run test")] public void An_unstarted_game_cannot_be_scored() { var sut = new BowlingGame(); + var previousRolls = new int[0]; DoRoll(previousRolls, sut); Assert.Throws(() => sut.Score()); } @@ -194,6 +232,7 @@ public void An_unstarted_game_cannot_be_scored() public void An_incomplete_game_cannot_be_scored() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0 }; DoRoll(previousRolls, sut); Assert.Throws(() => sut.Score()); } @@ -202,14 +241,16 @@ public void An_incomplete_game_cannot_be_scored() public void Cannot_roll_if_game_already_has_ten_frames() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(0)); } [Fact(Skip = "Remove to run test")] public void Bonus_rolls_for_a_strike_in_the_last_frame_must_be_rolled_before_score_can_be_calculated() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 }; DoRoll(previousRolls, sut); Assert.Throws(() => sut.Score()); } @@ -218,6 +259,7 @@ public void Bonus_rolls_for_a_strike_in_the_last_frame_must_be_rolled_before_sco public void Both_bonus_rolls_for_a_strike_in_the_last_frame_must_be_rolled_before_score_can_be_calculated() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10 }; DoRoll(previousRolls, sut); Assert.Throws(() => sut.Score()); } @@ -226,6 +268,7 @@ public void Both_bonus_rolls_for_a_strike_in_the_last_frame_must_be_rolled_befor public void Bonus_roll_for_a_spare_in_the_last_frame_must_be_rolled_before_score_can_be_calculated() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3 }; DoRoll(previousRolls, sut); Assert.Throws(() => sut.Score()); } @@ -234,16 +277,18 @@ public void Bonus_roll_for_a_spare_in_the_last_frame_must_be_rolled_before_score public void Cannot_roll_after_bonus_roll_for_spare() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 2 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(2)); } [Fact(Skip = "Remove to run test")] public void Cannot_roll_after_bonus_rolls_for_strike() { var sut = new BowlingGame(); + var previousRolls = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 3, 2 }; DoRoll(previousRolls, sut); - Assert.Throws(() => Bowling.Roll()); + Assert.Throws(() => sut.Roll(2)); } public void DoRoll(ICollection rolls, BowlingGame sut) diff --git a/exercises/bracket-push/BracketPushTest.cs b/exercises/bracket-push/BracketPushTest.cs index 4ce1422ee3..f87a41e2e4 100644 --- a/exercises/bracket-push/BracketPushTest.cs +++ b/exercises/bracket-push/BracketPushTest.cs @@ -105,7 +105,7 @@ public void Math_expression() [Fact(Skip = "Remove to run test")] public void Complex_latex_expression() { - var value = "\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &... x^2 \end{array}\right)"; + var value = "\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)"; Assert.True(BracketPush.IsPaired(value)); } } \ No newline at end of file diff --git a/exercises/clock/ClockTest.cs b/exercises/clock/ClockTest.cs index 8185a7e638..2699876f4c 100644 --- a/exercises/clock/ClockTest.cs +++ b/exercises/clock/ClockTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.1 of the canonical data. +// This file was auto-generated based on version 2.2.1 of the canonical data. using Xunit; @@ -197,56 +197,56 @@ public void Add_more_than_two_days() public void Subtract_minutes() { var sut = new Clock(10, 3); - Assert.Equal("10:00", sut.Add(-3).ToString()); + Assert.Equal("10:00", sut.Subtract(3).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_to_previous_hour() { var sut = new Clock(10, 3); - Assert.Equal("09:33", sut.Add(-30).ToString()); + Assert.Equal("09:33", sut.Subtract(30).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_more_than_an_hour() { var sut = new Clock(10, 3); - Assert.Equal("08:53", sut.Add(-70).ToString()); + Assert.Equal("08:53", sut.Subtract(70).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_across_midnight() { var sut = new Clock(0, 3); - Assert.Equal("23:59", sut.Add(-4).ToString()); + Assert.Equal("23:59", sut.Subtract(4).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_more_than_two_hours() { var sut = new Clock(0, 0); - Assert.Equal("21:20", sut.Add(-160).ToString()); + Assert.Equal("21:20", sut.Subtract(160).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_more_than_two_hours_with_borrow() { var sut = new Clock(6, 15); - Assert.Equal("03:35", sut.Add(-160).ToString()); + Assert.Equal("03:35", sut.Subtract(160).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_more_than_one_day_1500_min_25_hrs_() { var sut = new Clock(5, 32); - Assert.Equal("04:32", sut.Add(-1500).ToString()); + Assert.Equal("04:32", sut.Subtract(1500).ToString()); } [Fact(Skip = "Remove to run test")] public void Subtract_more_than_two_days() { var sut = new Clock(2, 20); - Assert.Equal("00:20", sut.Add(-3000).ToString()); + Assert.Equal("00:20", sut.Subtract(3000).ToString()); } [Fact(Skip = "Remove to run test")] diff --git a/exercises/collatz-conjecture/CollatzConjectureTest.cs b/exercises/collatz-conjecture/CollatzConjectureTest.cs index da1987ba66..32b512d359 100644 --- a/exercises/collatz-conjecture/CollatzConjectureTest.cs +++ b/exercises/collatz-conjecture/CollatzConjectureTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.1 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; using System; diff --git a/exercises/complex-numbers/ComplexNumbersTest.cs b/exercises/complex-numbers/ComplexNumbersTest.cs index c1e3380204..8835b7d521 100644 --- a/exercises/complex-numbers/ComplexNumbersTest.cs +++ b/exercises/complex-numbers/ComplexNumbersTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.3.0 of the canonical data. using Xunit; using System; @@ -6,6 +6,15 @@ public class ComplexNumbersTest { [Fact] + public void Imaginary_unit() + { + var sut = new ComplexNumber(0, 1); + var expected = new ComplexNumber(-1, 0); + Assert.Equal(expected.Real(), sut.Mul(new ComplexNumber(0, 1)).Real(), precision: 15); + Assert.Equal(expected.Imaginary(), sut.Mul(new ComplexNumber(0, 1)).Imaginary(), precision: 15); + } + + [Fact(Skip = "Remove to run test")] public void Real_part_of_a_purely_real_number() { var sut = new ComplexNumber(1, 0); @@ -47,15 +56,6 @@ public void Imaginary_part_of_a_number_with_real_and_imaginary_part() Assert.Equal(2, sut.Imaginary()); } - [Fact(Skip = "Remove to run test")] - public void Imaginary_unit() - { - var sut = new ComplexNumber(0, 1); - var expected = new ComplexNumber(-1, 0); - Assert.Equal(expected.Real(), sut.Mul(new ComplexNumber(0, 1)).Real(), precision: 15); - Assert.Equal(expected.Imaginary(), sut.Mul(new ComplexNumber(0, 1)).Imaginary(), precision: 15); - } - [Fact(Skip = "Remove to run test")] public void Add_purely_real_numbers() { @@ -252,4 +252,13 @@ public void Exponential_of_a_purely_real_number() Assert.Equal(expected.Real(), sut.Exp().Real(), precision: 15); Assert.Equal(expected.Imaginary(), sut.Exp().Imaginary(), precision: 15); } + + [Fact(Skip = "Remove to run test")] + public void Exponential_of_a_number_with_real_and_imaginary_part() + { + var sut = new ComplexNumber(Math.Log(2.0), Math.PI); + var expected = new ComplexNumber(-2, 0); + Assert.Equal(expected.Real(), sut.Exp().Real(), precision: 15); + Assert.Equal(expected.Imaginary(), sut.Exp().Imaginary(), precision: 15); + } } \ No newline at end of file diff --git a/exercises/connect/ConnectTest.cs b/exercises/connect/ConnectTest.cs index 213930c67d..2417d52d6d 100644 --- a/exercises/connect/ConnectTest.cs +++ b/exercises/connect/ConnectTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/crypto-square/CryptoSquareTest.cs b/exercises/crypto-square/CryptoSquareTest.cs index 5c4a471920..f9d4eb8632 100644 --- a/exercises/crypto-square/CryptoSquareTest.cs +++ b/exercises/crypto-square/CryptoSquareTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 3.1.0 of the canonical data. +// This file was auto-generated based on version 3.2.0 of the canonical data. using Xunit; diff --git a/exercises/difference-of-squares/DifferenceOfSquaresTest.cs b/exercises/difference-of-squares/DifferenceOfSquaresTest.cs index 8b5a040350..d21b61a242 100644 --- a/exercises/difference-of-squares/DifferenceOfSquaresTest.cs +++ b/exercises/difference-of-squares/DifferenceOfSquaresTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/dominoes/DominoesTest.cs b/exercises/dominoes/DominoesTest.cs index 4039fc56bd..97fa3bc7dd 100644 --- a/exercises/dominoes/DominoesTest.cs +++ b/exercises/dominoes/DominoesTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.0 of the canonical data. +// This file was auto-generated based on version 2.1.0 of the canonical data. using Xunit; using System; @@ -8,84 +8,84 @@ public class DominoesTest [Fact] public void Empty_input_empty_output() { - var input = new Tuple[] { }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { }; + Assert.True(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Singleton_input_singleton_output() { - var input = new Tuple[] { Tuple.Create(1, 1) }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 1) }; + Assert.True(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Singleton_that_cant_be_chained() { - var input = new Tuple[] { Tuple.Create(1, 2) }; - Assert.False(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2) }; + Assert.False(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Three_elements() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(3, 1), Tuple.Create(2, 3) }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(3, 1), Tuple.Create(2, 3) }; + Assert.True(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Can_reverse_dominoes() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(1, 3), Tuple.Create(2, 3) }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(1, 3), Tuple.Create(2, 3) }; + Assert.True(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Cant_be_chained() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(4, 1), Tuple.Create(2, 3) }; - Assert.False(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(4, 1), Tuple.Create(2, 3) }; + Assert.False(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Disconnected_simple() { - var input = new Tuple[] { Tuple.Create(1, 1), Tuple.Create(2, 2) }; - Assert.False(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 1), Tuple.Create(2, 2) }; + Assert.False(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Disconnected_double_loop() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 1), Tuple.Create(3, 4), Tuple.Create(4, 3) }; - Assert.False(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 1), Tuple.Create(3, 4), Tuple.Create(4, 3) }; + Assert.False(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Disconnected_single_isolated() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 3), Tuple.Create(3, 1), Tuple.Create(4, 4) }; - Assert.False(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 3), Tuple.Create(3, 1), Tuple.Create(4, 4) }; + Assert.False(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Need_backtrack() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 3), Tuple.Create(3, 1), Tuple.Create(2, 4), Tuple.Create(2, 4) }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 3), Tuple.Create(3, 1), Tuple.Create(2, 4), Tuple.Create(2, 4) }; + Assert.True(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Separate_loops() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 3), Tuple.Create(3, 1), Tuple.Create(1, 1), Tuple.Create(2, 2), Tuple.Create(3, 3) }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(2, 3), Tuple.Create(3, 1), Tuple.Create(1, 1), Tuple.Create(2, 2), Tuple.Create(3, 3) }; + Assert.True(Dominoes.CanChain(dominoes)); } [Fact(Skip = "Remove to run test")] public void Nine_elements() { - var input = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(5, 3), Tuple.Create(3, 1), Tuple.Create(1, 2), Tuple.Create(2, 4), Tuple.Create(1, 6), Tuple.Create(2, 3), Tuple.Create(3, 4), Tuple.Create(5, 6) }; - Assert.True(Dominoes.CanChain(input)); + var dominoes = new Tuple[] { Tuple.Create(1, 2), Tuple.Create(5, 3), Tuple.Create(3, 1), Tuple.Create(1, 2), Tuple.Create(2, 4), Tuple.Create(1, 6), Tuple.Create(2, 3), Tuple.Create(3, 4), Tuple.Create(5, 6) }; + Assert.True(Dominoes.CanChain(dominoes)); } } \ No newline at end of file diff --git a/exercises/etl/Etl.cs b/exercises/etl/Etl.cs index 7f29bf4518..2704c6ccc3 100644 --- a/exercises/etl/Etl.cs +++ b/exercises/etl/Etl.cs @@ -3,7 +3,7 @@ public static class Etl { - public static IDictionary Transform(IDictionary> old) + public static Dictionary Transform(Dictionary old) { throw new NotImplementedException("You need to implement this function."); } diff --git a/exercises/etl/EtlTest.cs b/exercises/etl/EtlTest.cs index 975b6b803d..5207bd5c74 100644 --- a/exercises/etl/EtlTest.cs +++ b/exercises/etl/EtlTest.cs @@ -8,7 +8,7 @@ public class EtlTest [Fact] public void A_single_letter() { - var input = new Dictionary> + var input = new Dictionary { [1] = new[] { "A" } }; @@ -22,7 +22,7 @@ public void A_single_letter() [Fact(Skip = "Remove to run test")] public void Single_score_with_multiple_letters() { - var input = new Dictionary> + var input = new Dictionary { [1] = new[] { "A", "E", "I", "O", "U" } }; @@ -40,7 +40,7 @@ public void Single_score_with_multiple_letters() [Fact(Skip = "Remove to run test")] public void Multiple_scores_with_multiple_letters() { - var input = new Dictionary> + var input = new Dictionary { [1] = new[] { "A", "E" }, [2] = new[] { "D", "G" } @@ -58,7 +58,7 @@ public void Multiple_scores_with_multiple_letters() [Fact(Skip = "Remove to run test")] public void Multiple_scores_with_differing_numbers_of_letters() { - var input = new Dictionary> + var input = new Dictionary { [1] = new[] { "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" }, [2] = new[] { "D", "G" }, diff --git a/exercises/etl/Example.cs b/exercises/etl/Example.cs index 5decaf54f4..832d76167d 100644 --- a/exercises/etl/Example.cs +++ b/exercises/etl/Example.cs @@ -2,7 +2,7 @@ public static class Etl { - public static IDictionary Transform(IDictionary> old) + public static Dictionary Transform(Dictionary old) { var transformed = new Dictionary(); diff --git a/exercises/flatten-array/FlattenArrayTest.cs b/exercises/flatten-array/FlattenArrayTest.cs index 42957ea089..9d66683805 100644 --- a/exercises/flatten-array/FlattenArrayTest.cs +++ b/exercises/flatten-array/FlattenArrayTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; @@ -7,15 +7,15 @@ public class FlattenArrayTest [Fact] public void No_nesting() { - var input = new[] { 0, 1, 2 }; + var array = new[] { 0, 1, 2 }; var expected = new[] { 0, 1, 2 }; - Assert.Equal(expected, FlattenArray.Flatten(input)); + Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove to run test")] public void Flattens_array_with_just_integers_present() { - var input = new object[] { + var array = new object[] { 1, new object[] { 2, @@ -28,13 +28,13 @@ public void Flattens_array_with_just_integers_present() 8 }; var expected = new[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - Assert.Equal(expected, FlattenArray.Flatten(input)); + Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove to run test")] public void Number_5_level_nesting() { - var input = new object[] { + var array = new object[] { 0, 2, new object[] { @@ -56,13 +56,13 @@ public void Number_5_level_nesting() -2 }; var expected = new[] { 0, 2, 2, 3, 8, 100, 4, 50, -2 }; - Assert.Equal(expected, FlattenArray.Flatten(input)); + Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove to run test")] public void Number_6_level_nesting() { - var input = new object[] { + var array = new object[] { 1, new object[] { 2, @@ -85,13 +85,13 @@ public void Number_6_level_nesting() 8 }; var expected = new[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - Assert.Equal(expected, FlattenArray.Flatten(input)); + Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove to run test")] public void Number_6_level_nest_list_with_null_values() { - var input = new object[] { + var array = new object[] { 0, 2, new object[] { @@ -115,13 +115,13 @@ public void Number_6_level_nest_list_with_null_values() -2 }; var expected = new[] { 0, 2, 2, 3, 8, 100, -2 }; - Assert.Equal(expected, FlattenArray.Flatten(input)); + Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove to run test")] public void All_values_in_nested_list_are_null() { - var input = new object[] { + var array = new object[] { null, new object[] { new object[] { @@ -141,6 +141,6 @@ public void All_values_in_nested_list_are_null() }, null }; - Assert.Empty(FlattenArray.Flatten(input)); + Assert.Empty(FlattenArray.Flatten(array)); } } \ No newline at end of file diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index a2389d9527..80fbfada00 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.0 of the canonical data. +// This file was auto-generated based on version 2.1.0 of the canonical data. using Xunit; diff --git a/exercises/gigasecond/GigasecondTest.cs b/exercises/gigasecond/GigasecondTest.cs index 97564d1f34..2c56fe3f73 100644 --- a/exercises/gigasecond/GigasecondTest.cs +++ b/exercises/gigasecond/GigasecondTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/grains/GrainsTest.cs b/exercises/grains/GrainsTest.cs index 31709cc979..895efb6775 100644 --- a/exercises/grains/GrainsTest.cs +++ b/exercises/grains/GrainsTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/hamming/HammingTest.cs b/exercises/hamming/HammingTest.cs index dba450aebc..67d3b71159 100644 --- a/exercises/hamming/HammingTest.cs +++ b/exercises/hamming/HammingTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.1 of the canonical data. +// This file was auto-generated based on version 2.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/hello-world/HelloWorldTest.cs b/exercises/hello-world/HelloWorldTest.cs index 2389b057d4..9aa33a72f9 100644 --- a/exercises/hello-world/HelloWorldTest.cs +++ b/exercises/hello-world/HelloWorldTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/house/Example.cs b/exercises/house/Example.cs index 8f831b9aae..a4cb62ba99 100644 --- a/exercises/house/Example.cs +++ b/exercises/house/Example.cs @@ -37,12 +37,12 @@ public static class House public static string Recite(int startVerse, int endVerse) { var numberOfVerses = endVerse - startVerse + 1; - return string.Join("\n\n", Enumerable.Range(startVerse, numberOfVerses).Select(Verse)); + return string.Join("\n", Enumerable.Range(startVerse, numberOfVerses).Select(Verse)); } private static string Verse(int number) { - return string.Join("\n", Enumerable.Range(1, number).Reverse().Select(index => Line(number, index))); + return string.Join(" ", Enumerable.Range(1, number).Reverse().Select(index => Line(number, index))); } private static string Line(int number, int index) diff --git a/exercises/house/HouseTest.cs b/exercises/house/HouseTest.cs index ab9eb1ea96..fecadfcf6a 100644 --- a/exercises/house/HouseTest.cs +++ b/exercises/house/HouseTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.0 of the canonical data. +// This file was auto-generated based on version 2.2.0 of the canonical data. using Xunit; @@ -14,154 +14,77 @@ public void Verse_one_the_house_that_jack_built() [Fact(Skip = "Remove to run test")] public void Verse_two_the_malt_that_lay() { - var expected = - "This is the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(2, 2)); } [Fact(Skip = "Remove to run test")] public void Verse_three_the_rat_that_ate() { - var expected = - "This is the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(3, 3)); } [Fact(Skip = "Remove to run test")] public void Verse_four_the_cat_that_killed() { - var expected = - "This is the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(4, 4)); } [Fact(Skip = "Remove to run test")] public void Verse_five_the_dog_that_worried() { - var expected = - "This is the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(5, 5)); } [Fact(Skip = "Remove to run test")] public void Verse_six_the_cow_with_the_crumpled_horn() { - var expected = - "This is the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(6, 6)); } [Fact(Skip = "Remove to run test")] public void Verse_seven_the_maiden_all_forlorn() { - var expected = - "This is the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(7, 7)); } [Fact(Skip = "Remove to run test")] public void Verse_eight_the_man_all_tattered_and_torn() { - var expected = - "This is the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(8, 8)); } [Fact(Skip = "Remove to run test")] public void Verse_nine_the_priest_all_shaven_and_shorn() { - var expected = - "This is the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(9, 9)); } [Fact(Skip = "Remove to run test")] public void Verse_10_the_rooster_that_crowed_in_the_morn() { - var expected = - "This is the rooster that crowed in the morn\n" + - "that woke the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(10, 10)); } [Fact(Skip = "Remove to run test")] public void Verse_11_the_farmer_sowing_his_corn() { - var expected = - "This is the farmer sowing his corn\n" + - "that kept the rooster that crowed in the morn\n" + - "that woke the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(11, 11)); } [Fact(Skip = "Remove to run test")] public void Verse_12_the_horse_and_the_hound_and_the_horn() { - var expected = - "This is the horse and the hound and the horn\n" + - "that belonged to the farmer sowing his corn\n" + - "that kept the rooster that crowed in the morn\n" + - "that woke the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + var expected = "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(12, 12)); } @@ -169,40 +92,11 @@ public void Verse_12_the_horse_and_the_hound_and_the_horn() public void Multiple_verses() { var expected = - "This is the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + "This is the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(4, 8)); } @@ -211,94 +105,17 @@ public void Full_rhyme() { var expected = "This is the house that Jack built.\n" + - "\n" + - "This is the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the rooster that crowed in the morn\n" + - "that woke the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the farmer sowing his corn\n" + - "that kept the rooster that crowed in the morn\n" + - "that woke the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built.\n" + - "\n" + - "This is the horse and the hound and the horn\n" + - "that belonged to the farmer sowing his corn\n" + - "that kept the rooster that crowed in the morn\n" + - "that woke the priest all shaven and shorn\n" + - "that married the man all tattered and torn\n" + - "that kissed the maiden all forlorn\n" + - "that milked the cow with the crumpled horn\n" + - "that tossed the dog\n" + - "that worried the cat\n" + - "that killed the rat\n" + - "that ate the malt\n" + - "that lay in the house that Jack built."; + "This is the malt that lay in the house that Jack built.\n" + + "This is the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built.\n" + + "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; Assert.Equal(expected, House.Recite(1, 12)); } } \ No newline at end of file diff --git a/exercises/isbn-verifier/IsbnVerifierTest.cs b/exercises/isbn-verifier/IsbnVerifierTest.cs index 9f3ab542b2..2d5999111c 100644 --- a/exercises/isbn-verifier/IsbnVerifierTest.cs +++ b/exercises/isbn-verifier/IsbnVerifierTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.0 of the canonical data. +// This file was auto-generated based on version 2.4.0 of the canonical data. using Xunit; @@ -31,7 +31,7 @@ public void Check_digit_is_a_character_other_than_x() [Fact(Skip = "Remove to run test")] public void Invalid_character_in_isbn() { - Assert.False(IsbnVerifier.IsValid("3-598-2K507-0")); + Assert.False(IsbnVerifier.IsValid("3-598-P1581-X")); } [Fact(Skip = "Remove to run test")] @@ -81,4 +81,16 @@ public void Check_digit_of_x_should_not_be_used_for_0() { Assert.False(IsbnVerifier.IsValid("3-598-21515-X")); } + + [Fact(Skip = "Remove to run test")] + public void Empty_isbn() + { + Assert.False(IsbnVerifier.IsValid("")); + } + + [Fact(Skip = "Remove to run test")] + public void Input_is_9_characters() + { + Assert.False(IsbnVerifier.IsValid("134456729")); + } } \ No newline at end of file diff --git a/exercises/isogram/IsogramTest.cs b/exercises/isogram/IsogramTest.cs index d11baa30f3..d4d15aaeec 100644 --- a/exercises/isogram/IsogramTest.cs +++ b/exercises/isogram/IsogramTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.2.0 of the canonical data. +// This file was auto-generated based on version 1.3.0 of the canonical data. using Xunit; diff --git a/exercises/kindergarten-garden/KindergartenGardenTest.cs b/exercises/kindergarten-garden/KindergartenGardenTest.cs index 550d98b042..dfb0d51f4b 100644 --- a/exercises/kindergarten-garden/KindergartenGardenTest.cs +++ b/exercises/kindergarten-garden/KindergartenGardenTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.1 of the canonical data. using Xunit; diff --git a/exercises/largest-series-product/LargestSeriesProductTest.cs b/exercises/largest-series-product/LargestSeriesProductTest.cs index 21ac6b4e5b..c41f8613c4 100644 --- a/exercises/largest-series-product/LargestSeriesProductTest.cs +++ b/exercises/largest-series-product/LargestSeriesProductTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/leap/LeapTest.cs b/exercises/leap/LeapTest.cs index 9eee13ae1a..228ea69015 100644 --- a/exercises/leap/LeapTest.cs +++ b/exercises/leap/LeapTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.2.0 of the canonical data. +// This file was auto-generated based on version 1.3.0 of the canonical data. using Xunit; diff --git a/exercises/luhn/LuhnTest.cs b/exercises/luhn/LuhnTest.cs index 6f48d6f9bc..cd5a0215c8 100644 --- a/exercises/luhn/LuhnTest.cs +++ b/exercises/luhn/LuhnTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/minesweeper/MinesweeperTest.cs b/exercises/minesweeper/MinesweeperTest.cs index aebdc36723..f44f6dad1c 100644 --- a/exercises/minesweeper/MinesweeperTest.cs +++ b/exercises/minesweeper/MinesweeperTest.cs @@ -1,27 +1,22 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; +using System; public class MinesweeperTest { [Fact] public void No_rows() { - var input = new string[] - { - - }; - var expected = new string[] - { - - }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + var minefield = new string[0]; + var expected = new string[0]; + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void No_columns() { - var input = new string[] + var minefield = new string[] { "" }; @@ -29,13 +24,13 @@ public void No_columns() { "" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void No_mines() { - var input = new string[] + var minefield = new string[] { " ", " ", @@ -49,13 +44,13 @@ public void No_mines() " " }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] - public void Board_with_only_mines() + public void Minefield_with_only_mines() { - var input = new string[] + var minefield = new string[] { "***", "***", @@ -69,13 +64,13 @@ public void Board_with_only_mines() "***" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Mine_surrounded_by_spaces() { - var input = new string[] + var minefield = new string[] { " ", " * ", @@ -89,13 +84,13 @@ public void Mine_surrounded_by_spaces() "111" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Space_surrounded_by_mines() { - var input = new string[] + var minefield = new string[] { "***", "* *", @@ -109,13 +104,13 @@ public void Space_surrounded_by_mines() "***" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Horizontal_line() { - var input = new string[] + var minefield = new string[] { " * * " }; @@ -123,13 +118,13 @@ public void Horizontal_line() { "1*2*1" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Horizontal_line_mines_at_edges() { - var input = new string[] + var minefield = new string[] { "* *" }; @@ -137,13 +132,13 @@ public void Horizontal_line_mines_at_edges() { "*1 1*" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Vertical_line() { - var input = new string[] + var minefield = new string[] { " ", "*", @@ -161,13 +156,13 @@ public void Vertical_line() "1" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Vertical_line_mines_at_edges() { - var input = new string[] + var minefield = new string[] { "*", " ", @@ -185,13 +180,13 @@ public void Vertical_line_mines_at_edges() "*" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] public void Cross() { - var input = new string[] + var minefield = new string[] { " * ", " * ", @@ -209,13 +204,13 @@ public void Cross() " 2*2 " }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove to run test")] - public void Large_board() + public void Large_minefield() { - var input = new string[] + var minefield = new string[] { " * * ", " * ", @@ -235,6 +230,6 @@ public void Large_board() "111111" }; - Assert.Equal(expected, Minesweeper.Annotate(input)); + Assert.Equal(expected, Minesweeper.Annotate(minefield)); } } \ No newline at end of file diff --git a/exercises/nth-prime/NthPrimeTest.cs b/exercises/nth-prime/NthPrimeTest.cs index 8f334d8a50..8c9aec4c89 100644 --- a/exercises/nth-prime/NthPrimeTest.cs +++ b/exercises/nth-prime/NthPrimeTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.0 of the canonical data. +// This file was auto-generated based on version 2.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/nucleotide-count/NucleotideCountTest.cs b/exercises/nucleotide-count/NucleotideCountTest.cs index d3e5fdf7d5..9b4174757c 100644 --- a/exercises/nucleotide-count/NucleotideCountTest.cs +++ b/exercises/nucleotide-count/NucleotideCountTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.2.0 of the canonical data. +// This file was auto-generated based on version 1.3.0 of the canonical data. using Xunit; using System.Collections.Generic; diff --git a/exercises/ocr-numbers/OcrNumbersTest.cs b/exercises/ocr-numbers/OcrNumbersTest.cs index e4e2d8ae6c..b189cdc75d 100644 --- a/exercises/ocr-numbers/OcrNumbersTest.cs +++ b/exercises/ocr-numbers/OcrNumbersTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; @@ -8,180 +8,180 @@ public class OcrNumbersTest [Fact] public void Recognizes_0() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + "| |" + "\n" + "|_|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("0", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_1() { - var input = " " + "\n" + + var rows = " " + "\n" + " |" + "\n" + " |" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("1", actual); } [Fact(Skip = "Remove to run test")] public void Unreadable_but_correctly_sized_inputs_return_() { - var input = " " + "\n" + + var rows = " " + "\n" + " _" + "\n" + " |" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("?", actual); } [Fact(Skip = "Remove to run test")] public void Input_with_a_number_of_lines_that_is_not_a_multiple_of_four_raises_an_error() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + "| |" + "\n" + " "; - Assert.Throws(() => OcrNumbers.Convert(input)); + Assert.Throws(() => OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove to run test")] public void Input_with_a_number_of_columns_that_is_not_a_multiple_of_three_raises_an_error() { - var input = " " + "\n" + + var rows = " " + "\n" + " |" + "\n" + " |" + "\n" + " "; - Assert.Throws(() => OcrNumbers.Convert(input)); + Assert.Throws(() => OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove to run test")] public void Recognizes_110101100() { - var input = " _ _ _ _ " + "\n" + + var rows = " _ _ _ _ " + "\n" + " | || | || | | || || |" + "\n" + " | ||_| ||_| | ||_||_|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("110101100", actual); } [Fact(Skip = "Remove to run test")] public void Garbled_numbers_in_a_string_are_replaced_with_() { - var input = " _ _ _ " + "\n" + + var rows = " _ _ _ " + "\n" + " | || | || | || || |" + "\n" + " | | _| ||_| | ||_||_|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("11?10?1?0", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_2() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + " _|" + "\n" + "|_ " + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("2", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_3() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + " _|" + "\n" + " _|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("3", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_4() { - var input = " " + "\n" + + var rows = " " + "\n" + "|_|" + "\n" + " |" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("4", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_5() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + "|_ " + "\n" + " _|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("5", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_6() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + "|_ " + "\n" + "|_|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("6", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_7() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + " |" + "\n" + " |" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("7", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_8() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + "|_|" + "\n" + "|_|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("8", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_9() { - var input = " _ " + "\n" + + var rows = " _ " + "\n" + "|_|" + "\n" + " _|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("9", actual); } [Fact(Skip = "Remove to run test")] public void Recognizes_string_of_decimal_numbers() { - var input = " _ _ _ _ _ _ _ _ " + "\n" + + var rows = " _ _ _ _ _ _ _ _ " + "\n" + " | _| _||_||_ |_ ||_||_|| |" + "\n" + " ||_ _| | _||_| ||_| _||_|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("1234567890", actual); } [Fact(Skip = "Remove to run test")] public void Numbers_separated_by_empty_lines_are_recognized_lines_are_joined_by_commas_() { - var input = " _ _ " + "\n" + + var rows = " _ _ " + "\n" + " | _| _|" + "\n" + " ||_ _|" + "\n" + " " + "\n" + @@ -193,7 +193,7 @@ public void Numbers_separated_by_empty_lines_are_recognized_lines_are_joined_by_ " ||_||_|" + "\n" + " ||_| _|" + "\n" + " "; - var actual = OcrNumbers.Convert(input); + var actual = OcrNumbers.Convert(rows); Assert.Equal("123,456,789", actual); } } \ No newline at end of file diff --git a/exercises/pangram/PangramTest.cs b/exercises/pangram/PangramTest.cs index b91d71a6b7..6bb6f0c4a3 100644 --- a/exercises/pangram/PangramTest.cs +++ b/exercises/pangram/PangramTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.3.0 of the canonical data. +// This file was auto-generated based on version 1.4.0 of the canonical data. using Xunit; diff --git a/exercises/pascals-triangle/PascalsTriangleTest.cs b/exercises/pascals-triangle/PascalsTriangleTest.cs index 3242ac8056..b5d1fad9ef 100644 --- a/exercises/pascals-triangle/PascalsTriangleTest.cs +++ b/exercises/pascals-triangle/PascalsTriangleTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.2.0 of the canonical data. +// This file was auto-generated based on version 1.3.0 of the canonical data. using Xunit; using System; diff --git a/exercises/perfect-numbers/PerfectNumbersTest.cs b/exercises/perfect-numbers/PerfectNumbersTest.cs index 01b2a9e6df..7fc8dd88fc 100644 --- a/exercises/perfect-numbers/PerfectNumbersTest.cs +++ b/exercises/perfect-numbers/PerfectNumbersTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.1 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/phone-number/PhoneNumberTest.cs b/exercises/phone-number/PhoneNumberTest.cs index 8db440aebc..7ffaa32460 100644 --- a/exercises/phone-number/PhoneNumberTest.cs +++ b/exercises/phone-number/PhoneNumberTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.2.0 of the canonical data. +// This file was auto-generated based on version 1.4.0 of the canonical data. using Xunit; using System; @@ -76,16 +76,30 @@ public void Invalid_with_punctuations() } [Fact(Skip = "Remove to run test")] - public void Invalid_if_area_code_does_not_start_with_2_9() + public void Invalid_if_area_code_starts_with_0() + { + var phrase = "(023) 456-7890"; + Assert.Throws(() => PhoneNumber.Clean(phrase)); + } + + [Fact(Skip = "Remove to run test")] + public void Invalid_if_area_code_starts_with_1() { var phrase = "(123) 456-7890"; Assert.Throws(() => PhoneNumber.Clean(phrase)); } [Fact(Skip = "Remove to run test")] - public void Invalid_if_exchange_code_does_not_start_with_2_9() + public void Invalid_if_exchange_code_starts_with_0() { var phrase = "(223) 056-7890"; Assert.Throws(() => PhoneNumber.Clean(phrase)); } + + [Fact(Skip = "Remove to run test")] + public void Invalid_if_exchange_code_starts_with_1() + { + var phrase = "(223) 156-7890"; + Assert.Throws(() => PhoneNumber.Clean(phrase)); + } } \ No newline at end of file diff --git a/exercises/pig-latin/PigLatinTest.cs b/exercises/pig-latin/PigLatinTest.cs index 3ddec03711..3714e5a68c 100644 --- a/exercises/pig-latin/PigLatinTest.cs +++ b/exercises/pig-latin/PigLatinTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/poker/PokerTest.cs b/exercises/poker/PokerTest.cs index 58d2205b6b..3f4001855c 100644 --- a/exercises/poker/PokerTest.cs +++ b/exercises/poker/PokerTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/prime-factors/PrimeFactorsTest.cs b/exercises/prime-factors/PrimeFactorsTest.cs index 6e5262722e..99fc9a7dad 100644 --- a/exercises/prime-factors/PrimeFactorsTest.cs +++ b/exercises/prime-factors/PrimeFactorsTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/queen-attack/QueenAttackTest.cs b/exercises/queen-attack/QueenAttackTest.cs index 12a28865d8..5b85d6459e 100644 --- a/exercises/queen-attack/QueenAttackTest.cs +++ b/exercises/queen-attack/QueenAttackTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 2.0.0 of the canonical data. +// This file was auto-generated based on version 2.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/rail-fence-cipher/RailFenceCipherTest.cs b/exercises/rail-fence-cipher/RailFenceCipherTest.cs index 0c53ef9967..098116cfa3 100644 --- a/exercises/rail-fence-cipher/RailFenceCipherTest.cs +++ b/exercises/rail-fence-cipher/RailFenceCipherTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.1 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/raindrops/RaindropsTest.cs b/exercises/raindrops/RaindropsTest.cs index e5e9b659aa..f15baff846 100644 --- a/exercises/raindrops/RaindropsTest.cs +++ b/exercises/raindrops/RaindropsTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/reverse-string/ReverseStringTest.cs b/exercises/reverse-string/ReverseStringTest.cs index d1b253bdc6..611e62c206 100644 --- a/exercises/reverse-string/ReverseStringTest.cs +++ b/exercises/reverse-string/ReverseStringTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.1 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/rna-transcription/RnaTranscriptionTest.cs b/exercises/rna-transcription/RnaTranscriptionTest.cs index 64956d91dd..6b3cf7a062 100644 --- a/exercises/rna-transcription/RnaTranscriptionTest.cs +++ b/exercises/rna-transcription/RnaTranscriptionTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/roman-numerals/RomanNumeralsTest.cs b/exercises/roman-numerals/RomanNumeralsTest.cs index 125e2f701a..fc20ce9361 100644 --- a/exercises/roman-numerals/RomanNumeralsTest.cs +++ b/exercises/roman-numerals/RomanNumeralsTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; @@ -58,6 +58,12 @@ public void Number_48_is_not_50_2_but_rather_40_8() Assert.Equal("XLVIII", 48.ToRoman()); } + [Fact(Skip = "Remove to run test")] + public void Number_49_is_not_40_5_4_but_rather_50_10_10_1() + { + Assert.Equal("XLIX", 49.ToRoman()); + } + [Fact(Skip = "Remove to run test")] public void Number_50_is_a_single_l() { diff --git a/exercises/rotational-cipher/RotationalCipherTest.cs b/exercises/rotational-cipher/RotationalCipherTest.cs index ca9488bda3..21d6864286 100644 --- a/exercises/rotational-cipher/RotationalCipherTest.cs +++ b/exercises/rotational-cipher/RotationalCipherTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/run-length-encoding/RunLengthEncodingTest.cs b/exercises/run-length-encoding/RunLengthEncodingTest.cs index 947747ac3d..f840783774 100644 --- a/exercises/run-length-encoding/RunLengthEncodingTest.cs +++ b/exercises/run-length-encoding/RunLengthEncodingTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/saddle-points/SaddlePointsTest.cs b/exercises/saddle-points/SaddlePointsTest.cs index 4020e1552b..db0c869a53 100644 --- a/exercises/saddle-points/SaddlePointsTest.cs +++ b/exercises/saddle-points/SaddlePointsTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; @@ -8,13 +8,13 @@ public class SaddlePointsTest [Fact] public void Can_identify_single_saddle_point() { - var input = new[,] + var matrix = new[,] { { 9, 8, 7 }, { 5, 3, 2 }, { 6, 6, 7 } }; - var sut = new SaddlePoints(input); + var sut = new SaddlePoints(matrix); var actual = sut.Calculate(); var expected = new[] { Tuple.Create(1, 0) }; Assert.Equal(expected, actual); @@ -23,8 +23,8 @@ public void Can_identify_single_saddle_point() [Fact(Skip = "Remove to run test")] public void Can_identify_that_empty_matrix_has_no_saddle_points() { - var input = new int[,] { }; - var sut = new SaddlePoints(input); + var matrix = new int[,] { }; + var sut = new SaddlePoints(matrix); var actual = sut.Calculate(); Assert.Empty(actual); } @@ -32,13 +32,13 @@ public void Can_identify_that_empty_matrix_has_no_saddle_points() [Fact(Skip = "Remove to run test")] public void Can_identify_lack_of_saddle_points_when_there_are_none() { - var input = new[,] + var matrix = new[,] { { 1, 2, 3 }, { 3, 1, 2 }, { 2, 3, 1 } }; - var sut = new SaddlePoints(input); + var sut = new SaddlePoints(matrix); var actual = sut.Calculate(); Assert.Empty(actual); } @@ -46,13 +46,13 @@ public void Can_identify_lack_of_saddle_points_when_there_are_none() [Fact(Skip = "Remove to run test")] public void Can_identify_multiple_saddle_points() { - var input = new[,] + var matrix = new[,] { { 4, 5, 4 }, { 3, 5, 5 }, { 1, 5, 4 } }; - var sut = new SaddlePoints(input); + var sut = new SaddlePoints(matrix); var actual = sut.Calculate(); var expected = new[] { Tuple.Create(0, 1), Tuple.Create(1, 1), Tuple.Create(2, 1) }; Assert.Equal(expected, actual); @@ -61,13 +61,13 @@ public void Can_identify_multiple_saddle_points() [Fact(Skip = "Remove to run test")] public void Can_identify_saddle_point_in_bottom_right_corner() { - var input = new[,] + var matrix = new[,] { { 8, 7, 9 }, { 6, 7, 6 }, { 3, 2, 5 } }; - var sut = new SaddlePoints(input); + var sut = new SaddlePoints(matrix); var actual = sut.Calculate(); var expected = new[] { Tuple.Create(2, 2) }; Assert.Equal(expected, actual); diff --git a/exercises/say/SayTest.cs b/exercises/say/SayTest.cs index c553404b7e..4b831f8de2 100644 --- a/exercises/say/SayTest.cs +++ b/exercises/say/SayTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/scrabble-score/ScrabbleScoreTest.cs b/exercises/scrabble-score/ScrabbleScoreTest.cs index 2e8cba75ca..8ea1b3b201 100644 --- a/exercises/scrabble-score/ScrabbleScoreTest.cs +++ b/exercises/scrabble-score/ScrabbleScoreTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/secret-handshake/SecretHandshakeTest.cs b/exercises/secret-handshake/SecretHandshakeTest.cs index db13f1f1cb..a6dd818635 100644 --- a/exercises/secret-handshake/SecretHandshakeTest.cs +++ b/exercises/secret-handshake/SecretHandshakeTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/sieve/SieveTest.cs b/exercises/sieve/SieveTest.cs index 4de24a373f..b30083c964 100644 --- a/exercises/sieve/SieveTest.cs +++ b/exercises/sieve/SieveTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/space-age/SpaceAgeTest.cs b/exercises/space-age/SpaceAgeTest.cs index e13487ad2d..89bd5e0a43 100644 --- a/exercises/space-age/SpaceAgeTest.cs +++ b/exercises/space-age/SpaceAgeTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/sum-of-multiples/SumOfMultiplesTest.cs b/exercises/sum-of-multiples/SumOfMultiplesTest.cs index 319b96a0e7..46268814f4 100644 --- a/exercises/sum-of-multiples/SumOfMultiplesTest.cs +++ b/exercises/sum-of-multiples/SumOfMultiplesTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/tournament/Example.cs b/exercises/tournament/Example.cs index f4fcec0802..5b9c837314 100644 --- a/exercises/tournament/Example.cs +++ b/exercises/tournament/Example.cs @@ -81,14 +81,21 @@ private void AddTeamOutcome(string team, Outcome outcome) private void WriteResults(TextWriter writer) { - writer.WriteLine( - "{0,-30:S} | {1,2:D} | {2,2:D} | {3,2:D} | {4,2:D} | {5,2:D}", - "Team", "MP", "W", "D", "L", "P"); - foreach (var pair in this.teams.OrderByDescending(pair => pair.Value.Score).ThenBy(pair => pair.Key)) { - writer.WriteLine( - "{0,-30:S} | {1,2:D} | {2,2:D} | {3,2:D} | {4,2:D} | {5,2:D}", + var headerSuffix = this.teams.Any() ? "\n" : ""; + writer.Write( + "{0,-30:S} | {1,2:D} | {2,2:D} | {3,2:D} | {4,2:D} | {5,2:D}{6}", + "Team", "MP", "W", "D", "L", "P", headerSuffix); + + var pairs = this.teams.OrderByDescending(pair => pair.Value.Score).ThenBy(pair => pair.Key).ToArray(); + + for (var i = 0; i < pairs.Length; i++) + { + var pair = pairs[i]; + var suffix = i == pairs.Length - 1 ? "" : "\n"; + writer.Write( + "{0,-30:S} | {1,2:D} | {2,2:D} | {3,2:D} | {4,2:D} | {5,2:D}{6}", pair.Key, pair.Value.Played, pair.Value.Wins, - pair.Value.Draws, pair.Value.Losses, pair.Value.Score); + pair.Value.Draws, pair.Value.Losses, pair.Value.Score, suffix); } writer.Flush(); } @@ -122,6 +129,7 @@ public static void Tally(Stream inStream, Stream outStream) } var outWriter = new StreamWriter(outStream, encoding); + outWriter.NewLine = "\n"; tournament.WriteResults(outWriter); } } diff --git a/exercises/tournament/TournamentTest.cs b/exercises/tournament/TournamentTest.cs index 6c0d79c62d..881efaad14 100644 --- a/exercises/tournament/TournamentTest.cs +++ b/exercises/tournament/TournamentTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.3.0 of the canonical data. +// This file was auto-generated based on version 1.4.0 of the canonical data. using Xunit; using System; @@ -10,161 +10,159 @@ public class TournamentTest [Fact] public void Just_the_header_if_no_input() { - var input = string.Empty; - var expected = "Team | MP | W | D | L | P".Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = ""; + var expected = "Team | MP | W | D | L | P"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void A_win_is_three_points_a_loss_is_zero_points() { - var input = "Allegoric Alaskans;Blithering Badgers;win".Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3" + Environment.NewLine + - "Blithering Badgers | 1 | 0 | 0 | 1 | 0" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = "Allegoric Alaskans;Blithering Badgers;win"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" + + "Blithering Badgers | 1 | 0 | 0 | 1 | 0"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void A_win_can_also_be_expressed_as_a_loss() { - var input = "Blithering Badgers;Allegoric Alaskans;loss".Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3" + Environment.NewLine + - "Blithering Badgers | 1 | 0 | 0 | 1 | 0" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = "Blithering Badgers;Allegoric Alaskans;loss"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" + + "Blithering Badgers | 1 | 0 | 0 | 1 | 0"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void A_different_team_can_win() { - var input = "Blithering Badgers;Allegoric Alaskans;win".Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Blithering Badgers | 1 | 1 | 0 | 0 | 3" + Environment.NewLine + - "Allegoric Alaskans | 1 | 0 | 0 | 1 | 0" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = "Blithering Badgers;Allegoric Alaskans;win"; + var expected = + "Team | MP | W | D | L | P\n" + + "Blithering Badgers | 1 | 1 | 0 | 0 | 3\n" + + "Allegoric Alaskans | 1 | 0 | 0 | 1 | 0"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void A_draw_is_one_point_each() { - var input = "Allegoric Alaskans;Blithering Badgers;draw".Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 1 | 0 | 1 | 0 | 1" + Environment.NewLine + - "Blithering Badgers | 1 | 0 | 1 | 0 | 1" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = "Allegoric Alaskans;Blithering Badgers;draw"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 1 | 0 | 1 | 0 | 1\n" + + "Blithering Badgers | 1 | 0 | 1 | 0 | 1"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void There_can_be_more_than_one_match() { - var input = "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine + - "Allegoric Alaskans;Blithering Badgers;win" - .Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6" + Environment.NewLine + - "Blithering Badgers | 2 | 0 | 0 | 2 | 0" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = + "Allegoric Alaskans;Blithering Badgers;win\n" + + "Allegoric Alaskans;Blithering Badgers;win"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" + + "Blithering Badgers | 2 | 0 | 0 | 2 | 0"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void There_can_be_more_than_one_winner() { - var input = "Allegoric Alaskans;Blithering Badgers;loss" + Environment.NewLine + - "Allegoric Alaskans;Blithering Badgers;win" - .Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 2 | 1 | 0 | 1 | 3" + Environment.NewLine + - "Blithering Badgers | 2 | 1 | 0 | 1 | 3" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = + "Allegoric Alaskans;Blithering Badgers;loss\n" + + "Allegoric Alaskans;Blithering Badgers;win"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 2 | 1 | 0 | 1 | 3\n" + + "Blithering Badgers | 2 | 1 | 0 | 1 | 3"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void There_can_be_more_than_two_teams() { - var input = "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine + - "Blithering Badgers;Courageous Californians;win" + Environment.NewLine + - "Courageous Californians;Allegoric Alaskans;loss" - .Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6" + Environment.NewLine + - "Blithering Badgers | 2 | 1 | 0 | 1 | 3" + Environment.NewLine + - "Courageous Californians | 2 | 0 | 0 | 2 | 0" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = + "Allegoric Alaskans;Blithering Badgers;win\n" + + "Blithering Badgers;Courageous Californians;win\n" + + "Courageous Californians;Allegoric Alaskans;loss"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" + + "Blithering Badgers | 2 | 1 | 0 | 1 | 3\n" + + "Courageous Californians | 2 | 0 | 0 | 2 | 0"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void Typical_input() { - var input = "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine + - "Devastating Donkeys;Courageous Californians;draw" + Environment.NewLine + - "Devastating Donkeys;Allegoric Alaskans;win" + Environment.NewLine + - "Courageous Californians;Blithering Badgers;loss" + Environment.NewLine + - "Blithering Badgers;Devastating Donkeys;loss" + Environment.NewLine + - "Allegoric Alaskans;Courageous Californians;win" - .Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Devastating Donkeys | 3 | 2 | 1 | 0 | 7" + Environment.NewLine + - "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6" + Environment.NewLine + - "Blithering Badgers | 3 | 1 | 0 | 2 | 3" + Environment.NewLine + - "Courageous Californians | 3 | 0 | 1 | 2 | 1" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = + "Allegoric Alaskans;Blithering Badgers;win\n" + + "Devastating Donkeys;Courageous Californians;draw\n" + + "Devastating Donkeys;Allegoric Alaskans;win\n" + + "Courageous Californians;Blithering Badgers;loss\n" + + "Blithering Badgers;Devastating Donkeys;loss\n" + + "Allegoric Alaskans;Courageous Californians;win"; + var expected = + "Team | MP | W | D | L | P\n" + + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n" + + "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" + + "Blithering Badgers | 3 | 1 | 0 | 2 | 3\n" + + "Courageous Californians | 3 | 0 | 1 | 2 | 1"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void Incomplete_competition_not_all_pairs_have_played_() { - var input = "Allegoric Alaskans;Blithering Badgers;loss" + Environment.NewLine + - "Devastating Donkeys;Allegoric Alaskans;loss" + Environment.NewLine + - "Courageous Californians;Blithering Badgers;draw" + Environment.NewLine + - "Allegoric Alaskans;Courageous Californians;win" - .Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6" + Environment.NewLine + - "Blithering Badgers | 2 | 1 | 1 | 0 | 4" + Environment.NewLine + - "Courageous Californians | 2 | 0 | 1 | 1 | 1" + Environment.NewLine + - "Devastating Donkeys | 1 | 0 | 0 | 1 | 0" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = + "Allegoric Alaskans;Blithering Badgers;loss\n" + + "Devastating Donkeys;Allegoric Alaskans;loss\n" + + "Courageous Californians;Blithering Badgers;draw\n" + + "Allegoric Alaskans;Courageous Californians;win"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" + + "Blithering Badgers | 2 | 1 | 1 | 0 | 4\n" + + "Courageous Californians | 2 | 0 | 1 | 1 | 1\n" + + "Devastating Donkeys | 1 | 0 | 0 | 1 | 0"; + Assert.Equal(expected, RunTally(rows)); } [Fact(Skip = "Remove to run test")] public void Ties_broken_alphabetically() { - var input = "Courageous Californians;Devastating Donkeys;win" + Environment.NewLine + - "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine + - "Devastating Donkeys;Allegoric Alaskans;loss" + Environment.NewLine + - "Courageous Californians;Blithering Badgers;win" + Environment.NewLine + - "Blithering Badgers;Devastating Donkeys;draw" + Environment.NewLine + - "Allegoric Alaskans;Courageous Californians;draw" - .Trim(); - var expected = "Team | MP | W | D | L | P" + Environment.NewLine + - "Allegoric Alaskans | 3 | 2 | 1 | 0 | 7" + Environment.NewLine + - "Courageous Californians | 3 | 2 | 1 | 0 | 7" + Environment.NewLine + - "Blithering Badgers | 3 | 0 | 1 | 2 | 1" + Environment.NewLine + - "Devastating Donkeys | 3 | 0 | 1 | 2 | 1" - .Trim(); - Assert.Equal(expected, RunTally(input).Trim()); + var rows = + "Courageous Californians;Devastating Donkeys;win\n" + + "Allegoric Alaskans;Blithering Badgers;win\n" + + "Devastating Donkeys;Allegoric Alaskans;loss\n" + + "Courageous Californians;Blithering Badgers;win\n" + + "Blithering Badgers;Devastating Donkeys;draw\n" + + "Allegoric Alaskans;Courageous Californians;draw"; + var expected = + "Team | MP | W | D | L | P\n" + + "Allegoric Alaskans | 3 | 2 | 1 | 0 | 7\n" + + "Courageous Californians | 3 | 2 | 1 | 0 | 7\n" + + "Blithering Badgers | 3 | 0 | 1 | 2 | 1\n" + + "Devastating Donkeys | 3 | 0 | 1 | 2 | 1"; + Assert.Equal(expected, RunTally(rows)); } private string RunTally(string input) { var encoding = new UTF8Encoding(); using (var inStream = new MemoryStream(encoding.GetBytes(input))) + using (var outStream = new MemoryStream()) { - using (var outStream = new MemoryStream()) - { - Tournament.Tally(inStream, outStream); - return encoding.GetString(outStream.ToArray()); - } + Tournament.Tally(inStream, outStream); + return encoding.GetString(outStream.ToArray()); } } } \ No newline at end of file diff --git a/exercises/transpose/TransposeTest.cs b/exercises/transpose/TransposeTest.cs index b7893ed7c9..ac603d8778 100644 --- a/exercises/transpose/TransposeTest.cs +++ b/exercises/transpose/TransposeTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; @@ -7,48 +7,48 @@ public class TransposeTest [Fact] public void Empty_string() { - var input = ""; + var lines = ""; var expected = ""; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Two_characters_in_a_row() { - var input = "A1"; + var lines = "A1"; var expected = "A\n" + "1"; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Two_characters_in_a_column() { - var input = + var lines = "A\n" + "1"; var expected = "A1"; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Simple() { - var input = + var lines = "ABC\n" + "123"; var expected = "A1\n" + "B2\n" + "C3"; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Single_line() { - var input = "Single line."; + var lines = "Single line."; var expected = "S\n" + "i\n" + @@ -62,13 +62,13 @@ public void Single_line() "n\n" + "e\n" + "."; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void First_line_longer_than_second_line() { - var input = + var lines = "The fourth line.\n" + "The fifth line."; var expected = @@ -88,13 +88,13 @@ public void First_line_longer_than_second_line() "ne\n" + "e.\n" + "."; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Second_line_longer_than_first_line() { - var input = + var lines = "The first line.\n" + "The second line."; var expected = @@ -114,13 +114,42 @@ public void Second_line_longer_than_first_line() "en\n" + ".e\n" + " ."; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); + } + + [Fact(Skip = "Remove to run test")] + public void Mixed_line_length() + { + var lines = + "The longest line.\n" + + "A long line.\n" + + "A longer line.\n" + + "A line."; + var expected = + "TAAA\n" + + "h \n" + + "elll\n" + + " ooi\n" + + "lnnn\n" + + "ogge\n" + + "n e.\n" + + "glr\n" + + "ei \n" + + "snl\n" + + "tei\n" + + " .n\n" + + "l e\n" + + "i .\n" + + "n\n" + + "e\n" + + "."; + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Square() { - var input = + var lines = "HEART\n" + "EMBER\n" + "ABUSE\n" + @@ -132,13 +161,13 @@ public void Square() "ABUSE\n" + "RESIN\n" + "TREND"; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Rectangle() { - var input = + var lines = "FRACTURE\n" + "OUTLINED\n" + "BLOOMING\n" + @@ -152,13 +181,13 @@ public void Rectangle() "UNIT\n" + "RENT\n" + "EDGE"; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } [Fact(Skip = "Remove to run test")] public void Triangle() { - var input = + var lines = "T\n" + "EE\n" + "AAA\n" + @@ -172,81 +201,6 @@ public void Triangle() " SER\n" + " ER\n" + " R"; - Assert.Equal(expected, Transpose.String(input)); - } - - [Fact(Skip = "Remove to run test")] - public void Many_lines() - { - var input = - "Chor. Two households, both alike in dignity,\n" + - "In fair Verona, where we lay our scene,\n" + - "From ancient grudge break to new mutiny,\n" + - "Where civil blood makes civil hands unclean.\n" + - "From forth the fatal loins of these two foes\n" + - "A pair of star-cross'd lovers take their life;\n" + - "Whose misadventur'd piteous overthrows\n" + - "Doth with their death bury their parents' strife.\n" + - "The fearful passage of their death-mark'd love,\n" + - "And the continuance of their parents' rage,\n" + - "Which, but their children's end, naught could remove,\n" + - "Is now the two hours' traffic of our stage;\n" + - "The which if you with patient ears attend,\n" + - "What here shall miss, our toil shall strive to mend."; - var expected = - "CIFWFAWDTAWITW\n" + - "hnrhr hohnhshh\n" + - "o oeopotedi ea\n" + - "rfmrmash cn t\n" + - ".a e ie fthow \n" + - " ia fr weh,whh\n" + - "Trnco miae ie\n" + - "w ciroitr btcr\n" + - "oVivtfshfcuhhe\n" + - " eeih a uote \n" + - "hrnl sdtln is\n" + - "oot ttvh tttfh\n" + - "un bhaeepihw a\n" + - "saglernianeoyl\n" + - "e,ro -trsui ol\n" + - "h uofcu sarhu \n" + - "owddarrdan o m\n" + - "lhg to'egccuwi\n" + - "deemasdaeehris\n" + - "sr als t ists\n" + - ",ebk 'phool'h,\n" + - " reldi ffd \n" + - "bweso tb rtpo\n" + - "oea ileutterau\n" + - "t kcnoorhhnatr\n" + - "hl isvuyee'fi \n" + - " atv es iisfet\n" + - "ayoior trr ino\n" + - "l lfsoh ecti\n" + - "ion vedpn l\n" + - "kuehtteieadoe \n" + - "erwaharrar,fas\n" + - " nekt te rh\n" + - "ismdsehphnnosa\n" + - "ncuse ra-tau l\n" + - " et tormsural\n" + - "dniuthwea'g t \n" + - "iennwesnr hsts\n" + - "g,ycoi tkrttet\n" + - "n ,l r s'a anr\n" + - "i ef 'dgcgdi\n" + - "t aol eoe,v\n" + - "y nei sl,u; e\n" + - ", .sf to l \n" + - " e rv d t\n" + - " ; ie o\n" + - " f, r \n" + - " e e m\n" + - " . m e\n" + - " o n\n" + - " v d\n" + - " e .\n" + - " ,"; - Assert.Equal(expected, Transpose.String(input)); + Assert.Equal(expected, Transpose.String(lines)); } } \ No newline at end of file diff --git a/exercises/triangle/TriangleTest.cs b/exercises/triangle/TriangleTest.cs index 3e56ea532a..fee4a183fa 100644 --- a/exercises/triangle/TriangleTest.cs +++ b/exercises/triangle/TriangleTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; diff --git a/exercises/two-bucket/TwoBucketTest.cs b/exercises/two-bucket/TwoBucketTest.cs index bd2d4e8985..bc37231661 100644 --- a/exercises/two-bucket/TwoBucketTest.cs +++ b/exercises/two-bucket/TwoBucketTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.2.0 of the canonical data. +// This file was auto-generated based on version 1.4.0 of the canonical data. using Xunit; diff --git a/exercises/two-fer/TwoFerTest.cs b/exercises/two-fer/TwoFerTest.cs index e37a89f1bd..d503feb1cd 100644 --- a/exercises/two-fer/TwoFerTest.cs +++ b/exercises/two-fer/TwoFerTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; diff --git a/exercises/word-count/Example.cs b/exercises/word-count/Example.cs index 2d1271a657..3ac968879a 100644 --- a/exercises/word-count/Example.cs +++ b/exercises/word-count/Example.cs @@ -4,7 +4,7 @@ public static class WordCount { - public static IDictionary Countwords(string phrase) + public static IDictionary CountWords(string phrase) { if (phrase == null) throw new ArgumentNullException("phrase"); diff --git a/exercises/word-count/WordCount.cs b/exercises/word-count/WordCount.cs index 34131fe8d3..a91ff362de 100644 --- a/exercises/word-count/WordCount.cs +++ b/exercises/word-count/WordCount.cs @@ -3,7 +3,7 @@ public static class WordCount { - public static IDictionary Countwords(string phrase) + public static IDictionary CountWords(string phrase) { throw new NotImplementedException("You need to implement this function."); } diff --git a/exercises/word-count/WordCountTest.cs b/exercises/word-count/WordCountTest.cs index d95b99f2c9..8e592381d5 100644 --- a/exercises/word-count/WordCountTest.cs +++ b/exercises/word-count/WordCountTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.2.0 of the canonical data. using Xunit; using System.Collections.Generic; @@ -8,7 +8,7 @@ public class WordCountTest [Fact] public void Count_one_word() { - var actual = WordCount.Countwords("word"); + var actual = WordCount.CountWords("word"); var expected = new Dictionary { ["word"] = 1 @@ -19,7 +19,7 @@ public void Count_one_word() [Fact(Skip = "Remove to run test")] public void Count_one_of_each_word() { - var actual = WordCount.Countwords("one of each"); + var actual = WordCount.CountWords("one of each"); var expected = new Dictionary { ["one"] = 1, @@ -32,7 +32,7 @@ public void Count_one_of_each_word() [Fact(Skip = "Remove to run test")] public void Multiple_occurrences_of_a_word() { - var actual = WordCount.Countwords("one fish two fish red fish blue fish"); + var actual = WordCount.CountWords("one fish two fish red fish blue fish"); var expected = new Dictionary { ["one"] = 1, @@ -47,7 +47,7 @@ public void Multiple_occurrences_of_a_word() [Fact(Skip = "Remove to run test")] public void Handles_cramped_lists() { - var actual = WordCount.Countwords("one,two,three"); + var actual = WordCount.CountWords("one,two,three"); var expected = new Dictionary { ["one"] = 1, @@ -60,7 +60,7 @@ public void Handles_cramped_lists() [Fact(Skip = "Remove to run test")] public void Handles_expanded_lists() { - var actual = WordCount.Countwords("one,\ntwo,\nthree"); + var actual = WordCount.CountWords("one,\ntwo,\nthree"); var expected = new Dictionary { ["one"] = 1, @@ -73,7 +73,7 @@ public void Handles_expanded_lists() [Fact(Skip = "Remove to run test")] public void Ignore_punctuation() { - var actual = WordCount.Countwords("car: carpet as java: javascript!!&@$%^&"); + var actual = WordCount.CountWords("car: carpet as java: javascript!!&@$%^&"); var expected = new Dictionary { ["car"] = 1, @@ -88,7 +88,7 @@ public void Ignore_punctuation() [Fact(Skip = "Remove to run test")] public void Include_numbers() { - var actual = WordCount.Countwords("testing, 1, 2 testing"); + var actual = WordCount.CountWords("testing, 1, 2 testing"); var expected = new Dictionary { ["testing"] = 2, @@ -101,7 +101,7 @@ public void Include_numbers() [Fact(Skip = "Remove to run test")] public void Normalize_case() { - var actual = WordCount.Countwords("go Go GO Stop stop"); + var actual = WordCount.CountWords("go Go GO Stop stop"); var expected = new Dictionary { ["go"] = 3, @@ -113,7 +113,7 @@ public void Normalize_case() [Fact(Skip = "Remove to run test")] public void With_apostrophes() { - var actual = WordCount.Countwords("First: don't laugh. Then: don't cry."); + var actual = WordCount.CountWords("First: don't laugh. Then: don't cry."); var expected = new Dictionary { ["first"] = 1, @@ -128,7 +128,7 @@ public void With_apostrophes() [Fact(Skip = "Remove to run test")] public void With_quotations() { - var actual = WordCount.Countwords("Joe can't tell between 'large' and large."); + var actual = WordCount.CountWords("Joe can't tell between 'large' and large."); var expected = new Dictionary { ["joe"] = 1, @@ -144,7 +144,7 @@ public void With_quotations() [Fact(Skip = "Remove to run test")] public void Multiple_spaces_not_detected_as_a_word() { - var actual = WordCount.Countwords(" multiple whitespaces"); + var actual = WordCount.CountWords(" multiple whitespaces"); var expected = new Dictionary { ["multiple"] = 1, diff --git a/exercises/wordy/WordyTest.cs b/exercises/wordy/WordyTest.cs index 2b76cab6cf..92adbc262d 100644 --- a/exercises/wordy/WordyTest.cs +++ b/exercises/wordy/WordyTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; using System; diff --git a/exercises/yacht/Example.cs b/exercises/yacht/Example.cs index 822c2d81cd..d33655a7b9 100644 --- a/exercises/yacht/Example.cs +++ b/exercises/yacht/Example.cs @@ -38,11 +38,8 @@ public static int Score(int[] dice, YachtCategory category) //Full House: Three of one number and two of another. Sum of all dice. case YachtCategory.FullHouse: - { - var testHashSet = new HashSet(); - dice.ToList().ForEach(x => testHashSet.Add(x)); - return (testHashSet.Count() == 2) ? dice.Sum() : 0; - } + var diceByValue = dice.ToLookup(x => x); + return diceByValue.Count == 2 && diceByValue.First().Count() == 2 || diceByValue.First().Count() == 3 ? dice.Sum() : 0; //Four-Of-A-Kind: At least four dice showing the same face. Sum of those four dice. case YachtCategory.FourOfAKind: var testDict = new Dictionary(); diff --git a/exercises/yacht/YachtTest.cs b/exercises/yacht/YachtTest.cs index 31144cb4c9..ffeb4dcf3a 100644 --- a/exercises/yacht/YachtTest.cs +++ b/exercises/yacht/YachtTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; @@ -82,6 +82,12 @@ public void Two_pair_is_not_a_full_house() Assert.Equal(0, YachtGame.Score(new[] { 2, 2, 4, 4, 5 }, YachtCategory.FullHouse)); } + [Fact(Skip = "Remove to run test")] + public void Four_of_a_kind_is_not_a_full_house() + { + Assert.Equal(0, YachtGame.Score(new[] { 1, 4, 4, 4, 4 }, YachtCategory.FullHouse)); + } + [Fact(Skip = "Remove to run test")] public void Yacht_is_not_a_full_house() { diff --git a/generators/Exercises/AllYourBase.cs b/generators/Exercises/AllYourBase.cs index bbed5aaa3a..a75393c626 100644 --- a/generators/Exercises/AllYourBase.cs +++ b/generators/Exercises/AllYourBase.cs @@ -10,6 +10,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { + canonicalDataCase.Input["digits"] = ConvertHelper.ToArray(canonicalDataCase.Input["digits"]); canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is Dictionary ? typeof(ArgumentException) : null; canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; diff --git a/generators/Exercises/Alphametics.cs b/generators/Exercises/Alphametics.cs index 319a8a9815..0b4eaf5d9f 100644 --- a/generators/Exercises/Alphametics.cs +++ b/generators/Exercises/Alphametics.cs @@ -21,8 +21,11 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) } } - private static dynamic ConvertExpected(CanonicalDataCase canonicalDataCase) - => ((Dictionary)canonicalDataCase.Expected).ToDictionary(kv => kv.Key[0], kv => int.Parse(kv.Value.ToString())); + private static dynamic ConvertExpected(CanonicalDataCase canonicalDataCase) + { + Dictionary expected = canonicalDataCase.Expected; + return expected.ToDictionary(kv => kv.Key[0], kv => int.Parse(kv.Value.ToString())); + } protected override HashSet AddAdditionalNamespaces() => new HashSet { typeof(Dictionary).Namespace }; } diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index 913bf055c3..8432c65936 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -7,7 +7,10 @@ public class BeerSong : GeneratorExercise protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) + { canonicalDataCase.UseVariableForExpected = true; + canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); + } } } } \ No newline at end of file diff --git a/generators/Exercises/BinarySearch.cs b/generators/Exercises/BinarySearch.cs index a19b98fd5c..6ab3860f86 100644 --- a/generators/Exercises/BinarySearch.cs +++ b/generators/Exercises/BinarySearch.cs @@ -8,6 +8,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { + canonicalDataCase.Input["array"] = ConvertHelper.ToArray(canonicalDataCase.Input["array"]); canonicalDataCase.UseVariablesForConstructorParameters = true; canonicalDataCase.SetConstructorInputParameters("array"); } diff --git a/generators/Exercises/BookStore.cs b/generators/Exercises/BookStore.cs index e3fe8ac022..de874c5aa5 100644 --- a/generators/Exercises/BookStore.cs +++ b/generators/Exercises/BookStore.cs @@ -8,6 +8,8 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { + canonicalDataCase.Expected = canonicalDataCase.Expected / 100.0f; + canonicalDataCase.Input["basket"] = ConvertHelper.ToArray(canonicalDataCase.Input["basket"]); canonicalDataCase.SetInputParameters("basket"); canonicalDataCase.UseVariablesForInput = true; } diff --git a/generators/Exercises/Bowling.cs b/generators/Exercises/Bowling.cs index e9302820ff..2f561f75c7 100644 --- a/generators/Exercises/Bowling.cs +++ b/generators/Exercises/Bowling.cs @@ -8,17 +8,17 @@ namespace Generators.Exercises { public class Bowling : GeneratorExercise { - private const string PreviousRolls = "previous_rolls"; + private const string PreviousRolls = "previousRolls"; protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { - if(!(canonicalDataCase.Expected is long)) + if (!(canonicalDataCase.Expected is int)) { canonicalDataCase.ExceptionThrown = typeof(ArgumentException); } - else + else { canonicalDataCase.UseVariableForTested = true; @@ -32,12 +32,19 @@ protected override string RenderTestMethodBodyArrange(TestMethodBody testMethodB var builder = new StringBuilder(); builder.AppendLine("var sut = new BowlingGame();"); - if (testMethodBody.CanonicalDataCase.Properties.ContainsKey(PreviousRolls)) + if (testMethodBody.CanonicalDataCase.Input.ContainsKey(PreviousRolls)) { - int[] array = testMethodBody.CanonicalDataCase.Properties[PreviousRolls]; - builder.Append("var previousRolls = new int[] {"); + var array = testMethodBody.CanonicalDataCase.Input[PreviousRolls] as int[]; + if (array == null) + { + builder.Append("var previousRolls = new int[0];"); + } + else + { + builder.Append("var previousRolls = new [] { "); builder.AppendJoin(", ", array); - builder.AppendLine("};"); + builder.AppendLine(" };"); + } } return builder.ToString(); @@ -46,21 +53,20 @@ protected override string RenderTestMethodBodyArrange(TestMethodBody testMethodB protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) { var template = string.Empty; - if(testMethodBody.CanonicalDataCase.ExceptionThrown != null && testMethodBody.CanonicalDataCase.Properties.ContainsKey("roll")) + if (testMethodBody.CanonicalDataCase.ExceptionThrown != null && testMethodBody.CanonicalDataCase.Input.ContainsKey("roll")) { template = "Assert.Throws(() => sut.Roll({{RollVal}}));"; var templateParams = new { - RollVal = testMethodBody.CanonicalDataCase.Properties["roll"] + RollVal = testMethodBody.CanonicalDataCase.Input["roll"] }; return TemplateRenderer.RenderInline(template, templateParams); } - else if (testMethodBody.CanonicalDataCase.ExceptionThrown != null && testMethodBody.CanonicalDataCase.Property == "score") + else if (testMethodBody.CanonicalDataCase.ExceptionThrown != null && testMethodBody.CanonicalDataCase.Property == "score") { template = "Assert.Throws(() => sut.Score());"; return template; } - return base.RenderTestMethodBodyAssert(testMethodBody); } @@ -71,12 +77,12 @@ protected override string RenderTestMethodBodyAct(TestMethodBody testMethodBody) @"DoRoll(previousRolls, sut); "; - if(testMethodBody.CanonicalDataCase.ExceptionThrown != null) + if (testMethodBody.CanonicalDataCase.ExceptionThrown != null) { return template; } - if (testMethodBody.CanonicalDataCase.Properties.ContainsKey("roll")) + if (testMethodBody.CanonicalDataCase.Input.ContainsKey("roll")) { template += @"sut.Roll({{RolVal}}); @@ -84,14 +90,13 @@ protected override string RenderTestMethodBodyAct(TestMethodBody testMethodBody) "; var templateParameters = new { - RolVal = testMethodBody.CanonicalDataCase.Properties["roll"] + RolVal = testMethodBody.CanonicalDataCase.Input["roll"] }; return TemplateRenderer.RenderInline(template, templateParameters); } template += "var actual = sut.Score();"; return template; - } protected override string[] RenderAdditionalMethods() diff --git a/generators/Exercises/BracketPush.cs b/generators/Exercises/BracketPush.cs index 52a1221565..086b3c2afa 100644 --- a/generators/Exercises/BracketPush.cs +++ b/generators/Exercises/BracketPush.cs @@ -8,7 +8,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { - canonicalDataCase.Properties["input"]["value"] = canonicalDataCase.Properties["input"]["value"].Replace("\\", "\\\\"); + canonicalDataCase.Input["value"] = canonicalDataCase.Input["value"].Replace("\\", "\\\\"); canonicalDataCase.UseVariablesForInput = true; } } diff --git a/generators/Exercises/Clock.cs b/generators/Exercises/Clock.cs index 0e8dab53d2..79e8f5bf83 100644 --- a/generators/Exercises/Clock.cs +++ b/generators/Exercises/Clock.cs @@ -15,7 +15,6 @@ public class Clock : GeneratorExercise private const string PropertyEqual = "equal"; private const string PropertyEquals = "equals"; private const string PropertyToString = "to_string"; - private const string PropertyEqualityExpectance = "expected"; protected override void UpdateCanonicalData(CanonicalData canonicalData) { @@ -29,8 +28,8 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.SetConstructorInputParameters(ParamClock1); - var result = (Dictionary)canonicalDataCase.Properties[ParamClock2]; - canonicalDataCase.Properties[ParamClock2] = new UnescapedValue($"new Clock({result[ParamHour]}, {result[ParamMinute]})"); + var result = (Dictionary)canonicalDataCase.Input[ParamClock2]; + canonicalDataCase.Input[ParamClock2] = new UnescapedValue($"new Clock({result[ParamHour]}, {result[ParamMinute]})"); } if (canonicalDataCase.Property == PropertyCreate) @@ -71,9 +70,9 @@ private static string RenderEqualToAssert(TestMethodBody testMethodBody) { var ExpectedParameter = testMethodBody.CanonicalDataCase.Input[ParamClock2]; var TestedValue = "sut"; - var expectedEqual = testMethodBody.CanonicalDataCase.Properties[PropertyEqualityExpectance]; + var expectedEqual = testMethodBody.CanonicalDataCase.Expected; - testMethodBody.AssertTemplateParameters = new { ExpectedParameter, TestedValue}; + testMethodBody.AssertTemplateParameters = new { ExpectedParameter, TestedValue }; var template = expectedEqual ? $"Assert.Equal({{{{ ExpectedParameter }}}}, {{{{ TestedValue }}}}); " diff --git a/generators/Exercises/ComplexNumbers.cs b/generators/Exercises/ComplexNumbers.cs index 32b8fc94b6..1be6cbe87a 100644 --- a/generators/Exercises/ComplexNumbers.cs +++ b/generators/Exercises/ComplexNumbers.cs @@ -11,39 +11,28 @@ public class ComplexNumbers : GeneratorExercise { protected override void UpdateCanonicalData(CanonicalData canonicalData) { - // TODO - //canonicalData.Exercise = "complex-number"; - - // Ensure the Real and Imaginary methods are tested first as they're used later to assert equality between complex numbers - // TODO - //canonicalData.Cases = canonicalData.Cases.OrderBy(c => c.Property == "real" || c.Property == "imaginary" ? 0 : 1).ToArray(); + canonicalData.Exercise = "complex-number"; foreach (var canonicalDataCase in canonicalData.Cases) { - // Process expected - if (IsComplexNumber(canonicalDataCase.Expected)) - canonicalDataCase.UseVariableForExpected = true; - + canonicalDataCase.UseVariableForExpected = IsComplexNumber(canonicalDataCase.Expected); canonicalDataCase.Expected = ConvertToType(canonicalDataCase.Expected); - // Process constructor param - var constructorParamName = canonicalDataCase.Input.ContainsKey("input") ? "input" : "z1"; - - canonicalDataCase.Properties["real"] = ConvertMathDouble(canonicalDataCase.Input[constructorParamName][0]); - canonicalDataCase.Properties["imaginary"] = ConvertMathDouble(canonicalDataCase.Input[constructorParamName][1]); + var constructorParamName = canonicalDataCase.Input.ContainsKey("z") ? "z" : "z1"; + canonicalDataCase.Input["real"] = ConvertMathDouble(canonicalDataCase.Input[constructorParamName][0]); + canonicalDataCase.Input["imaginary"] = ConvertMathDouble(canonicalDataCase.Input[constructorParamName][1]); - canonicalDataCase.SetConstructorInputParameters("real", "imaginary"); canonicalDataCase.SetInputParameters(GetInputParameters(canonicalDataCase, constructorParamName)); + canonicalDataCase.SetConstructorInputParameters("real", "imaginary"); - // Process function param var keys = canonicalDataCase.Input.Keys.ToArray(); foreach (var key in keys) - canonicalDataCase.Properties[key] = ConvertToType(canonicalDataCase.Properties[key]); + canonicalDataCase.Input[key] = ConvertToType(canonicalDataCase.Input[key]); } } - private static string[] GetInputParameters(CanonicalDataCase canonicalDataCase, string constructorParamName) + private static string[] GetInputParameters(CanonicalDataCase canonicalDataCase, string constructorParamName) => canonicalDataCase.Input.Keys.Where(x => x != constructorParamName).ToArray(); protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) @@ -84,6 +73,8 @@ private static object ConvertMathDouble(dynamic value) return new UnescapedValue("Math.E"); case "pi": return new UnescapedValue("Math.PI"); + case "ln(2)": + return new UnescapedValue("Math.Log(2.0)"); default: return double.Parse(value.ToString()); } diff --git a/generators/Exercises/Connect.cs b/generators/Exercises/Connect.cs index 4607fc6266..4176151aa0 100644 --- a/generators/Exercises/Connect.cs +++ b/generators/Exercises/Connect.cs @@ -12,19 +12,19 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) canonicalDataCase.UseVariablesForConstructorParameters = true; canonicalDataCase.SetConstructorInputParameters("board"); canonicalDataCase.Property = "result"; - canonicalDataCase.Properties["board"] = ToMultiLineString(canonicalDataCase.Properties["board"]); + canonicalDataCase.Input["board"] = ToMultiLineString(canonicalDataCase.Input["board"]); //convert to enum - switch (canonicalDataCase.Properties["expected"]) + switch (canonicalDataCase.Expected) { case "X": - canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.Black"); + canonicalDataCase.Expected = new UnescapedValue("ConnectWinner.Black"); break; case "O": - canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.White"); + canonicalDataCase.Expected = new UnescapedValue("ConnectWinner.White"); break; case "": - canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.None"); + canonicalDataCase.Expected = new UnescapedValue("ConnectWinner.None"); break; } } @@ -32,7 +32,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) private UnescapedValue ToMultiLineString(string[] input) { - const string template = + const string template = @"new [] { {% if input.size == 0 %}string.Empty{% else %}{% for item in {{input}} %}{% if forloop.length == 1 %}""{{item}}""{% break %}{% endif %}""{{item}}""{% if forloop.last == false %},{% else %}{{string.Empty}}{% endif %} diff --git a/generators/Exercises/Dominoes.cs b/generators/Exercises/Dominoes.cs index d71459d951..2bc4625b67 100644 --- a/generators/Exercises/Dominoes.cs +++ b/generators/Exercises/Dominoes.cs @@ -14,10 +14,10 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) foreach (var canonicalDataCase in canonicalData.Cases) { canonicalDataCase.UseVariablesForInput = true; - canonicalDataCase.Properties["input"] = ConvertInput(canonicalDataCase.Properties["input"]); + canonicalDataCase.Input["dominoes"] = ConvertInput(canonicalDataCase.Input["dominoes"]); } } - + protected override HashSet AddAdditionalNamespaces() => new HashSet() { typeof(Tuple).Namespace }; private UnescapedValue ConvertInput(dynamic input) diff --git a/generators/Exercises/Etl.cs b/generators/Exercises/Etl.cs index b46d15dc5a..5e81377877 100644 --- a/generators/Exercises/Etl.cs +++ b/generators/Exercises/Etl.cs @@ -13,48 +13,20 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; - // Make sure to convert keys to ints as stated in canonical data - canonicalDataCase.Properties["input"] = ConvertInput(canonicalDataCase.Properties["input"]); + canonicalDataCase.Input = ConvertInput(canonicalDataCase.Input); canonicalDataCase.Expected = ConvertExpected(canonicalDataCase.Expected); + canonicalDataCase.SetInputParameters("input"); } } - protected override string RenderTestMethodBodyArrange(TestMethodBody testMethodBody) - { - // The ValueFormatter doesn't handle Dictionary>. Need to format manually. - Dictionary inputDictionary = testMethodBody.CanonicalDataCase.Properties["input"]; - var newInput = FormatMultiLineEnumerable( - inputDictionary.Keys.Select((key, i) => $"[{ValueFormatter.Format(key)}] = {ValueFormatter.Format(inputDictionary[key])}" + (i < inputDictionary.Keys.Count - 1 ? "," : "")), - "input", "new Dictionary>"); - newInput = AddTrailingSemicolon(newInput); - - var arrangeVariables = testMethodBody.Data.Variables.ToList(); - arrangeVariables.RemoveAt(0); - arrangeVariables.InsertRange(0, newInput); - testMethodBody.ArrangeTemplateParameters = new { Variables = arrangeVariables }; - - return base.RenderTestMethodBodyArrange(testMethodBody); - } - private static dynamic ConvertExpected(dynamic expected) => ((Dictionary)expected).ToDictionary(kv => kv.Key, kv => int.Parse($"{kv.Value}")); - private static dynamic ConvertInput(dynamic input) - => ((Dictionary)input).ToDictionary(kv => int.Parse(kv.Key), kv => (string[])kv.Value); - - private static string[] FormatMultiLineEnumerable(IEnumerable enumerable, string name, string constructor = null) - => FormatMultiLineVariable(enumerable.Prepend("{").Append("}"), name, constructor); - - private static string[] FormatMultiLineVariable(IEnumerable enumerable, string name, string constructor = null) - => enumerable.Select(line => line == "{" || line == "}" ? line : line.Indent()) - .Prepend($"var {name} = {constructor}") - .ToArray(); - - private static string[] AddTrailingSemicolon(string[] array) - { - array[array.Length - 1] += ";"; - return array; - } + private static IDictionary ConvertInput(IDictionary input) + => new Dictionary + { + ["input"] = input.ToDictionary(kv => int.Parse(kv.Key), kv => (string[])kv.Value) + }; protected override HashSet AddAdditionalNamespaces() => new HashSet { typeof(Dictionary).Namespace }; } diff --git a/generators/Exercises/FlattenArray.cs b/generators/Exercises/FlattenArray.cs index 956f29ad8f..724d5677d0 100644 --- a/generators/Exercises/FlattenArray.cs +++ b/generators/Exercises/FlattenArray.cs @@ -5,31 +5,27 @@ namespace Generators.Exercises { public class FlattenArray : GeneratorExercise { - protected override void UpdateCanonicalData(CanonicalData canonicalData) + protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; - string stringInput = canonicalDataCase.Properties["input"].ToString(); + var stringInput = canonicalDataCase.Input["array"].ToString(); // We skip reformatting of pure int arrays. - if(stringInput.Contains("System.Int32")) + if (stringInput.Contains("System.Int32")) continue; - string properInput = ToProperObjArray(stringInput); - - canonicalDataCase.Properties["input"] = new UnescapedValue(properInput); + canonicalDataCase.Input["array"] = new UnescapedValue(ToProperObjArray(stringInput)); } } - private string ToProperObjArray(string input) - { - string res = input.Replace("System.Int32", ""); - res = res.Replace("]", "}"); - res = res.Replace("[", "new object[] {"); - return res; - } + private string ToProperObjArray(string input) + => input + .Replace("System.Int32", "") + .Replace("]", "}") + .Replace("[", "new object[] {"); } } \ No newline at end of file diff --git a/generators/Exercises/Gigasecond.cs b/generators/Exercises/Gigasecond.cs index 193aef8e3e..ca61e5d75b 100644 --- a/generators/Exercises/Gigasecond.cs +++ b/generators/Exercises/Gigasecond.cs @@ -11,10 +11,10 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { - var input = DateTime.Parse(canonicalDataCase.Properties["input"].ToString()); - canonicalDataCase.Properties["input"] = new UnescapedValue(FormatDateTime(input)); - - canonicalDataCase.Expected = new UnescapedValue(FormatDateTime((DateTime)canonicalDataCase.Expected)); + var input = DateTime.Parse(canonicalDataCase.Input["birthdate"].ToString()); + canonicalDataCase.Input["birthdate"] = new UnescapedValue(FormatDateTime(input)); + + canonicalDataCase.Expected = new UnescapedValue(FormatDateTime((DateTime)canonicalDataCase.Expected)); } } diff --git a/generators/Exercises/Grains.cs b/generators/Exercises/Grains.cs index d4f7da7bee..b3a4364ce6 100644 --- a/generators/Exercises/Grains.cs +++ b/generators/Exercises/Grains.cs @@ -16,6 +16,6 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) } } - private static bool ShouldThrowException(dynamic value) => value == -1; + private static bool ShouldThrowException(dynamic value) => value is int i && i == -1; } } \ No newline at end of file diff --git a/generators/Exercises/Hamming.cs b/generators/Exercises/Hamming.cs index 85913021af..2d6c7ed1e2 100644 --- a/generators/Exercises/Hamming.cs +++ b/generators/Exercises/Hamming.cs @@ -8,7 +8,7 @@ public class Hamming : GeneratorExercise protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) - canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is long ? null : typeof(ArgumentException); + canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is int ? null : typeof(ArgumentException); } } } diff --git a/generators/Exercises/KindergartenGarden.cs b/generators/Exercises/KindergartenGarden.cs index 0c98a8ed4c..c00a6507b1 100644 --- a/generators/Exercises/KindergartenGarden.cs +++ b/generators/Exercises/KindergartenGarden.cs @@ -15,13 +15,13 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) canonicalDataCase.TestedMethodType = TestedMethodType.Instance; canonicalDataCase.UseFullDescriptionPath = true; - if (canonicalDataCase.Properties.ContainsKey("students")) + if (canonicalDataCase.Input.ContainsKey("students")) canonicalDataCase.SetConstructorInputParameters("diagram", "students"); else canonicalDataCase.SetConstructorInputParameters("diagram"); - var plants = (IEnumerable)canonicalDataCase.Properties["expected"]; - canonicalDataCase.Properties["expected"] = plants + var plants = (IEnumerable)canonicalDataCase.Expected; + canonicalDataCase.Expected = plants .Select(x => new UnescapedValue($"Plant.{x.Humanize()}")) .ToArray(); } diff --git a/generators/Exercises/Meetup.cs b/generators/Exercises/Meetup.cs index 839dcc9463..76b063a5f5 100644 --- a/generators/Exercises/Meetup.cs +++ b/generators/Exercises/Meetup.cs @@ -24,12 +24,12 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) canonicalDataCase.SetConstructorInputParameters(ParamMonth, ParamYear); canonicalDataCase.SetInputParameters(ParamDayOfWeek, ParamWeek); - canonicalDataCase.Properties[ParamYear] = canonicalDataCase.Properties["input"][ParamYear]; - canonicalDataCase.Properties[ParamMonth] = canonicalDataCase.Properties["input"][ParamMonth]; - canonicalDataCase.Properties[ParamWeek] = - new UnescapedValue($"Schedule.{((string)canonicalDataCase.Properties["input"][ParamWeek]).Transform(To.SentenceCase)}"); - canonicalDataCase.Properties[ParamDayOfWeek] = - new UnescapedValue($"DayOfWeek.{((string)canonicalDataCase.Properties["input"][ParamDayOfWeek]).Transform(To.SentenceCase)}"); + canonicalDataCase.Input[ParamYear] = canonicalDataCase.Input[ParamYear]; + canonicalDataCase.Input[ParamMonth] = canonicalDataCase.Input[ParamMonth]; + canonicalDataCase.Input[ParamWeek] = + new UnescapedValue($"Schedule.{((string)canonicalDataCase.Input[ParamWeek]).Transform(To.SentenceCase)}"); + canonicalDataCase.Input[ParamDayOfWeek] = + new UnescapedValue($"DayOfWeek.{((string)canonicalDataCase.Input[ParamDayOfWeek]).Transform(To.SentenceCase)}"); } } diff --git a/generators/Exercises/Minesweeper.cs b/generators/Exercises/Minesweeper.cs index fbf25add0b..64ee61e5ce 100644 --- a/generators/Exercises/Minesweeper.cs +++ b/generators/Exercises/Minesweeper.cs @@ -1,5 +1,8 @@ +using System; +using System.Collections.Generic; using Generators.Input; using Generators.Output; +using Newtonsoft.Json.Linq; namespace Generators.Exercises { @@ -12,14 +15,19 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; - canonicalDataCase.Properties["input"] = ToMultiLineString(canonicalDataCase.Properties["input"]); - canonicalDataCase.Properties["expected"] = ToMultiLineString(canonicalDataCase.Properties["expected"]); + canonicalDataCase.Input["minefield"] = ToMultiLineString(canonicalDataCase.Input["minefield"]); + canonicalDataCase.Expected = ToMultiLineString(canonicalDataCase.Expected); } } - private UnescapedValue ToMultiLineString(string[] input) + private UnescapedValue ToMultiLineString(JArray input) { - const string template = + return new UnescapedValue("new string[0]"); + } + + private UnescapedValue ToMultiLineString(IEnumerable input) + { + const string template = @"new string[] { {% if input.size > 0 %}{% for item in {{input}} %}{% if forloop.length == 1 %}""{{item}}""{% break %}{% endif %}""{{item}}""{% if forloop.last == false %},{% else %}{{string.Empty}}{% endif %} @@ -28,5 +36,7 @@ private UnescapedValue ToMultiLineString(string[] input) return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input })); } + + protected override HashSet AddAdditionalNamespaces() => new HashSet { typeof(Array).Namespace }; } } diff --git a/generators/Exercises/OcrNumbers.cs b/generators/Exercises/OcrNumbers.cs index 5259f5722b..2f6d36ee8f 100644 --- a/generators/Exercises/OcrNumbers.cs +++ b/generators/Exercises/OcrNumbers.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using Generators.Input; using Generators.Output; +using Newtonsoft.Json.Linq; namespace Generators.Exercises { @@ -10,14 +12,19 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { - canonicalDataCase.ExceptionThrown = (canonicalDataCase.Expected is long && canonicalDataCase.Expected <= 0) ? typeof(ArgumentException) : null; - canonicalDataCase.Properties["input"] = ToDigitStringRepresentation(canonicalDataCase.Properties["input"]); + canonicalDataCase.ExceptionThrown = (canonicalDataCase.Expected is int && canonicalDataCase.Expected <= 0) ? typeof(ArgumentException) : null; + canonicalDataCase.Input["rows"] = ToDigitStringRepresentation(canonicalDataCase.Input["rows"]); canonicalDataCase.Expected = canonicalDataCase.Expected.ToString(); canonicalDataCase.UseVariableForTested = true; canonicalDataCase.UseVariablesForInput = true; } } - + + private UnescapedValue ToMultiLineString(JArray input) + { + return new UnescapedValue("Array.Empty()"); + } + private UnescapedValue ToDigitStringRepresentation(string[] input) { const string template = @" {% for item in {{input}} %}{% if forloop.first == true %}""{{item}}"" + ""\n"" +{% continue %}{% endif %} @@ -25,5 +32,7 @@ private UnescapedValue ToDigitStringRepresentation(string[] input) return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input })); } + + protected override HashSet AddAdditionalNamespaces() => new HashSet { typeof(Array).Namespace }; } } diff --git a/generators/Exercises/PascalsTriangle.cs b/generators/Exercises/PascalsTriangle.cs index efc77083ec..3b573694cf 100644 --- a/generators/Exercises/PascalsTriangle.cs +++ b/generators/Exercises/PascalsTriangle.cs @@ -9,20 +9,12 @@ public class PascalsTriangle : GeneratorExercise { protected override void UpdateCanonicalData(CanonicalData canonicalData) { - //remove null case until canonical data is updated - var cases = canonicalData.Cases.ToList(); - cases.RemoveAll(x => x.Properties["count"] == null); - // TODO - //canonicalData.Cases = cases.ToArray(); - foreach (var canonicalDataCase in canonicalData.Cases) { canonicalDataCase.UseVariableForExpected = true; canonicalDataCase.Property = "calculate"; if (!(canonicalDataCase.Expected is JArray)) canonicalDataCase.ExceptionThrown = typeof(ArgumentOutOfRangeException); - if (canonicalDataCase.Properties["count"] == null) - canonicalDataCase.Properties["count"] = -1; } } } diff --git a/generators/Exercises/QueenAttack.cs b/generators/Exercises/QueenAttack.cs index 817ad0aa38..0e4b288669 100644 --- a/generators/Exercises/QueenAttack.cs +++ b/generators/Exercises/QueenAttack.cs @@ -65,9 +65,9 @@ private static void SetCreatePropertyData(CanonicalDataCase canonicalDataCase) canonicalDataCase.Description = validExpected ? canonicalDataCase.Description + " does not throw exception" : canonicalDataCase.Description; var coordinates = GetCoordinatesFromPosition(canonicalDataCase.Input["queen"]); - canonicalDataCase.Properties["X"] = coordinates.Item1; - canonicalDataCase.Properties["Y"] = coordinates.Item2; - + canonicalDataCase.Input["X"] = coordinates.Item1; + canonicalDataCase.Input["Y"] = coordinates.Item2; + canonicalDataCase.SetInputParameters("X", "Y"); } } diff --git a/generators/Exercises/RobotSimulator.cs b/generators/Exercises/RobotSimulator.cs index fc9407316a..ea226e9175 100644 --- a/generators/Exercises/RobotSimulator.cs +++ b/generators/Exercises/RobotSimulator.cs @@ -16,11 +16,11 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) foreach (var canonicalDataCase in canonicalData.Cases) { - var positionVal = new UnescapedValue(GetCoordinateInstance(canonicalDataCase.Input["input"][position])); - var directionVal = new UnescapedValue(GetDirectionEnum(canonicalDataCase.Input["input"][direction])); + var positionVal = new UnescapedValue(GetCoordinateInstance(canonicalDataCase.Input[position])); + var directionVal = new UnescapedValue(GetDirectionEnum(canonicalDataCase.Input[direction])); - canonicalDataCase.Properties[direction] = directionVal; - canonicalDataCase.Properties[coordinate] = positionVal; + canonicalDataCase.Input[direction] = directionVal; + canonicalDataCase.Input[coordinate] = positionVal; canonicalDataCase.SetConstructorInputParameters(direction, coordinate); @@ -65,7 +65,7 @@ private string RenderInstructionsMethodBodyAct(TestMethodBody testMethodBody) var templateParameters = new { MethodInvocation = "Simulate", - Instructions = testMethodBody.CanonicalDataCase.Properties["input"]["instructions"] + Instructions = testMethodBody.CanonicalDataCase.Input["instructions"] }; return TemplateRenderer.RenderInline(template, templateParameters); @@ -92,7 +92,7 @@ protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBo { Direction = !string.IsNullOrEmpty(direction) ? GetDirectionEnum(direction) : null, X = position?["x"], - Y = position?["y"] + Y = position?["y"] }; return TemplateRenderer.RenderInline(template.ToString(), templateParameters); diff --git a/generators/Exercises/SaddlePoints.cs b/generators/Exercises/SaddlePoints.cs index c7e8b17e54..3c76d335a4 100644 --- a/generators/Exercises/SaddlePoints.cs +++ b/generators/Exercises/SaddlePoints.cs @@ -13,13 +13,13 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.TestedMethodType = TestedMethodType.Instance; canonicalDataCase.Property = "Calculate"; - canonicalDataCase.SetConstructorInputParameters("input"); + canonicalDataCase.SetConstructorInputParameters("matrix"); canonicalDataCase.UseVariablesForConstructorParameters = true; canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForTested = true; canonicalDataCase.UseVariableForExpected = true; - canonicalDataCase.Properties["input"] = (canonicalDataCase.Properties["input"] as JArray).ToObject(); + canonicalDataCase.Input["matrix"] = (canonicalDataCase.Input["matrix"] as JArray).ToObject(); var array = canonicalDataCase.Expected as Array; diff --git a/generators/Exercises/Say.cs b/generators/Exercises/Say.cs index a9ae22baaf..568bc0ca1a 100644 --- a/generators/Exercises/Say.cs +++ b/generators/Exercises/Say.cs @@ -10,7 +10,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) foreach (var canonicalDataCase in canonicalData.Cases) { canonicalDataCase.Property = "InEnglish"; - canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is long ? typeof(ArgumentOutOfRangeException) : null; + canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is int ? typeof(ArgumentOutOfRangeException) : null; } } } diff --git a/generators/Exercises/Sublist.cs b/generators/Exercises/Sublist.cs index f39075876b..39683c6714 100644 --- a/generators/Exercises/Sublist.cs +++ b/generators/Exercises/Sublist.cs @@ -18,13 +18,12 @@ private UnescapedValue InputValues(int[] list) protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) - { - var input = canonicalDataCase.Properties["input"] as Dictionary; - input["listOne"] = InputValues(input["listOne"] as int[]); - input["listTwo"] = InputValues(input["listTwo"] as int[]); + { + canonicalDataCase.Input["listOne"] = InputValues(canonicalDataCase.Input["listOne"] as int[]); + canonicalDataCase.Input["listTwo"] = InputValues(canonicalDataCase.Input["listTwo"] as int[]); canonicalDataCase.Property = "classify"; - canonicalDataCase.Properties["expected"] = new UnescapedValue($"SublistType.{(canonicalDataCase.Properties["expected"] as string).Dehumanize()}"); + canonicalDataCase.Expected = new UnescapedValue($"SublistType.{(canonicalDataCase.Expected as string).Dehumanize()}"); } } } diff --git a/generators/Exercises/SumOfMultiples.cs b/generators/Exercises/SumOfMultiples.cs index 89c64eb93f..1d4f4ef797 100644 --- a/generators/Exercises/SumOfMultiples.cs +++ b/generators/Exercises/SumOfMultiples.cs @@ -1,6 +1,15 @@ -namespace Generators.Exercises +using Generators.Input; + +namespace Generators.Exercises { public class SumOfMultiples : GeneratorExercise { + protected override void UpdateCanonicalData(CanonicalData canonicalData) + { + foreach (var canonicalDataCase in canonicalData.Cases) + { + canonicalDataCase.Input["factors"] = ConvertHelper.ToArray(canonicalDataCase.Input["factors"]); + } + } } } \ No newline at end of file diff --git a/generators/Exercises/Tournament.cs b/generators/Exercises/Tournament.cs index c9f2d82a69..a6f49a7e1d 100644 --- a/generators/Exercises/Tournament.cs +++ b/generators/Exercises/Tournament.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Generators.Input; using Generators.Output; +using Newtonsoft.Json.Linq; namespace Generators.Exercises { @@ -10,11 +12,12 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { + canonicalDataCase.Property = "RunTally"; canonicalDataCase.TestedMethodType = TestedMethodType.Static; canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; - canonicalDataCase.Properties["input"] = ToMultiLineString(canonicalDataCase.Properties["input"]); - canonicalDataCase.Expected = ToMultiLineString(canonicalDataCase.Expected); + canonicalDataCase.Input["rows"] = ConvertHelper.ToMultiLineString(canonicalDataCase.Input["rows"], ""); + canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); } } @@ -22,6 +25,7 @@ protected override HashSet AddAdditionalNamespaces() { return new HashSet { + typeof(Array).Namespace, typeof(System.String).Namespace, typeof(System.IO.Stream).Namespace, typeof(System.Text.UTF8Encoding).Namespace @@ -30,18 +34,10 @@ protected override HashSet AddAdditionalNamespaces() protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) { - string template = @"Assert.Equal(expected, RunTally(input).Trim());"; + string template = @"Assert.Equal(expected, RunTally(rows));"; return TemplateRenderer.RenderInline(template, new { }); } - private UnescapedValue ToMultiLineString(string[] input) - { - const string template = @"{% if input.size == 0 %}string.Empty{% else %}{% for item in {{input}} %}{% if forloop.length == 1 %}""{{item}}""{% break %}{% endif %}""{{item}}""{% if forloop.last == false %} + Environment.NewLine +{% endif %} - {% endfor %}.Trim(){% endif %}"; - - return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input })); - } - protected override string[] RenderAdditionalMethods() { var methods = @" @@ -50,17 +46,13 @@ private string RunTally(string input) var encoding = new UTF8Encoding(); using (var inStream = new MemoryStream(encoding.GetBytes(input))) + using (var outStream = new MemoryStream()) { - using (var outStream = new MemoryStream()) - { - Tournament.Tally(inStream, outStream); - return encoding.GetString(outStream.ToArray()); - } + Tournament.Tally(inStream, outStream); + return encoding.GetString(outStream.ToArray()); } }"; return methods.Split("", System.StringSplitOptions.None); } - - } } diff --git a/generators/Exercises/Transpose.cs b/generators/Exercises/Transpose.cs index 40edf8dd06..166d326659 100644 --- a/generators/Exercises/Transpose.cs +++ b/generators/Exercises/Transpose.cs @@ -9,8 +9,8 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) foreach (var canonicalDataCase in canonicalData.Cases) { canonicalDataCase.Property = "String"; - canonicalDataCase.Properties["input"] = ConvertHelper.ToMultiLineString(canonicalDataCase.Properties["input"]); - canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); + canonicalDataCase.Input["lines"] = ConvertHelper.ToMultiLineString(canonicalDataCase.Input["lines"], ""); + canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected, ""); canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; diff --git a/generators/Exercises/Triangle.cs b/generators/Exercises/Triangle.cs index 92b2551499..24c2d34ef8 100644 --- a/generators/Exercises/Triangle.cs +++ b/generators/Exercises/Triangle.cs @@ -16,7 +16,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) else if (data.Property == "scalene") data.Property = "IsScalene"; - data.Properties["sides"] = SplitArrayToValues(data.Properties["sides"]); + data.Input["sides"] = SplitArrayToValues(data.Input["sides"]); data.SetInputParameters("sides"); data.UseFullDescriptionPath = true; @@ -29,7 +29,5 @@ private UnescapedValue SplitArrayToValues(IEnumerable input) return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input })); } - - } } \ No newline at end of file diff --git a/generators/Exercises/TwelveDays.cs b/generators/Exercises/TwelveDays.cs index ff2042088e..63c9e10c3e 100644 --- a/generators/Exercises/TwelveDays.cs +++ b/generators/Exercises/TwelveDays.cs @@ -16,11 +16,9 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.UseVariableForExpected = true; canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); - var properties = canonicalDataCase.Properties as Dictionary; - var input = properties["input"] as Dictionary; - if ((long)input["startVerse"] == (long)input["endVerse"]) + if ((int)canonicalDataCase.Input["startVerse"] == (int)canonicalDataCase.Input["endVerse"]) { - properties["input"] = input["startVerse"]; + canonicalDataCase.SetInputParameters("startVerse"); } } } diff --git a/generators/Exercises/TwoBucket.cs b/generators/Exercises/TwoBucket.cs index 2a0889183a..ef3cc54341 100644 --- a/generators/Exercises/TwoBucket.cs +++ b/generators/Exercises/TwoBucket.cs @@ -10,10 +10,10 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) foreach (var canonicalDataCase in canonicalData.Cases) { canonicalDataCase.TestedMethodType = TestedMethodType.Instance; - canonicalDataCase.SetConstructorInputParameters("bucket_one", "bucket_two", "start_bucket"); + canonicalDataCase.SetConstructorInputParameters("bucketOne", "bucketTwo", "startBucket"); - var start_bucket = canonicalDataCase.Properties["start_bucket"]; - canonicalDataCase.Properties["start_bucket"] = new UnescapedValue(start_bucket == "two" ? "Bucket.Two" : "Bucket.One"); + var startBucket = canonicalDataCase.Input["startBucket"]; + canonicalDataCase.Input["startBucket"] = new UnescapedValue(startBucket == "two" ? "Bucket.Two" : "Bucket.One"); } } @@ -39,8 +39,8 @@ protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBo var templateParameters = new { MovesExpected = testMethodBody.CanonicalDataCase.Expected["moves"], - OtherBucketExpected = testMethodBody.CanonicalDataCase.Expected["other_bucket"], - GoalBucketExpected = testMethodBody.CanonicalDataCase.Expected["goal_bucket"], + OtherBucketExpected = testMethodBody.CanonicalDataCase.Expected["otherBucket"], + GoalBucketExpected = testMethodBody.CanonicalDataCase.Expected["goalBucket"], }; return TemplateRenderer.RenderInline(template, templateParameters); diff --git a/generators/Exercises/TwoFer.cs b/generators/Exercises/TwoFer.cs index 2fb6377d20..35c7a86954 100644 --- a/generators/Exercises/TwoFer.cs +++ b/generators/Exercises/TwoFer.cs @@ -1,6 +1,15 @@ -namespace Generators.Exercises +using Generators.Input; + +namespace Generators.Exercises { public class TwoFer : GeneratorExercise { + protected override void UpdateCanonicalData(CanonicalData canonicalData) + { + foreach (var canonicalDataCase in canonicalData.Cases) + { + canonicalDataCase.Property = "Name"; + } + } } -} +} \ No newline at end of file diff --git a/generators/Exercises/Yacht.cs b/generators/Exercises/Yacht.cs index 014745efc9..f79a37c95a 100644 --- a/generators/Exercises/Yacht.cs +++ b/generators/Exercises/Yacht.cs @@ -5,17 +5,17 @@ namespace Generators.Exercises { - public class Yacht: GeneratorExercise + public class Yacht : GeneratorExercise { - protected override void UpdateCanonicalData(CanonicalData canonicalData) - { - // TODO - //canonicalData.Exercise = "yacht-game"; - foreach (var canonicalDataCase in canonicalData.Cases) - { - var input = canonicalDataCase.Properties["input"] as System.Collections.Generic.Dictionary; - input["category"] = new UnescapedValue($"YachtCategory.{input["category"].ToString().Dehumanize()}"); - } - } + protected override void UpdateCanonicalData(CanonicalData canonicalData) + { + canonicalData.Exercise = "yacht-game"; + foreach (var canonicalDataCase in canonicalData.Cases) + { + var category = canonicalDataCase.Input["category"].ToString(); + var formattedCategory = StringDehumanizeExtensions.Dehumanize(category); + canonicalDataCase.Input["category"] = new UnescapedValue($"YachtCategory.{formattedCategory}"); + } + } } } diff --git a/generators/Input/CanonicalData.cs b/generators/Input/CanonicalData.cs index fda4ceed73..1359c97859 100644 --- a/generators/Input/CanonicalData.cs +++ b/generators/Input/CanonicalData.cs @@ -5,7 +5,7 @@ public class CanonicalData public CanonicalData(string exercise, string version, CanonicalDataCase[] cases) => (Exercise, Version, Cases) = (exercise, version, cases); - public string Exercise { get; } + public string Exercise { get; set; } public string Version { get; } diff --git a/generators/Input/CanonicalDataCase.cs b/generators/Input/CanonicalDataCase.cs index a46d96ee37..1c1b4e243f 100644 --- a/generators/Input/CanonicalDataCase.cs +++ b/generators/Input/CanonicalDataCase.cs @@ -2,84 +2,47 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Newtonsoft.Json; namespace Generators.Input { - [JsonConverter(typeof(CanonicalDataCaseParser))] public class CanonicalDataCase { - private readonly HashSet _inputParameters = new HashSet(); - private readonly HashSet _constructorInputParameters = new HashSet(); + public IDictionary Properties { get; set; } + public IDictionary Input { get; set; } + public dynamic Expected { get; set; } - [Required] public string Property { get; set; } - - [Required] public string Description { get; set; } - - [JsonIgnore] public string[] DescriptionPath { get; set; } - [JsonIgnore] - public IDictionary Input { get; set; } - - [JsonIgnore] - public IDictionary ConstructorInput { get; set; } - - [JsonIgnore] - public IDictionary Properties { get; set; } - - [JsonIgnore] - public dynamic Expected { get; set; } - - [JsonIgnore] public bool UseVariablesForInput { get; set; } - - [JsonIgnore] public bool UseVariableForExpected { get; set; } - - [JsonIgnore] public bool UseVariablesForConstructorParameters { get; set; } - - [JsonIgnore] public bool UseVariableForTested { get; set; } - - [JsonIgnore] public bool UseFullDescriptionPath { get; set; } - [JsonIgnore] public TestedMethodType TestedMethodType { get; set; } - - [JsonIgnore] public Type ExceptionThrown { get; set; } + public HashSet InputParameters { get; } = new HashSet(); + public HashSet ConstructorInputParameters { get; } = new HashSet(); + public void SetInputParameters(params string[] properties) { - _inputParameters.Clear(); - _inputParameters.UnionWith(properties); + InputParameters.Clear(); + InputParameters.UnionWith(properties); - _constructorInputParameters.ExceptWith(properties); - - UpdateInput(); + ConstructorInputParameters.ExceptWith(properties); } public void SetConstructorInputParameters(params string[] properties) { - _constructorInputParameters.Clear(); - _constructorInputParameters.UnionWith(properties); - - _inputParameters.ExceptWith(properties); - - TestedMethodType = TestedMethodType.Instance; + ConstructorInputParameters.Clear(); + ConstructorInputParameters.UnionWith(properties); - UpdateInput(); - } + InputParameters.ExceptWith(properties); - private void UpdateInput() - { - ConstructorInput = _constructorInputParameters.ToDictionary(parameter => parameter, parameter => Input[parameter]); - Input = _inputParameters.ToDictionary(parameter => parameter, parameter => Input[parameter]); + TestedMethodType = TestedMethodType.Instance; } } } \ No newline at end of file diff --git a/generators/Input/CanonicalDataCaseParser.cs b/generators/Input/CanonicalDataCaseParser.cs index 1a7f05c392..9452347c82 100644 --- a/generators/Input/CanonicalDataCaseParser.cs +++ b/generators/Input/CanonicalDataCaseParser.cs @@ -9,23 +9,24 @@ public static class CanonicalDataCaseParser { private const string TokensPath = "$..*[?(@.property)]"; - public static CanonicalDataCase[] Parse(JArray canonicalDataCasesJArray) + public static CanonicalDataCase[] Parse(JArray canonicalDataCasesJArray) => canonicalDataCasesJArray .SelectTokens(TokensPath) .Select(Parse) .ToArray(); - public static CanonicalDataCase Parse(JToken canonicalDataCaseJToken) + private static CanonicalDataCase Parse(JToken canonicalDataCaseJToken) { - var canonicalDataCase = new CanonicalDataCase(); - - canonicalDataCase.Property = canonicalDataCaseJToken.Value("property"); - canonicalDataCase.Description = canonicalDataCaseJToken.Value("description"); - canonicalDataCase.Properties = ToDictionary(canonicalDataCaseJToken); - canonicalDataCase.Expected = ConvertJToken(canonicalDataCaseJToken["expected"]); - canonicalDataCase.Input = ToDictionary(canonicalDataCaseJToken["input"]); - canonicalDataCase.ConstructorInput = new Dictionary(); - canonicalDataCase.DescriptionPath = GetDescriptionPath(canonicalDataCaseJToken); + var canonicalDataCase = new CanonicalDataCase + { + Property = canonicalDataCaseJToken.Value("property"), + Properties = ToDictionary(canonicalDataCaseJToken), + Input = ToDictionary(canonicalDataCaseJToken["input"]), + Expected = ConvertJToken(canonicalDataCaseJToken["expected"]), + Description = canonicalDataCaseJToken.Value("description"), + DescriptionPath = GetDescriptionPath(canonicalDataCaseJToken) + }; + canonicalDataCase.SetInputParameters(canonicalDataCase.Input.Keys.ToArray()); return canonicalDataCase; } @@ -44,7 +45,7 @@ private static string[] GetDescriptionPath(JToken canonicalDataCaseToken) break; descriptionPath.Push(description.ToObject()); - } + } currentToken = currentToken.Parent; } @@ -52,12 +53,12 @@ private static string[] GetDescriptionPath(JToken canonicalDataCaseToken) return descriptionPath.Where(x => !string.IsNullOrEmpty(x)).ToArray(); } - public static IDictionary ToDictionary(JToken jToken) => ConvertJToken(jToken); + private static IDictionary ToDictionary(JToken jToken) => ConvertJToken(jToken); - public static dynamic ConvertJToken(JToken jToken) + private static dynamic ConvertJToken(JToken jToken) { switch (jToken?.Type) - { + { case JTokenType.Object: return ConvertJObject((JObject)jToken); case JTokenType.Array: @@ -65,7 +66,7 @@ public static dynamic ConvertJToken(JToken jToken) case JTokenType.Property: return jToken.ToObject>(); case JTokenType.Integer: - return jToken.ToObject(); + return ConvertIntegerJToken(jToken); case JTokenType.Float: return jToken.ToObject(); case JTokenType.String: @@ -96,7 +97,8 @@ private static dynamic ConvertJObject(JObject jObject) for (var i = 0; i < properties.Count; i++) { var key = properties.Keys.ElementAt(i); - properties[key] = ConvertJToken(properties[key]); + var value = properties[key]; + properties[key] = value is JToken jToken ? ConvertJToken(jToken) : value; } return properties; @@ -117,7 +119,17 @@ private static dynamic ConvertJArray(JArray jArray) case JTokenType.Object: return jArray.Select(ConvertJToken).ToArray(); case JTokenType.Integer: - return jArray.ToObject(); + var strings = jArray.ToObject(); + if (strings.All(str => int.TryParse(str, out var _))) + return jArray.ToObject(); + + if (strings.All(str => long.TryParse(str, out var _))) + return jArray.ToObject(); + + if (strings.All(str => ulong.TryParse(str, out var _))) + return jArray.ToObject(); + + return strings; case JTokenType.Float: return jArray.ToObject(); case JTokenType.String: @@ -138,5 +150,21 @@ private static dynamic ConvertJArray(JArray jArray) return jArray; } } + + private static dynamic ConvertIntegerJToken(JToken jToken) + { + var str = jToken.ToObject(); + + if (int.TryParse(str, out var i)) + return i; + + if (long.TryParse(str, out var l)) + return l; + + if (ulong.TryParse(str, out var ul)) + return ul; + + return str; + } } } diff --git a/generators/Input/CanonicalDataParser.cs b/generators/Input/CanonicalDataParser.cs index dc93625d62..4229b7471e 100644 --- a/generators/Input/CanonicalDataParser.cs +++ b/generators/Input/CanonicalDataParser.cs @@ -4,8 +4,6 @@ namespace Generators.Input { public class CanonicalDataParser { - private const string TokensPath = "$..*[?(@.property)]"; - private readonly CanonicalDataFile _canonicalDataFile; public CanonicalDataParser(CanonicalDataFile canonicalDataFile) => _canonicalDataFile = canonicalDataFile; @@ -22,9 +20,9 @@ public CanonicalData Parse(string exercise) return new CanonicalData(name, version, canonicalDataCases); } - private static string ParseName(JObject canonicalDataJObject) => canonicalDataJObject.Value("exercise"); + private static string ParseName(JToken canonicalDataJObject) => canonicalDataJObject.Value("exercise"); - private static string ParseVersion(JObject canonicalDataJObject) => canonicalDataJObject.Value("version"); + private static string ParseVersion(JToken canonicalDataJObject) => canonicalDataJObject.Value("version"); private static CanonicalDataCase[] ParseCanonicalDataCases(JObject canonicalDataJObject) => CanonicalDataCaseParser.Parse((JArray)canonicalDataJObject["cases"]); } diff --git a/generators/Input/ConvertHelper.cs b/generators/Input/ConvertHelper.cs index 1f86da64e8..81b0c66216 100644 --- a/generators/Input/ConvertHelper.cs +++ b/generators/Input/ConvertHelper.cs @@ -3,5 +3,25 @@ public static class ConvertHelper { public static string ToMultiLineString(this object obj) => string.Join("\n", obj as object[]); + + public static string ToMultiLineString(this object obj, string empty) + { + var arr = obj as object[]; + + if (arr == null || arr.Length == 0) + return empty; + + return string.Join("\n", obj as object[]); + } + + public static T[] ToArray(this object obj) + { + var arr = obj as T[]; + + if (arr == null || arr.Length == 0) + return new T[0]; + + return arr; + } } } \ No newline at end of file diff --git a/generators/Output/TestMethodBodyData.cs b/generators/Output/TestMethodBodyData.cs index 588cc6ae1e..5591cd71f8 100644 --- a/generators/Output/TestMethodBodyData.cs +++ b/generators/Output/TestMethodBodyData.cs @@ -13,15 +13,12 @@ public class TestMethodBodyData private readonly TestMethodBody _testMethodBody; - public TestMethodBodyData(TestMethodBody testMethodBody) - { - _testMethodBody = testMethodBody; - } + public TestMethodBodyData(TestMethodBody testMethodBody) => _testMethodBody = testMethodBody; - public object TestedValue => _testMethodBody.UseVariableForTested ? TestedVariableName : TestedMethodInvocation; - public object InputParameters => _testMethodBody.UseVariablesForInput ? string.Join(", ", CanonicalDataCase.Input.Keys.Select(key => key.ToVariableName())) : Input; - public object ExpectedParameter => _testMethodBody.UseVariableForExpected ? ExpectedVariableName : Expected; - public object ConstructorParameters => _testMethodBody.UseVariablesForConstructorParameters ? string.Join(", ", CanonicalDataCase.ConstructorInput.Keys.Select(key => key.ToVariableName())) : ConstructorInput; + public string TestedValue => _testMethodBody.UseVariableForTested ? TestedVariableName : TestedMethodInvocation; + public string InputParameters => _testMethodBody.UseVariablesForInput ? string.Join(", ", CanonicalDataCase.InputParameters.Select(key => key.ToVariableName())) : ValueFormatter.Format(Input); + public string ExpectedParameter => _testMethodBody.UseVariableForExpected ? ExpectedVariableName : ValueFormatter.Format(CanonicalDataCase.Expected); + public string ConstructorParameters => _testMethodBody.UseVariablesForConstructorParameters ? string.Join(", ", CanonicalDataCase.ConstructorInputParameters.Select(key => key.ToVariableName())) : ValueFormatter.Format(ConstructorInput); private CanonicalDataCase CanonicalDataCase => _testMethodBody.CanonicalDataCase; private CanonicalData CanonicalData => _testMethodBody.CanonicalData; @@ -29,13 +26,13 @@ public TestMethodBodyData(TestMethodBody testMethodBody) private string TestedClassName => CanonicalData.Exercise.ToTestedClassName(); private string TestedMethodName => CanonicalDataCase.Property.ToTestedMethodName(); - private object Input => ValueFormatter.Format(CanonicalDataCase.Input); - private object Expected => ValueFormatter.Format(CanonicalDataCase.Expected); - private object ConstructorInput => ValueFormatter.Format(CanonicalDataCase.ConstructorInput); + private IDictionary Input => CanonicalDataCase.InputParameters.ToDictionary(key => key, key => CanonicalDataCase.Input[key]); + private IDictionary ConstructorInput => CanonicalDataCase.ConstructorInputParameters.ToDictionary(key => key, key => CanonicalDataCase.Input[key]); + private object Expected => CanonicalDataCase.Expected; - private IEnumerable InputVariablesDeclaration => ValueFormatter.FormatVariables(CanonicalDataCase.Input); - private IEnumerable ExpectedVariableDeclaration => ValueFormatter.FormatVariable(CanonicalDataCase.Expected, ExpectedVariableName); - private IEnumerable ConstructorVariablesDeclaration => ValueFormatter.FormatVariables(CanonicalDataCase.ConstructorInput); + private IEnumerable InputVariablesDeclaration => ValueFormatter.FormatVariables(Input); + private IEnumerable ExpectedVariableDeclaration => ValueFormatter.FormatVariable(Expected, ExpectedVariableName); + private IEnumerable ConstructorVariablesDeclaration => ValueFormatter.FormatVariables(ConstructorInput); private IEnumerable SutVariableDeclaration => new[] { $"var {SutVariableName} = new {TestedClassName}({ConstructorParameters});" }; private IEnumerable ActualVariableDeclaration => new[] { $"var {TestedVariableName} = {TestedMethodInvocation};" }; diff --git a/generators/Output/ValueFormatter.cs b/generators/Output/ValueFormatter.cs index c71974db77..2bfb1e72db 100644 --- a/generators/Output/ValueFormatter.cs +++ b/generators/Output/ValueFormatter.cs @@ -8,7 +8,7 @@ namespace Generators.Output { public static class ValueFormatter { - public static object Format(object val) + public static string Format(object val) { switch (val) { @@ -25,10 +25,11 @@ public static object Format(object val) case IDictionary dict: return dict.Format(); case IDictionary dict: return dict.Format(); case IDictionary dict: return dict.Format(); + case IDictionary dict: return dict.Format(); case JArray jArray: return jArray.Format(); case int[,] multidimensionalArray: return multidimensionalArray.Format(); case IEnumerable> tuples: return tuples.Format(); - default: return val; + default: return val?.ToString(); } } @@ -45,6 +46,8 @@ public static string[] FormatVariable(object val, string name) return FormatMultiLineEnumerable(dict.Keys.Select((key, i) => $"[{Format(key)}] = {Format(dict[key])}" + (i < dict.Keys.Count - 1 ? "," : "")), name, "new Dictionary"); case IDictionary dict: return FormatMultiLineEnumerable(dict.Keys.Select((key, i) => $"[{Format(key)}] = {Format(dict[key])}" + (i < dict.Keys.Count - 1 ? "," : "")), name, "new Dictionary"); + case IDictionary dict: + return FormatMultiLineEnumerable(dict.Keys.Select((key, i) => $"[{Format(key)}] = {Format(dict[key])}" + (i < dict.Keys.Count - 1 ? "," : "")), name, "new Dictionary"); default: return new[] { $"var {name} = {Format(val)};" }; } @@ -75,7 +78,7 @@ private static string Format(this IEnumerable strings) => private static string Format(this IEnumerable unescapedValues) => $"new[] {{ {string.Join(", ", unescapedValues.Select(Format))} }}"; - private static string Format(this IDictionary dict) => + private static string Format(this IDictionary dict) => string.Join(", ", dict.Values.Select(Format)); private static string Format(this IDictionary dict) => @@ -84,7 +87,10 @@ private static string Format(this IDictionary dict) => private static string Format(this IDictionary dict) => $"new Dictionary {{ {string.Join(", ", dict.Keys.Select(key => $"[{Format(key)}] = {Format(dict[key])}"))} }}"; - private static string Format(this JArray jArray) => + private static string Format(this IDictionary dict) => + $"new Dictionary {{ {string.Join(", ", dict.Keys.Select(key => $"[{Format(key)}] = {Format(dict[key])}"))} }}"; + + private static string Format(this JArray jArray) => $"new[] {{ {string.Join(", ", jArray.Select(Format))} }}"; private static string Format(this int[,] multidimensionalArray) @@ -94,7 +100,7 @@ private static string Format(this int[,] multidimensionalArray) : "new int[,] { }"; } - private static string Format(this IEnumerable> tuples) => + private static string Format(this IEnumerable> tuples) => $"new[] {{ {string.Join(", ", tuples.Select(Format))} }}"; private static string ToNestedArray(this IEnumerable enumerable) =>