From 4bc99360f1c261cf9790c74066fd5148c8214ec3 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 12 Jun 2017 15:39:34 +0200 Subject: [PATCH 01/22] Simplify generators --- exercises/beer-song/BeerSongTest.cs | 660 +++++++++--------- exercises/bob/BobTest.cs | 2 + exercises/food-chain/FoodChainTest.cs | 192 ++--- generators/Data/CanonicalData.cs | 2 - generators/Data/CanonicalDataCase.cs | 7 +- .../Data/CanonicalDataCaseJsonConverter.cs | 19 +- .../Data/CanonicalDataCasesJsonConverter.cs | 14 +- generators/Data/CanonicalDataValue.cs | 24 - generators/Exercises/Acronym.cs | 6 + generators/Exercises/AtbashCipher.cs | 6 + generators/Exercises/AtbashCipherExercise.cs | 20 - .../{AcronymExercise.cs => BeerSong.cs} | 8 +- generators/Exercises/BeerSongExercise.cs | 33 - generators/Exercises/Bob.cs | 18 +- generators/Exercises/BooleanExercise.cs | 4 - generators/Exercises/EqualityExercise.cs | 4 - generators/Exercises/Exercise.cs | 20 +- generators/Exercises/FoodChain.cs | 16 + generators/Exercises/FoodChainExercise.cs | 27 - generators/Exercises/HelloWorld.cs | 6 + generators/Exercises/HelloWorldExercise.cs | 9 - generators/Exercises/Isogram.cs | 6 + generators/Exercises/IsogramExercise.cs | 9 - generators/Exercises/Leap.cs | 6 + generators/Exercises/LeapExercise.cs | 9 - generators/Exercises/Luhn.cs | 6 + generators/Exercises/LuhnExercise.cs | 9 - .../{NthPrimeExercise.cs => NthPrime.cs} | 6 +- ...ctNumbersExercise.cs => PerfectNumbers.cs} | 8 +- generators/Exercises/PigLatin.cs | 6 + generators/Exercises/PigLatinExercise.cs | 9 - generators/Exercises/Raindrops.cs | 6 + generators/Exercises/RaindropsExercise.cs | 20 - ...anNumeralsExercise.cs => RomanNumerals.cs} | 9 +- generators/Exercises/RotationalCipher.cs | 6 + .../Exercises/RotationalCipherExercise.cs | 23 - .../Exercises/{WordyExercise.cs => Wordy.cs} | 6 +- generators/Generators.csproj | 4 +- generators/Helpers/StringExtensions.cs | 3 + .../Methods/EqualityTestMethodGenerator.cs | 25 +- generators/Methods/ExpectedFormat.cs | 9 + generators/Methods/TestMethodGenerator.cs | 41 +- generators/Methods/TestMethodOptions.cs | 7 +- generators/Program.cs | 42 +- generators/TestFileGenerator.cs | 37 + 45 files changed, 631 insertions(+), 778 deletions(-) delete mode 100644 generators/Data/CanonicalDataValue.cs create mode 100644 generators/Exercises/Acronym.cs create mode 100644 generators/Exercises/AtbashCipher.cs delete mode 100644 generators/Exercises/AtbashCipherExercise.cs rename generators/Exercises/{AcronymExercise.cs => BeerSong.cs} (68%) delete mode 100644 generators/Exercises/BeerSongExercise.cs create mode 100644 generators/Exercises/FoodChain.cs delete mode 100644 generators/Exercises/FoodChainExercise.cs create mode 100644 generators/Exercises/HelloWorld.cs delete mode 100644 generators/Exercises/HelloWorldExercise.cs create mode 100644 generators/Exercises/Isogram.cs delete mode 100644 generators/Exercises/IsogramExercise.cs create mode 100644 generators/Exercises/Leap.cs delete mode 100644 generators/Exercises/LeapExercise.cs create mode 100644 generators/Exercises/Luhn.cs delete mode 100644 generators/Exercises/LuhnExercise.cs rename generators/Exercises/{NthPrimeExercise.cs => NthPrime.cs} (82%) rename generators/Exercises/{PerfectNumbersExercise.cs => PerfectNumbers.cs} (80%) create mode 100644 generators/Exercises/PigLatin.cs delete mode 100644 generators/Exercises/PigLatinExercise.cs create mode 100644 generators/Exercises/Raindrops.cs delete mode 100644 generators/Exercises/RaindropsExercise.cs rename generators/Exercises/{RomanNumeralsExercise.cs => RomanNumerals.cs} (81%) create mode 100644 generators/Exercises/RotationalCipher.cs delete mode 100644 generators/Exercises/RotationalCipherExercise.cs rename generators/Exercises/{WordyExercise.cs => Wordy.cs} (80%) create mode 100644 generators/Methods/ExpectedFormat.cs create mode 100644 generators/TestFileGenerator.cs diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index bc1dcf5f22..ddb2218fb7 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -8,9 +8,9 @@ public class BeerSongTest public void First_generic_verse() { 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"+ - ""; + ""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" + + """; Assert.Equal(expected, BeerSong.Verse(99)); } @@ -18,9 +18,9 @@ public void First_generic_verse() public void Last_generic_verse() { 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.\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" + + """; Assert.Equal(expected, BeerSong.Verse(3)); } @@ -28,9 +28,9 @@ public void Last_generic_verse() public void Verse_2() { 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"+ - ""; + ""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" + + """; Assert.Equal(expected, BeerSong.Verse(2)); } @@ -38,9 +38,9 @@ public void Verse_2() public void Verse_1() { 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.\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" + + """; Assert.Equal(expected, BeerSong.Verse(1)); } @@ -48,9 +48,9 @@ public void Verse_1() public void Verse_0() { 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.\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.\n" + + """; Assert.Equal(expected, BeerSong.Verse(0)); } @@ -58,12 +58,12 @@ public void Verse_0() public void First_two_verses() { 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"+ - ""; + ""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" + + """; Assert.Equal(expected, BeerSong.Verses(99, 98)); } @@ -71,15 +71,15 @@ public void First_two_verses() public void Last_three_verses() { 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.\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.\n" + + """; Assert.Equal(expected, BeerSong.Verses(2, 0)); } @@ -87,306 +87,306 @@ public void Last_three_verses() public void All_verses() { 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.\n"+ - ""; + ""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.\n" + + """; Assert.Equal(expected, BeerSong.Verses(99, 0)); } } \ No newline at end of file diff --git a/exercises/bob/BobTest.cs b/exercises/bob/BobTest.cs index 12d2997ddb..33d609e019 100644 --- a/exercises/bob/BobTest.cs +++ b/exercises/bob/BobTest.cs @@ -1,3 +1,5 @@ +// This file was auto-generated based on version 1.0.0 of the canonical data. + using Xunit; public class BobTest diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index 91ae55af8c..51ffbbf297 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -8,7 +8,7 @@ public class FoodChainTest public void Fly() { var expected = - "I know an old lady who swallowed a fly.\n"+ + "I know an old lady who swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(1)); } @@ -17,9 +17,9 @@ public void Fly() public void Spider() { var expected = - "I know an old lady who swallowed a spider.\n"+ - "It wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(2)); } @@ -28,10 +28,10 @@ public void Spider() public void Bird() { var expected = - "I know an old lady who swallowed a bird.\n"+ - "How absurd to swallow a bird!\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(3)); } @@ -40,11 +40,11 @@ public void Bird() public void Cat() { var expected = - "I know an old lady who swallowed a cat.\n"+ - "Imagine that, to swallow a cat!\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a cat.\n" + + "Imagine that, to swallow a cat!\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(4)); } @@ -53,12 +53,12 @@ public void Cat() public void Dog() { var expected = - "I know an old lady who swallowed a dog.\n"+ - "What a hog, to swallow a dog!\n"+ - "She swallowed the dog to catch the cat.\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a dog.\n" + + "What a hog, to swallow a dog!\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(5)); } @@ -67,13 +67,13 @@ public void Dog() public void Goat() { var expected = - "I know an old lady who swallowed a goat.\n"+ - "Just opened her throat and swallowed a goat!\n"+ - "She swallowed the goat to catch the dog.\n"+ - "She swallowed the dog to catch the cat.\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a goat.\n" + + "Just opened her throat and swallowed a goat!\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(6)); } @@ -82,14 +82,14 @@ public void Goat() public void Cow() { var expected = - "I know an old lady who swallowed a cow.\n"+ - "I don't know how she swallowed a cow!\n"+ - "She swallowed the cow to catch the goat.\n"+ - "She swallowed the goat to catch the dog.\n"+ - "She swallowed the dog to catch the cat.\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a cow.\n" + + "I don't know how she swallowed a cow!\n" + + "She swallowed the cow to catch the goat.\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(7)); } @@ -98,7 +98,7 @@ public void Cow() public void Horse() { var expected = - "I know an old lady who swallowed a horse.\n"+ + "I know an old lady who swallowed a horse.\n" + "She's dead, of course!"; Assert.Equal(expected, FoodChain.Verse(8)); } @@ -107,18 +107,18 @@ public void Horse() public void Multiple_verses() { var expected = - "I know an old lady who swallowed a fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a spider.\n"+ - "It wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a bird.\n"+ - "How absurd to swallow a bird!\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, FoodChain.Verse(1, 3)); } @@ -127,55 +127,55 @@ public void Multiple_verses() public void Full_song() { var expected = - "I know an old lady who swallowed a fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a spider.\n"+ - "It wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a bird.\n"+ - "How absurd to swallow a bird!\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a cat.\n"+ - "Imagine that, to swallow a cat!\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a dog.\n"+ - "What a hog, to swallow a dog!\n"+ - "She swallowed the dog to catch the cat.\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a goat.\n"+ - "Just opened her throat and swallowed a goat!\n"+ - "She swallowed the goat to catch the dog.\n"+ - "She swallowed the dog to catch the cat.\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a cow.\n"+ - "I don't know how she swallowed a cow!\n"+ - "She swallowed the cow to catch the goat.\n"+ - "She swallowed the goat to catch the dog.\n"+ - "She swallowed the dog to catch the cat.\n"+ - "She swallowed the cat to catch the bird.\n"+ - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+ - "She swallowed the spider to catch the fly.\n"+ - "I don't know why she swallowed the fly. Perhaps she'll die.\n"+ - "\n"+ - "I know an old lady who swallowed a horse.\n"+ + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a cat.\n" + + "Imagine that, to swallow a cat!\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a dog.\n" + + "What a hog, to swallow a dog!\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a goat.\n" + + "Just opened her throat and swallowed a goat!\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a cow.\n" + + "I don't know how she swallowed a cow!\n" + + "She swallowed the cow to catch the goat.\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a horse.\n" + "She's dead, of course!"; Assert.Equal(expected, FoodChain.Verse(1, 8)); } diff --git a/generators/Data/CanonicalData.cs b/generators/Data/CanonicalData.cs index 577c96871e..8d8dbe3b1e 100644 --- a/generators/Data/CanonicalData.cs +++ b/generators/Data/CanonicalData.cs @@ -11,8 +11,6 @@ public class CanonicalData [Required] public string Version { get; set; } - public string[] Comments { get; set; } - [JsonConverter(typeof(CanonicalDataCasesJsonConverter))] public CanonicalDataCase[] Cases { get; set; } } diff --git a/generators/Data/CanonicalDataCase.cs b/generators/Data/CanonicalDataCase.cs index 081b535f61..307c90b926 100644 --- a/generators/Data/CanonicalDataCase.cs +++ b/generators/Data/CanonicalDataCase.cs @@ -13,12 +13,9 @@ public class CanonicalDataCase [Required] public string Property { get; set; } - public string[] Comments { get; set; } - - public object Input { get; set; } + [JsonIgnore] + public IDictionary Input { get; set; } public object Expected { get; set; } - - public IDictionary Data { get; set; } } } \ No newline at end of file diff --git a/generators/Data/CanonicalDataCaseJsonConverter.cs b/generators/Data/CanonicalDataCaseJsonConverter.cs index c1003e25e8..25b03d57da 100644 --- a/generators/Data/CanonicalDataCaseJsonConverter.cs +++ b/generators/Data/CanonicalDataCaseJsonConverter.cs @@ -7,10 +7,9 @@ namespace Generators.Data { public class CanonicalDataCaseJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) - { - return typeof(CanonicalDataCase) == objectType; - } + private static readonly string[] NonInputProperties = {"description", "property", "expected", "comments"}; + + public override bool CanConvert(Type objectType) => typeof(CanonicalDataCase) == objectType; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { @@ -18,15 +17,17 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var canonicalDataCase = new CanonicalDataCase(); serializer.Populate(new JTokenReader(jToken), canonicalDataCase); + + var allProperties = jToken.ToObject>(); - canonicalDataCase.Data = jToken.ToObject>(); + foreach (var nonInputProperty in NonInputProperties) + allProperties.Remove(nonInputProperty); + + canonicalDataCase.Input = allProperties; return canonicalDataCase; } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/generators/Data/CanonicalDataCasesJsonConverter.cs b/generators/Data/CanonicalDataCasesJsonConverter.cs index 9092376425..6d9242cff8 100644 --- a/generators/Data/CanonicalDataCasesJsonConverter.cs +++ b/generators/Data/CanonicalDataCasesJsonConverter.cs @@ -9,22 +9,18 @@ namespace Generators.Data { public class CanonicalDataCasesJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) - { - return typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(objectType); - } + private const string TokensPath = "$..*[?(@.property)]"; + + public override bool CanConvert(Type objectType) => typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(objectType); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var casesToken = JToken.ReadFrom(reader); - var caseTokens = casesToken.SelectTokens("$..*[?(@.property)]").ToArray(); + var caseTokens = casesToken.SelectTokens(TokensPath).ToArray(); return new JArray(caseTokens).ToObject(objectType); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/generators/Data/CanonicalDataValue.cs b/generators/Data/CanonicalDataValue.cs deleted file mode 100644 index fa04423b55..0000000000 --- a/generators/Data/CanonicalDataValue.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace Generators.Data -{ - public static class CanonicalDataValue - { - public static string ExpectedToMultiLineString(object expected) - { - switch (expected) - { - case IEnumerable enumerable: - return string.Join("\\n\"+\n\"", enumerable); - case JArray jarray: - return ExpectedToMultiLineString(((JArray) expected).Values()); - case string str: - return ExpectedToMultiLineString(str.Split('\n')); - default: - throw new ArgumentException("Cannot convert expected value to multil-ine string."); - } - } - } -} diff --git a/generators/Exercises/Acronym.cs b/generators/Exercises/Acronym.cs new file mode 100644 index 0000000000..45c57a8757 --- /dev/null +++ b/generators/Exercises/Acronym.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class Acronym : EqualityExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/AtbashCipher.cs b/generators/Exercises/AtbashCipher.cs new file mode 100644 index 0000000000..819f800e25 --- /dev/null +++ b/generators/Exercises/AtbashCipher.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class AtbashCipher : EqualityExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/AtbashCipherExercise.cs b/generators/Exercises/AtbashCipherExercise.cs deleted file mode 100644 index c4489ec6a2..0000000000 --- a/generators/Exercises/AtbashCipherExercise.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises -{ - public class AtbashCipherExercise : EqualityExercise - { - public AtbashCipherExercise() : base("atbash-cipher") - { - } - - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); - testMethodOptions.InputProperty = "phrase"; - - return testMethodOptions; - } - } -} \ No newline at end of file diff --git a/generators/Exercises/AcronymExercise.cs b/generators/Exercises/BeerSong.cs similarity index 68% rename from generators/Exercises/AcronymExercise.cs rename to generators/Exercises/BeerSong.cs index d7a6654022..e6f917f1cb 100644 --- a/generators/Exercises/AcronymExercise.cs +++ b/generators/Exercises/BeerSong.cs @@ -3,16 +3,12 @@ namespace Generators.Exercises { - public class AcronymExercise : EqualityExercise + public class BeerSong : EqualityExercise { - public AcronymExercise() : base("acronym") - { - } - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); - testMethodData.Options.InputProperty = "phrase"; + testMethodData.Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; return testMethodData; } diff --git a/generators/Exercises/BeerSongExercise.cs b/generators/Exercises/BeerSongExercise.cs deleted file mode 100644 index 2d8e3a8b61..0000000000 --- a/generators/Exercises/BeerSongExercise.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises -{ - public class BeerSongExercise : EqualityExercise - { - public BeerSongExercise() : base("beer-song") - { - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); - - testMethodData.Options.UseVariableForExpected = true; - testMethodData.Options.FormatExpected = true; - - testMethodData.CanonicalDataCase.Expected = CanonicalDataValue.ExpectedToMultiLineString(testMethodData.CanonicalDataCase.Expected); - - if (testMethodData.CanonicalDataCase.Property == "verse") - testMethodData.Options.InputProperty = "number"; - else - testMethodData.CanonicalDataCase.Input = new[] - { - testMethodData.CanonicalDataCase.Data["beginning"], - testMethodData.CanonicalDataCase.Data["end"] - }; - - return testMethodData; - } - } -} \ No newline at end of file diff --git a/generators/Exercises/Bob.cs b/generators/Exercises/Bob.cs index 81441ed2e3..af91138b16 100644 --- a/generators/Exercises/Bob.cs +++ b/generators/Exercises/Bob.cs @@ -1,20 +1,6 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises +namespace Generators.Exercises { - public class BobExercise : EqualityExercise + public class Bob : EqualityExercise { - public BobExercise() : base("bob") - { - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); - testMethodData.Options.InputProperty = "input"; - - return testMethodData; - } } } \ No newline at end of file diff --git a/generators/Exercises/BooleanExercise.cs b/generators/Exercises/BooleanExercise.cs index afc9d87d71..3695e638f3 100644 --- a/generators/Exercises/BooleanExercise.cs +++ b/generators/Exercises/BooleanExercise.cs @@ -4,10 +4,6 @@ namespace Generators.Exercises { public abstract class BooleanExercise : Exercise { - protected BooleanExercise(string name) : base(name) - { - } - protected override TestMethod CreateTestMethod(TestMethodData testMethodData) => CreateBooleanTestMethod(testMethodData); } diff --git a/generators/Exercises/EqualityExercise.cs b/generators/Exercises/EqualityExercise.cs index fc729a7967..264d93434f 100644 --- a/generators/Exercises/EqualityExercise.cs +++ b/generators/Exercises/EqualityExercise.cs @@ -4,10 +4,6 @@ namespace Generators.Exercises { public abstract class EqualityExercise : Exercise { - protected EqualityExercise(string name) : base(name) - { - } - protected override TestMethod CreateTestMethod(TestMethodData testMethodData) { if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 00907a2a12..5c35a1a93f 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -15,9 +15,9 @@ public abstract class Exercise private static readonly EqualityTestMethodGenerator EqualityTestMethodGenerator = new EqualityTestMethodGenerator(); private static readonly ExceptionTestMethodGenerator ExceptionTestMethodGenerator = new ExceptionTestMethodGenerator(); - protected Exercise(string name) + protected Exercise() { - Name = name; + Name = GetType().Name.Kebaberize(); } public string Name { get; } @@ -51,20 +51,20 @@ protected virtual TestMethod CreateTestMethod(CanonicalData canonicalData, Canon { var testMethodData = CreateTestMethodData(canonicalData, canonicalDataCase, index); - if (testMethodData.CanonicalDataCase.Expected is JObject jObject) + if (testMethodData.CanonicalDataCase.Expected is JObject) return CreateExceptionTestMethod(testMethodData); return CreateTestMethod(testMethodData); } - protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) => new TestMethodData - { - CanonicalData = canonicalData, - CanonicalDataCase = canonicalDataCase, - Index = index, - Options = CreateTestMethodOptions(canonicalData, canonicalDataCase, index) - }; + { + CanonicalData = canonicalData, + CanonicalDataCase = canonicalDataCase, + Index = index, + Options = CreateTestMethodOptions(canonicalData, canonicalDataCase, index) + }; protected virtual TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) => new TestMethodOptions(); diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs new file mode 100644 index 0000000000..8f33262b4d --- /dev/null +++ b/generators/Exercises/FoodChain.cs @@ -0,0 +1,16 @@ +using Generators.Data; +using Generators.Methods; + +namespace Generators.Exercises +{ + public class FoodChain : EqualityExercise + { + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + { + var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); + testMethodData.Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; + + return testMethodData; + } + } +} \ No newline at end of file diff --git a/generators/Exercises/FoodChainExercise.cs b/generators/Exercises/FoodChainExercise.cs deleted file mode 100644 index 0e3e1800cd..0000000000 --- a/generators/Exercises/FoodChainExercise.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises -{ - public class FoodChainExercise : EqualityExercise - { - public FoodChainExercise() : base("food-chain") - { - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); - - testMethodData.Options.UseVariableForExpected = true; - testMethodData.CanonicalDataCase.Expected = CanonicalDataValue.ExpectedToMultiLineString(testMethodData.CanonicalDataCase.Expected); - - if (testMethodData.CanonicalDataCase.Data.ContainsKey("end verse")) - testMethodData.CanonicalDataCase.Input = new[] { testMethodData.CanonicalDataCase.Data["start verse"], testMethodData.CanonicalDataCase.Data["end verse"] }; - else - testMethodData.Options.InputProperty = "start verse"; - - return testMethodData; - } - } -} \ No newline at end of file diff --git a/generators/Exercises/HelloWorld.cs b/generators/Exercises/HelloWorld.cs new file mode 100644 index 0000000000..c5103ce0f2 --- /dev/null +++ b/generators/Exercises/HelloWorld.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class HelloWorld : EqualityExercise + { + } +} diff --git a/generators/Exercises/HelloWorldExercise.cs b/generators/Exercises/HelloWorldExercise.cs deleted file mode 100644 index 2dc311a916..0000000000 --- a/generators/Exercises/HelloWorldExercise.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Generators.Exercises -{ - public class HelloWorldExercise : EqualityExercise - { - public HelloWorldExercise() : base("hello-world") - { - } - } -} diff --git a/generators/Exercises/Isogram.cs b/generators/Exercises/Isogram.cs new file mode 100644 index 0000000000..1fae877b6c --- /dev/null +++ b/generators/Exercises/Isogram.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class Isogram : BooleanExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/IsogramExercise.cs b/generators/Exercises/IsogramExercise.cs deleted file mode 100644 index ac422da9bc..0000000000 --- a/generators/Exercises/IsogramExercise.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Generators.Exercises -{ - public class IsogramExercise : BooleanExercise - { - public IsogramExercise() : base("isogram") - { - } - } -} \ No newline at end of file diff --git a/generators/Exercises/Leap.cs b/generators/Exercises/Leap.cs new file mode 100644 index 0000000000..d068ef653c --- /dev/null +++ b/generators/Exercises/Leap.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class Leap : BooleanExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/LeapExercise.cs b/generators/Exercises/LeapExercise.cs deleted file mode 100644 index b3689f4f7e..0000000000 --- a/generators/Exercises/LeapExercise.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Generators.Exercises -{ - public class LeapExercise : BooleanExercise - { - public LeapExercise() : base("leap") - { - } - } -} \ No newline at end of file diff --git a/generators/Exercises/Luhn.cs b/generators/Exercises/Luhn.cs new file mode 100644 index 0000000000..e39608097e --- /dev/null +++ b/generators/Exercises/Luhn.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class Luhn : BooleanExercise + { + } +} diff --git a/generators/Exercises/LuhnExercise.cs b/generators/Exercises/LuhnExercise.cs deleted file mode 100644 index 7789f85571..0000000000 --- a/generators/Exercises/LuhnExercise.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Generators.Exercises -{ - public class LuhnExercise : BooleanExercise - { - public LuhnExercise() : base("luhn") - { - } - } -} diff --git a/generators/Exercises/NthPrimeExercise.cs b/generators/Exercises/NthPrime.cs similarity index 82% rename from generators/Exercises/NthPrimeExercise.cs rename to generators/Exercises/NthPrime.cs index d1f887223a..a4e63a6549 100644 --- a/generators/Exercises/NthPrimeExercise.cs +++ b/generators/Exercises/NthPrime.cs @@ -4,12 +4,8 @@ namespace Generators.Exercises { - public class NthPrimeExercise : EqualityExercise + public class NthPrime : EqualityExercise { - public NthPrimeExercise() : base("nth-prime") - { - } - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); diff --git a/generators/Exercises/PerfectNumbersExercise.cs b/generators/Exercises/PerfectNumbers.cs similarity index 80% rename from generators/Exercises/PerfectNumbersExercise.cs rename to generators/Exercises/PerfectNumbers.cs index ba84988a81..41a6af4b42 100644 --- a/generators/Exercises/PerfectNumbersExercise.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -5,17 +5,13 @@ namespace Generators.Exercises { - public class PerfectNumbersExercise : EqualityExercise + public class PerfectNumbers : EqualityExercise { - public PerfectNumbersExercise() : base("perfect-numbers") - { - } - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); testMethodData.Options.ExceptionType = typeof(ArgumentOutOfRangeException); - testMethodData.Options.FormatExpected = false; + testMethodData.Options.ExpectedFormat = ExpectedFormat.Unformatted; if (testMethodData.CanonicalDataCase.Expected is string classificationType) testMethodData.CanonicalDataCase.Expected = GetClassification(classificationType); diff --git a/generators/Exercises/PigLatin.cs b/generators/Exercises/PigLatin.cs new file mode 100644 index 0000000000..d9a6bc1fd7 --- /dev/null +++ b/generators/Exercises/PigLatin.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class PigLatin : EqualityExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/PigLatinExercise.cs b/generators/Exercises/PigLatinExercise.cs deleted file mode 100644 index 7241affc9e..0000000000 --- a/generators/Exercises/PigLatinExercise.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Generators.Exercises -{ - public class PigLatinExercise : EqualityExercise - { - public PigLatinExercise() : base("pig-latin") - { - } - } -} \ No newline at end of file diff --git a/generators/Exercises/Raindrops.cs b/generators/Exercises/Raindrops.cs new file mode 100644 index 0000000000..0169452ac6 --- /dev/null +++ b/generators/Exercises/Raindrops.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class Raindrops : EqualityExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/RaindropsExercise.cs b/generators/Exercises/RaindropsExercise.cs deleted file mode 100644 index 502a940e05..0000000000 --- a/generators/Exercises/RaindropsExercise.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises -{ - public class RaindropsExercise : EqualityExercise - { - public RaindropsExercise() : base("raindrops") - { - } - - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); - testMethodOptions.InputProperty = "number"; - - return testMethodOptions; - } - } -} \ No newline at end of file diff --git a/generators/Exercises/RomanNumeralsExercise.cs b/generators/Exercises/RomanNumerals.cs similarity index 81% rename from generators/Exercises/RomanNumeralsExercise.cs rename to generators/Exercises/RomanNumerals.cs index 8dff638a42..c7c24e2ac1 100644 --- a/generators/Exercises/RomanNumeralsExercise.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -3,13 +3,9 @@ namespace Generators.Exercises { - public class RomanNumeralsExercise : EqualityExercise + public class RomanNumerals : EqualityExercise { - public RomanNumeralsExercise() : base("roman-numerals") - { - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); testMethodData.CanonicalDataCase.Property = "ToRoman"; @@ -21,7 +17,6 @@ protected override TestMethodData CreateTestMethodData(CanonicalData canonicalDa protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodOptions = new TestMethodOptions(); - testMethodOptions.InputProperty = "number"; testMethodOptions.TestedMethodType = TestedMethodType.Extension; return testMethodOptions; diff --git a/generators/Exercises/RotationalCipher.cs b/generators/Exercises/RotationalCipher.cs new file mode 100644 index 0000000000..33d12e94d7 --- /dev/null +++ b/generators/Exercises/RotationalCipher.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class RotationalCipher : EqualityExercise + { + } +} \ No newline at end of file diff --git a/generators/Exercises/RotationalCipherExercise.cs b/generators/Exercises/RotationalCipherExercise.cs deleted file mode 100644 index 7cfdb3bfa8..0000000000 --- a/generators/Exercises/RotationalCipherExercise.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises -{ - public class RotationalCipherExercise : EqualityExercise - { - public RotationalCipherExercise() : base("rotational-cipher") - { - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); - testMethodData.CanonicalDataCase.Input = new[] - { - testMethodData.CanonicalDataCase.Data["text"], - testMethodData.CanonicalDataCase.Data["shiftKey"] - }; - return testMethodData; - } - } -} \ No newline at end of file diff --git a/generators/Exercises/WordyExercise.cs b/generators/Exercises/Wordy.cs similarity index 80% rename from generators/Exercises/WordyExercise.cs rename to generators/Exercises/Wordy.cs index befd927978..dcd2c43c6d 100644 --- a/generators/Exercises/WordyExercise.cs +++ b/generators/Exercises/Wordy.cs @@ -3,12 +3,8 @@ namespace Generators.Exercises { - public class WordyExercise : EqualityExercise + public class Wordy : EqualityExercise { - public WordyExercise() : base("wordy") - { - } - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); diff --git a/generators/Generators.csproj b/generators/Generators.csproj index efab961ac0..95e8eb2699 100644 --- a/generators/Generators.csproj +++ b/generators/Generators.csproj @@ -4,8 +4,8 @@ netcoreapp1.1 - - + + diff --git a/generators/Helpers/StringExtensions.cs b/generators/Helpers/StringExtensions.cs index b949f3186f..adf230c32c 100644 --- a/generators/Helpers/StringExtensions.cs +++ b/generators/Helpers/StringExtensions.cs @@ -4,5 +4,8 @@ public static class StringExtensions { public static string EnsureStartsWith(this string str, string value) => str.StartsWith(value) ? str : value + str; + + public static bool IsQuoted(this string str) + => str.StartsWith("\"") && str.EndsWith("\""); } } \ No newline at end of file diff --git a/generators/Methods/EqualityTestMethodGenerator.cs b/generators/Methods/EqualityTestMethodGenerator.cs index d13e6b6210..c554db1619 100644 --- a/generators/Methods/EqualityTestMethodGenerator.cs +++ b/generators/Methods/EqualityTestMethodGenerator.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Linq; +using Newtonsoft.Json.Linq; namespace Generators.Methods { @@ -14,17 +16,17 @@ protected override string Body switch (TestMethodData.Options.TestedMethodType) { case TestedMethodType.Static: - if (TestMethodData.Options.UseVariableForExpected) + if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return $"var expected = {FormattedExpectedVariable};\nAssert.Equal(expected, {TestedClassName}.{TestedMethod}({Input}));"; return $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethod}({Input}));"; case TestedMethodType.Instance: - if (TestMethodData.Options.UseVariableForExpected) + if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return $"var expected = {FormattedExpectedVariable};\nvar sut = new {TestedClassName}();\n Assert.Equal({Expected}, sut.{TestedMethod}({Input}));"; return $"var sut = new {TestedClassName}();\n Assert.Equal({Expected}, sut.{TestedMethod}({Input}));"; case TestedMethodType.Extension: - if (TestMethodData.Options.UseVariableForExpected) + if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return $"var expected = {FormattedExpectedVariable};\nAssert.Equal(expected, {Input}.{TestedMethod}());"; return $"Assert.Equal({Expected}, {Input}.{TestedMethod}());"; @@ -38,12 +40,27 @@ protected virtual string FormattedExpectedVariable { get { - var lines = Expected.ToString().Split('\n'); + var lines = ExpectedToMultiLineString(Expected).Split('\n'); if (lines.Length == 1) return lines[0]; return "\n" + string.Join("\n", lines.Select(line => $"{Tab}{line}")); } } + + private string ExpectedToMultiLineString(object expected) + { + switch (expected) + { + case JArray jarray: + return ExpectedToMultiLineString(jarray.Values()); + case IEnumerable enumerable: + return string.Join(" + \"\\n\" +\n", enumerable.Select(FormatExpectedValue)).Replace("\" + \"\\n", "\\n"); + case string str: + return ExpectedToMultiLineString(str.Split('\n')); + default: + throw new ArgumentException("Cannot convert expected value to multiline string."); + } + } } } \ No newline at end of file diff --git a/generators/Methods/ExpectedFormat.cs b/generators/Methods/ExpectedFormat.cs new file mode 100644 index 0000000000..1aa23d05fd --- /dev/null +++ b/generators/Methods/ExpectedFormat.cs @@ -0,0 +1,9 @@ +namespace Generators.Methods +{ + public enum ExpectedFormat + { + Formatted, + FormattedAsMultilineString, + Unformatted + } +} \ No newline at end of file diff --git a/generators/Methods/TestMethodGenerator.cs b/generators/Methods/TestMethodGenerator.cs index ec17643a6d..f25afdf6e0 100644 --- a/generators/Methods/TestMethodGenerator.cs +++ b/generators/Methods/TestMethodGenerator.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Generators.Helpers; using Humanizer; using To = Generators.Helpers.To; @@ -36,44 +37,36 @@ protected virtual string TestedClassName protected virtual string TestedMethod => TestMethodData.CanonicalDataCase.Property.Transform(To.TestedMethodName); - protected virtual object Input => - TestMethodData.Options.FormatInput - ? FormatInputValue(InputValue) - : InputValue; + protected virtual object Input => FormatInputValue(TestMethodData.CanonicalDataCase.Input); - protected virtual object Expected => - TestMethodData.Options.FormatExpected - ? FormatValue(TestMethodData.CanonicalDataCase.Expected) - : TestMethodData.CanonicalDataCase.Expected; - - protected virtual object InputValue => - TestMethodData.Options.InputProperty == null - ? TestMethodData.CanonicalDataCase.Input - : TestMethodData.CanonicalDataCase.Data[TestMethodData.Options.InputProperty]; - - protected virtual object FormatValue(object val) + protected virtual object FormatInputValue(object val) { switch (val) { + case IDictionary dict: + return string.Join(", ", dict.Values.Select(FormatInputValue)); case string s: - s = s - .Replace("\n", "\\n") - .Replace("\r", "\\r") - .Replace("\t", "\\t"); - return $"\"{s}\""; + return $"\"{s.Replace("\n", "\\n").Replace("\t", "\\t").Replace("\r", "\\r")}\""; default: return val; } } - protected virtual object FormatInputValue(object val) + protected virtual object Expected => + TestMethodData.Options.ExpectedFormat == ExpectedFormat.Unformatted + ? TestMethodData.CanonicalDataCase.Expected + : FormatExpectedValue(TestMethodData.CanonicalDataCase.Expected); + + protected virtual object FormatExpectedValue(object val) { switch (val) { - case IEnumerable inputs when !(val is string): - return string.Join(", ", inputs.Select(FormatValue)); + case string s: + return $"\"{s}\""; + case IEnumerable enumerable: + return enumerable.Select(FormatExpectedValue); default: - return FormatValue(val); + return val; } } } diff --git a/generators/Methods/TestMethodOptions.cs b/generators/Methods/TestMethodOptions.cs index c39397ec86..c95c172a8f 100644 --- a/generators/Methods/TestMethodOptions.cs +++ b/generators/Methods/TestMethodOptions.cs @@ -4,12 +4,9 @@ namespace Generators.Methods { public class TestMethodOptions { - public string InputProperty { get; set; } - public bool FormatInput { get; set; } = true; - public bool FormatExpected { get; set; } = true; - public bool UseVariableForExpected { get; set; } = false; + public ExpectedFormat ExpectedFormat { get; set; } = ExpectedFormat.Formatted; public Type ExceptionType { get; set; } = typeof(ArgumentException); public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.Static; - public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = (x) => false; + public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = x => false; } } \ No newline at end of file diff --git a/generators/Program.cs b/generators/Program.cs index a96395f769..ca20a20631 100644 --- a/generators/Program.cs +++ b/generators/Program.cs @@ -1,7 +1,5 @@ -using Generators.Exercises; -using System.IO; -using Generators.Classes; -using Generators.Data; +using Generators.Data; +using Generators.Exercises; using Serilog; namespace Generators @@ -25,42 +23,12 @@ private static void GenerateAll() { Log.Information("Start generating tests..."); - TestFileGenerator.Generate(new FoodChainExercise()); + TestFileGenerator.Generate(new BeerSong()); - foreach (var exercise in new ExerciseCollection()) - TestFileGenerator.Generate(exercise); + //foreach (var exercise in new ExerciseCollection()) + // TestFileGenerator.Generate(exercise); Log.Information("Finished generating tests for all supported exercises."); } } - - public static class TestFileGenerator - { - public static void Generate(Exercise exercise) - { - var testClass = CreateTestClass(exercise); - var testClassContents = TestClassRenderer.Render(testClass); - var testClassFilePath = TestFilePath(exercise, testClass); - - SaveTestClassContentsToFile(testClassFilePath, testClassContents); - Log.Information("Generated tests for {Exercise} exercise in {TestFile}.", exercise.Name, testClassFilePath); - } - - private static TestClass CreateTestClass(Exercise exercise) - { - var canonicalData = CanonicalDataParser.Parse(exercise.Name); - return exercise.CreateTestClass(canonicalData); - } - - private static void SaveTestClassContentsToFile(string testClassFilePath, string testClassContents) - { - Directory.CreateDirectory(Path.GetDirectoryName(testClassFilePath)); - File.WriteAllText(testClassFilePath, testClassContents); - } - - - private static string TestFilePath(Exercise exercise, TestClass testClass) => Path.Combine("..", "exercises", exercise.Name, TestFileName(testClass)); - - private static string TestFileName(TestClass testClass) => $"{testClass.ClassName}.cs"; - } } \ No newline at end of file diff --git a/generators/TestFileGenerator.cs b/generators/TestFileGenerator.cs new file mode 100644 index 0000000000..41224a14b8 --- /dev/null +++ b/generators/TestFileGenerator.cs @@ -0,0 +1,37 @@ +using System.IO; +using Generators.Classes; +using Generators.Data; +using Generators.Exercises; +using Serilog; + +namespace Generators +{ + public static class TestFileGenerator + { + public static void Generate(Exercise exercise) + { + var testClass = CreateTestClass(exercise); + var testClassContents = TestClassRenderer.Render(testClass); + var testClassFilePath = TestFilePath(exercise, testClass); + + SaveTestClassContentsToFile(testClassFilePath, testClassContents); + Log.Information("Generated tests for {Exercise} exercise in {TestFile}.", exercise.Name, testClassFilePath); + } + + private static TestClass CreateTestClass(Exercise exercise) + { + var canonicalData = CanonicalDataParser.Parse(exercise.Name); + return exercise.CreateTestClass(canonicalData); + } + + private static void SaveTestClassContentsToFile(string testClassFilePath, string testClassContents) + { + Directory.CreateDirectory(Path.GetDirectoryName(testClassFilePath)); + File.WriteAllText(testClassFilePath, testClassContents); + } + + private static string TestFilePath(Exercise exercise, TestClass testClass) => Path.Combine("..", "exercises", exercise.Name, TestFileName(testClass)); + + private static string TestFileName(TestClass testClass) => $"{testClass.ClassName}.cs"; + } +} \ No newline at end of file From dd4f80ce8a59d6566aaf9ee7288df6121c099858 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 09:10:52 +0200 Subject: [PATCH 02/22] Small refactoring --- generators/Data/CanonicalDataCasesJsonConverter.cs | 3 +-- generators/Data/ExerciseCollection.cs | 4 ++-- generators/Generators.csproj | 2 +- generators/Program.cs | 11 ++++------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/generators/Data/CanonicalDataCasesJsonConverter.cs b/generators/Data/CanonicalDataCasesJsonConverter.cs index 6d9242cff8..ab2bcf33fe 100644 --- a/generators/Data/CanonicalDataCasesJsonConverter.cs +++ b/generators/Data/CanonicalDataCasesJsonConverter.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -16,7 +15,7 @@ public class CanonicalDataCasesJsonConverter : JsonConverter public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var casesToken = JToken.ReadFrom(reader); - var caseTokens = casesToken.SelectTokens(TokensPath).ToArray(); + var caseTokens = new JArray(casesToken.SelectTokens(TokensPath)); return new JArray(caseTokens).ToObject(objectType); } diff --git a/generators/Data/ExerciseCollection.cs b/generators/Data/ExerciseCollection.cs index db96ec628f..b486505008 100644 --- a/generators/Data/ExerciseCollection.cs +++ b/generators/Data/ExerciseCollection.cs @@ -9,9 +9,9 @@ namespace Generators.Data { public class ExerciseCollection : IEnumerable { - private readonly IEnumerable generators = GetDefinedGenerators(); + private readonly IEnumerable _generators = GetDefinedGenerators(); - public IEnumerator GetEnumerator() => generators.GetEnumerator(); + public IEnumerator GetEnumerator() => _generators.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/generators/Generators.csproj b/generators/Generators.csproj index 95e8eb2699..463f556f48 100644 --- a/generators/Generators.csproj +++ b/generators/Generators.csproj @@ -5,7 +5,7 @@ - + diff --git a/generators/Program.cs b/generators/Program.cs index ca20a20631..1aa55ea12a 100644 --- a/generators/Program.cs +++ b/generators/Program.cs @@ -1,5 +1,4 @@ using Generators.Data; -using Generators.Exercises; using Serilog; namespace Generators @@ -21,14 +20,12 @@ private static void SetupLogger() private static void GenerateAll() { - Log.Information("Start generating tests..."); + Log.Information("Generating tests..."); - TestFileGenerator.Generate(new BeerSong()); + foreach (var exercise in new ExerciseCollection()) + TestFileGenerator.Generate(exercise); - //foreach (var exercise in new ExerciseCollection()) - // TestFileGenerator.Generate(exercise); - - Log.Information("Finished generating tests for all supported exercises."); + Log.Information("Generated tests."); } } } \ No newline at end of file From 1de916a5a1fe4a3bc04a642b9075ca1dd98f5fa0 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 09:43:10 +0200 Subject: [PATCH 03/22] Use enumerable for body input --- exercises/beer-song/BeerSongTest.cs | 676 +++++++++--------- exercises/food-chain/FoodChainTest.cs | 232 +++--- generators/Classes/TestClass.cs | 2 - generators/Classes/TestClassRenderer.cs | 13 +- .../Methods/BooleanTestMethodGenerator.cs | 9 +- .../Methods/EqualityTestMethodGenerator.cs | 16 +- .../Methods/ExceptionTestMethodGenerator.cs | 8 +- generators/Methods/TestMethod.cs | 2 +- generators/Methods/TestMethodGenerator.cs | 4 +- generators/Methods/TestMethodRenderer.cs | 2 +- 10 files changed, 477 insertions(+), 487 deletions(-) diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index ddb2218fb7..e10f9bc704 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -8,385 +8,385 @@ public class BeerSongTest public void First_generic_verse() { 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" + - """; - Assert.Equal(expected, BeerSong.Verse(99)); + ""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" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Last_generic_verse() { 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.\n" + - """; - Assert.Equal(expected, BeerSong.Verse(3)); + ""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" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Verse_2() { 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" + - """; - Assert.Equal(expected, BeerSong.Verse(2)); + ""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" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Verse_1() { 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.\n" + - """; - Assert.Equal(expected, BeerSong.Verse(1)); + ""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" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Verse_0() { 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.\n" + - """; - Assert.Equal(expected, BeerSong.Verse(0)); + ""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.\n" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void First_two_verses() { 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" + - """; - Assert.Equal(expected, BeerSong.Verses(99, 98)); + ""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" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Last_three_verses() { 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.\n" + - """; - Assert.Equal(expected, BeerSong.Verses(2, 0)); + ""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.\n" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void All_verses() { 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.\n" + - """; - Assert.Equal(expected, BeerSong.Verses(99, 0)); + ""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.\n" + + """; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } } \ No newline at end of file diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index 51ffbbf297..af3000d5dc 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -8,175 +8,175 @@ public class FoodChainTest public void Fly() { var expected = - "I know an old lady who swallowed a fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(1)); + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Spider() { var expected = - "I know an old lady who swallowed a spider.\n" + - "It wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(2)); + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Bird() { var expected = - "I know an old lady who swallowed a bird.\n" + - "How absurd to swallow a bird!\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(3)); + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Cat() { var expected = - "I know an old lady who swallowed a cat.\n" + - "Imagine that, to swallow a cat!\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(4)); + "I know an old lady who swallowed a cat.\n" + + "Imagine that, to swallow a cat!\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Dog() { var expected = - "I know an old lady who swallowed a dog.\n" + - "What a hog, to swallow a dog!\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(5)); + "I know an old lady who swallowed a dog.\n" + + "What a hog, to swallow a dog!\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Goat() { var expected = - "I know an old lady who swallowed a goat.\n" + - "Just opened her throat and swallowed a goat!\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(6)); + "I know an old lady who swallowed a goat.\n" + + "Just opened her throat and swallowed a goat!\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Cow() { var expected = - "I know an old lady who swallowed a cow.\n" + - "I don't know how she swallowed a cow!\n" + - "She swallowed the cow to catch the goat.\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(7)); + "I know an old lady who swallowed a cow.\n" + + "I don't know how she swallowed a cow!\n" + + "She swallowed the cow to catch the goat.\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Horse() { var expected = - "I know an old lady who swallowed a horse.\n" + - "She's dead, of course!"; - Assert.Equal(expected, FoodChain.Verse(8)); + "I know an old lady who swallowed a horse.\n" + + "She's dead, of course!"; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Multiple_verses() { var expected = - "I know an old lady who swallowed a fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a spider.\n" + - "It wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a bird.\n" + - "How absurd to swallow a bird!\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(1, 3)); + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } [Fact(Skip = "Remove to run test")] public void Full_song() { var expected = - "I know an old lady who swallowed a fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a spider.\n" + - "It wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a bird.\n" + - "How absurd to swallow a bird!\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a cat.\n" + - "Imagine that, to swallow a cat!\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a dog.\n" + - "What a hog, to swallow a dog!\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a goat.\n" + - "Just opened her throat and swallowed a goat!\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a cow.\n" + - "I don't know how she swallowed a cow!\n" + - "She swallowed the cow to catch the goat.\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a horse.\n" + - "She's dead, of course!"; - Assert.Equal(expected, FoodChain.Verse(1, 8)); + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a cat.\n" + + "Imagine that, to swallow a cat!\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a dog.\n" + + "What a hog, to swallow a dog!\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a goat.\n" + + "Just opened her throat and swallowed a goat!\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a cow.\n" + + "I don't know how she swallowed a cow!\n" + + "She swallowed the cow to catch the goat.\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a horse.\n" + + "She's dead, of course!"; + Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } } \ No newline at end of file diff --git a/generators/Classes/TestClass.cs b/generators/Classes/TestClass.cs index 4be84ca6ca..8bd4513b9a 100644 --- a/generators/Classes/TestClass.cs +++ b/generators/Classes/TestClass.cs @@ -7,9 +7,7 @@ public class TestClass { public ISet UsingNamespaces { get; set; } = new HashSet { "Xunit" }; public string ClassName { get; set; } - public string BeforeTestMethods { get; set; } public TestMethod[] TestMethods { get; set; } - public string AfterTestMethods { get; set; } public string CanonicalDataVersion { get; set; } } } \ No newline at end of file diff --git a/generators/Classes/TestClassRenderer.cs b/generators/Classes/TestClassRenderer.cs index 6ab7446e91..306444961a 100644 --- a/generators/Classes/TestClassRenderer.cs +++ b/generators/Classes/TestClassRenderer.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Generators.Methods; namespace Generators.Classes @@ -27,14 +26,6 @@ private static string RenderUsingNamespaces(TestClass testClass) => string.Join("\n", testClass.UsingNamespaces.Select(usingNamespace => $"using {usingNamespace};")); private static string RenderBody(TestClass testClass) => - string.Join("\n\n", GetBodyParts(testClass)); - - private static IEnumerable GetBodyParts(TestClass testClass) => - from bodyPart in new [] { testClass.BeforeTestMethods, RenderTestMethods(testClass), testClass.AfterTestMethods } - where !string.IsNullOrWhiteSpace(bodyPart) - select bodyPart; - - private static string RenderTestMethods(TestClass testClass) => - string.Join("\n\n", testClass.TestMethods.Select(TestMethodRenderer.Render)); + string.Join("\n\n", testClass.TestMethods.Select(TestMethodRenderer.Render)); } } diff --git a/generators/Methods/BooleanTestMethodGenerator.cs b/generators/Methods/BooleanTestMethodGenerator.cs index 69b92c6ec4..ead9591bad 100644 --- a/generators/Methods/BooleanTestMethodGenerator.cs +++ b/generators/Methods/BooleanTestMethodGenerator.cs @@ -1,22 +1,23 @@ using System; +using System.Collections.Generic; using Generators.Helpers; namespace Generators.Methods { public class BooleanTestMethodGenerator : TestMethodGenerator { - protected override string Body + protected override IEnumerable Body { get { switch (TestMethodData.Options.TestedMethodType) { case TestedMethodType.Static: - return $"{Assertion}({TestedClassName}.{TestedMethod}({Input}));"; + return new[] { $"{Assertion}({TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: - return $"var sut = new {TestedClassName}();\n {Assertion}(sut.{TestedMethod}({Input}));"; + return new[] { $"var sut = new {TestedClassName}();\n{Tab}{Assertion}(sut.{TestedMethod}({Input}));" }; case TestedMethodType.Extension: - return $"{Assertion}({Input}.{TestedMethod}());"; + return new[] { $"{Assertion}({Input}.{TestedMethod}());" }; default: throw new ArgumentOutOfRangeException(); } diff --git a/generators/Methods/EqualityTestMethodGenerator.cs b/generators/Methods/EqualityTestMethodGenerator.cs index c554db1619..12fff036b2 100644 --- a/generators/Methods/EqualityTestMethodGenerator.cs +++ b/generators/Methods/EqualityTestMethodGenerator.cs @@ -7,9 +7,7 @@ namespace Generators.Methods { public class EqualityTestMethodGenerator : TestMethodGenerator { - private const string Tab = " "; - - protected override string Body + protected override IEnumerable Body { get { @@ -17,19 +15,19 @@ protected override string Body { case TestedMethodType.Static: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return $"var expected = {FormattedExpectedVariable};\nAssert.Equal(expected, {TestedClassName}.{TestedMethod}({Input}));"; + return new[] { $"var expected = {FormattedExpectedVariable};", "Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input}));" }; - return $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethod}({Input}));"; + return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return $"var expected = {FormattedExpectedVariable};\nvar sut = new {TestedClassName}();\n Assert.Equal({Expected}, sut.{TestedMethod}({Input}));"; + return new[] { $"var expected = {FormattedExpectedVariable};", "var sut = new {TestedClassName}();", "Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; - return $"var sut = new {TestedClassName}();\n Assert.Equal({Expected}, sut.{TestedMethod}({Input}));"; + return new[] { $"var sut = new {TestedClassName}();", "Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; case TestedMethodType.Extension: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return $"var expected = {FormattedExpectedVariable};\nAssert.Equal(expected, {Input}.{TestedMethod}());"; + return new[] { $"var expected = {FormattedExpectedVariable};", "Assert.Equal(expected, {Input}.{TestedMethod}());" }; - return $"Assert.Equal({Expected}, {Input}.{TestedMethod}());"; + return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethod}());" }; default: throw new ArgumentOutOfRangeException(); } diff --git a/generators/Methods/ExceptionTestMethodGenerator.cs b/generators/Methods/ExceptionTestMethodGenerator.cs index 7117129d80..cef7769ae3 100644 --- a/generators/Methods/ExceptionTestMethodGenerator.cs +++ b/generators/Methods/ExceptionTestMethodGenerator.cs @@ -5,18 +5,18 @@ namespace Generators.Methods { public class ExceptionTestMethodGenerator : TestMethodGenerator { - protected override string Body + protected override IEnumerable Body { get { switch (TestMethodData.Options.TestedMethodType) { case TestedMethodType.Static: - return $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethod}({Input}));"; + return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: - return $"var sut = new {TestedClassName}();\n Assert.Throws<{ExceptionType}>(() => sut.{TestedMethod}({Input}));;"; + return new[] { $"var sut = new {TestedClassName}();", "Assert.Throws<{ExceptionType}>(() => sut.{TestedMethod}({Input}));;" }; case TestedMethodType.Extension: - return $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethod}());"; + return new[] { $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethod}());" }; default: throw new ArgumentOutOfRangeException(); } diff --git a/generators/Methods/TestMethod.cs b/generators/Methods/TestMethod.cs index ae87a55301..3fbe802e45 100644 --- a/generators/Methods/TestMethod.cs +++ b/generators/Methods/TestMethod.cs @@ -6,7 +6,7 @@ public class TestMethod { public ISet UsingNamespaces { get; set; } = new HashSet(); public string MethodName { get; set; } - public string Body { get; set; } + public IEnumerable Body { get; set; } public int Index { get; set; } } } \ No newline at end of file diff --git a/generators/Methods/TestMethodGenerator.cs b/generators/Methods/TestMethodGenerator.cs index f25afdf6e0..8e8a2e70c7 100644 --- a/generators/Methods/TestMethodGenerator.cs +++ b/generators/Methods/TestMethodGenerator.cs @@ -8,6 +8,8 @@ namespace Generators.Methods { public abstract class TestMethodGenerator { + protected const string Tab = " "; + public TestMethod Create(TestMethodData testMethodData) { TestMethodData = testMethodData; @@ -23,7 +25,7 @@ public TestMethod Create(TestMethodData testMethodData) protected TestMethodData TestMethodData { get; private set; } - protected abstract string Body { get; } + protected abstract IEnumerable Body { get; } protected virtual ISet UsingNamespaces => new HashSet(); diff --git a/generators/Methods/TestMethodRenderer.cs b/generators/Methods/TestMethodRenderer.cs index 1be927eb57..fbd71f1c28 100644 --- a/generators/Methods/TestMethodRenderer.cs +++ b/generators/Methods/TestMethodRenderer.cs @@ -21,6 +21,6 @@ public static string Render(TestMethod testMethod) => .Replace("{Skip}", testMethod.Index == 0 ? "" : "(Skip = \"Remove to run test\")"); private static string RenderBody(TestMethod testMethod) - => string.Join("\n", testMethod.Body.Split('\n').Select(line => $"{Tab}{Tab}{line}")); + => string.Join("\n", testMethod.Body.Select(line => $"{Tab}{Tab}{line}")); } } From 06c4df164c858fd0d268f1685a0b01b2aed2d643 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 10:02:04 +0200 Subject: [PATCH 04/22] Simplify options --- exercises/beer-song/BeerSongTest.cs | 660 +++++++++--------- exercises/food-chain/FoodChainTest.cs | 212 +++--- generators/Exercises/BooleanExercise.cs | 7 +- generators/Exercises/EqualityExercise.cs | 4 +- generators/Exercises/Exercise.cs | 25 +- generators/Exercises/NthPrime.cs | 11 +- generators/Exercises/PerfectNumbers.cs | 2 +- generators/Exercises/RomanNumerals.cs | 13 +- generators/Exercises/Wordy.cs | 12 +- .../Methods/BooleanTestMethodGenerator.cs | 8 +- .../Methods/EqualityTestMethodGenerator.cs | 2 +- generators/Methods/TestMethodGenerator.cs | 3 - 12 files changed, 468 insertions(+), 491 deletions(-) diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index e10f9bc704..29292e7783 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -8,9 +8,9 @@ public class BeerSongTest public void First_generic_verse() { 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" + - """; +""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" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -18,9 +18,9 @@ public void First_generic_verse() public void Last_generic_verse() { 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.\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" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -28,9 +28,9 @@ public void Last_generic_verse() public void Verse_2() { 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" + - """; +""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" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -38,9 +38,9 @@ public void Verse_2() public void Verse_1() { 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.\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" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -48,9 +48,9 @@ public void Verse_1() public void Verse_0() { 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.\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.\n" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -58,12 +58,12 @@ public void Verse_0() public void First_two_verses() { 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" + - """; +""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" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -71,15 +71,15 @@ public void First_two_verses() public void Last_three_verses() { 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.\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.\n" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -87,306 +87,306 @@ public void Last_three_verses() public void All_verses() { 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.\n" + - """; +""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.\n" + +"""; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } } \ No newline at end of file diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index af3000d5dc..8fbff3e65f 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -8,8 +8,8 @@ public class FoodChainTest public void Fly() { var expected = - "I know an old lady who swallowed a fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -17,10 +17,10 @@ public void Fly() public void Spider() { var expected = - "I know an old lady who swallowed a spider.\n" + - "It wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a spider.\n" + +"It wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -28,11 +28,11 @@ public void Spider() public void Bird() { var expected = - "I know an old lady who swallowed a bird.\n" + - "How absurd to swallow a bird!\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a bird.\n" + +"How absurd to swallow a bird!\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -40,12 +40,12 @@ public void Bird() public void Cat() { var expected = - "I know an old lady who swallowed a cat.\n" + - "Imagine that, to swallow a cat!\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a cat.\n" + +"Imagine that, to swallow a cat!\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -53,13 +53,13 @@ public void Cat() public void Dog() { var expected = - "I know an old lady who swallowed a dog.\n" + - "What a hog, to swallow a dog!\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a dog.\n" + +"What a hog, to swallow a dog!\n" + +"She swallowed the dog to catch the cat.\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -67,14 +67,14 @@ public void Dog() public void Goat() { var expected = - "I know an old lady who swallowed a goat.\n" + - "Just opened her throat and swallowed a goat!\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a goat.\n" + +"Just opened her throat and swallowed a goat!\n" + +"She swallowed the goat to catch the dog.\n" + +"She swallowed the dog to catch the cat.\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -82,15 +82,15 @@ public void Goat() public void Cow() { var expected = - "I know an old lady who swallowed a cow.\n" + - "I don't know how she swallowed a cow!\n" + - "She swallowed the cow to catch the goat.\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a cow.\n" + +"I don't know how she swallowed a cow!\n" + +"She swallowed the cow to catch the goat.\n" + +"She swallowed the goat to catch the dog.\n" + +"She swallowed the dog to catch the cat.\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -98,8 +98,8 @@ public void Cow() public void Horse() { var expected = - "I know an old lady who swallowed a horse.\n" + - "She's dead, of course!"; +"I know an old lady who swallowed a horse.\n" + +"She's dead, of course!"; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -107,19 +107,19 @@ public void Horse() public void Multiple_verses() { var expected = - "I know an old lady who swallowed a fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a spider.\n" + - "It wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a bird.\n" + - "How absurd to swallow a bird!\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die."; +"I know an old lady who swallowed a fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a spider.\n" + +"It wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a bird.\n" + +"How absurd to swallow a bird!\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die."; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } @@ -127,56 +127,56 @@ public void Multiple_verses() public void Full_song() { var expected = - "I know an old lady who swallowed a fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a spider.\n" + - "It wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a bird.\n" + - "How absurd to swallow a bird!\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a cat.\n" + - "Imagine that, to swallow a cat!\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a dog.\n" + - "What a hog, to swallow a dog!\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a goat.\n" + - "Just opened her throat and swallowed a goat!\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a cow.\n" + - "I don't know how she swallowed a cow!\n" + - "She swallowed the cow to catch the goat.\n" + - "She swallowed the goat to catch the dog.\n" + - "She swallowed the dog to catch the cat.\n" + - "She swallowed the cat to catch the bird.\n" + - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + - "She swallowed the spider to catch the fly.\n" + - "I don't know why she swallowed the fly. Perhaps she'll die.\n" + - "\n" + - "I know an old lady who swallowed a horse.\n" + - "She's dead, of course!"; +"I know an old lady who swallowed a fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a spider.\n" + +"It wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a bird.\n" + +"How absurd to swallow a bird!\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a cat.\n" + +"Imagine that, to swallow a cat!\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a dog.\n" + +"What a hog, to swallow a dog!\n" + +"She swallowed the dog to catch the cat.\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a goat.\n" + +"Just opened her throat and swallowed a goat!\n" + +"She swallowed the goat to catch the dog.\n" + +"She swallowed the dog to catch the cat.\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a cow.\n" + +"I don't know how she swallowed a cow!\n" + +"She swallowed the cow to catch the goat.\n" + +"She swallowed the goat to catch the dog.\n" + +"She swallowed the dog to catch the cat.\n" + +"She swallowed the cat to catch the bird.\n" + +"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + +"She swallowed the spider to catch the fly.\n" + +"I don't know why she swallowed the fly. Perhaps she'll die.\n" + +"\n" + +"I know an old lady who swallowed a horse.\n" + +"She's dead, of course!"; Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); } } \ No newline at end of file diff --git a/generators/Exercises/BooleanExercise.cs b/generators/Exercises/BooleanExercise.cs index 3695e638f3..6e7fa484cb 100644 --- a/generators/Exercises/BooleanExercise.cs +++ b/generators/Exercises/BooleanExercise.cs @@ -5,6 +5,11 @@ namespace Generators.Exercises public abstract class BooleanExercise : Exercise { protected override TestMethod CreateTestMethod(TestMethodData testMethodData) - => CreateBooleanTestMethod(testMethodData); + { + if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) + return ExceptionTestMethodGenerator.Create(testMethodData); + + return BooleanTestMethodGenerator.Create(testMethodData); + } } } \ No newline at end of file diff --git a/generators/Exercises/EqualityExercise.cs b/generators/Exercises/EqualityExercise.cs index 264d93434f..fcfc531721 100644 --- a/generators/Exercises/EqualityExercise.cs +++ b/generators/Exercises/EqualityExercise.cs @@ -7,9 +7,9 @@ public abstract class EqualityExercise : Exercise protected override TestMethod CreateTestMethod(TestMethodData testMethodData) { if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return CreateExceptionTestMethod(testMethodData); + return ExceptionTestMethodGenerator.Create(testMethodData); - return CreateEqualityTestMethod(testMethodData); + return EqualityTestMethodGenerator.Create(testMethodData); } } } \ No newline at end of file diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 5c35a1a93f..883296ee55 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -11,17 +11,20 @@ namespace Generators.Exercises { public abstract class Exercise { - private static readonly BooleanTestMethodGenerator BooleanTestMethodGenerator = new BooleanTestMethodGenerator(); - private static readonly EqualityTestMethodGenerator EqualityTestMethodGenerator = new EqualityTestMethodGenerator(); - private static readonly ExceptionTestMethodGenerator ExceptionTestMethodGenerator = new ExceptionTestMethodGenerator(); + protected static readonly BooleanTestMethodGenerator BooleanTestMethodGenerator = new BooleanTestMethodGenerator(); + protected static readonly EqualityTestMethodGenerator EqualityTestMethodGenerator = new EqualityTestMethodGenerator(); + protected static readonly ExceptionTestMethodGenerator ExceptionTestMethodGenerator = new ExceptionTestMethodGenerator(); protected Exercise() { Name = GetType().Name.Kebaberize(); + Options = new TestMethodOptions(); } public string Name { get; } + protected TestMethodOptions Options { get; } + public TestClass CreateTestClass(CanonicalData canonicalData) { var testClass = new TestClass @@ -52,7 +55,7 @@ protected virtual TestMethod CreateTestMethod(CanonicalData canonicalData, Canon var testMethodData = CreateTestMethodData(canonicalData, canonicalDataCase, index); if (testMethodData.CanonicalDataCase.Expected is JObject) - return CreateExceptionTestMethod(testMethodData); + return ExceptionTestMethodGenerator.Create(testMethodData); return CreateTestMethod(testMethodData); } @@ -63,19 +66,7 @@ protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalDat CanonicalData = canonicalData, CanonicalDataCase = canonicalDataCase, Index = index, - Options = CreateTestMethodOptions(canonicalData, canonicalDataCase, index) + Options = Options }; - - protected virtual TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - => new TestMethodOptions(); - - protected virtual TestMethod CreateBooleanTestMethod(TestMethodData testMethodData) - => BooleanTestMethodGenerator.Create(testMethodData); - - protected virtual TestMethod CreateEqualityTestMethod(TestMethodData testMethodData) - => EqualityTestMethodGenerator.Create(testMethodData); - - protected virtual TestMethod CreateExceptionTestMethod(TestMethodData testMethodData) - => ExceptionTestMethodGenerator.Create(testMethodData); } } \ No newline at end of file diff --git a/generators/Exercises/NthPrime.cs b/generators/Exercises/NthPrime.cs index a4e63a6549..c79fb74fb9 100644 --- a/generators/Exercises/NthPrime.cs +++ b/generators/Exercises/NthPrime.cs @@ -1,18 +1,13 @@ using System; -using Generators.Data; -using Generators.Methods; namespace Generators.Exercises { public class NthPrime : EqualityExercise { - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + public NthPrime() { - var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); - testMethodOptions.ExceptionType = typeof(ArgumentOutOfRangeException); - testMethodOptions.ThrowExceptionWhenExpectedValueEquals = x => x is bool; - - return testMethodOptions; + Options.ExceptionType = typeof(ArgumentOutOfRangeException); + Options.ThrowExceptionWhenExpectedValueEquals = x => x is bool; } } } \ No newline at end of file diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index 41a6af4b42..59a64c250c 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -20,6 +20,6 @@ protected override TestMethodData CreateTestMethodData(CanonicalData canonicalDa } private static string GetClassification(string classificationType) - => $"Classification.{classificationType.Transform(Humanizer.To.TitleCase)}"; + => $"Classification.{classificationType.Transform(To.TitleCase)}"; } } \ No newline at end of file diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index c7c24e2ac1..6fd9374d1d 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -5,6 +5,11 @@ namespace Generators.Exercises { public class RomanNumerals : EqualityExercise { + public RomanNumerals() + { + Options.TestedMethodType = TestedMethodType.Extension; + } + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); @@ -13,13 +18,5 @@ protected override TestMethodData CreateTestMethodData(CanonicalData canonicalDa return testMethodData; } - - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodOptions = new TestMethodOptions(); - testMethodOptions.TestedMethodType = TestedMethodType.Extension; - - return testMethodOptions; - } } } \ No newline at end of file diff --git a/generators/Exercises/Wordy.cs b/generators/Exercises/Wordy.cs index dcd2c43c6d..8228db878d 100644 --- a/generators/Exercises/Wordy.cs +++ b/generators/Exercises/Wordy.cs @@ -1,16 +1,10 @@ -using Generators.Data; -using Generators.Methods; - -namespace Generators.Exercises +namespace Generators.Exercises { public class Wordy : EqualityExercise { - protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + public Wordy() { - var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); - testMethodOptions.ThrowExceptionWhenExpectedValueEquals = x => x is bool; - - return testMethodOptions; + Options.ThrowExceptionWhenExpectedValueEquals = x => x is bool; } } } \ No newline at end of file diff --git a/generators/Methods/BooleanTestMethodGenerator.cs b/generators/Methods/BooleanTestMethodGenerator.cs index ead9591bad..e47f02aefc 100644 --- a/generators/Methods/BooleanTestMethodGenerator.cs +++ b/generators/Methods/BooleanTestMethodGenerator.cs @@ -15,7 +15,7 @@ protected override IEnumerable Body case TestedMethodType.Static: return new[] { $"{Assertion}({TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: - return new[] { $"var sut = new {TestedClassName}();\n{Tab}{Assertion}(sut.{TestedMethod}({Input}));" }; + return new[] { $"var sut = new {TestedClassName}();", "{Assertion}(sut.{TestedMethod}({Input}));" }; case TestedMethodType.Extension: return new[] { $"{Assertion}({Input}.{TestedMethod}());" }; default: @@ -24,10 +24,8 @@ protected override IEnumerable Body } } - private string Assertion - => $"Assert.{Convert.ToBoolean(TestMethodData.CanonicalDataCase.Expected)}"; + private string Assertion => $"Assert.{Convert.ToBoolean(TestMethodData.CanonicalDataCase.Expected)}"; - protected override string TestedMethod - => base.TestedMethod.EnsureStartsWith("Is"); + protected override string TestedMethod => base.TestedMethod.EnsureStartsWith("Is"); } } \ No newline at end of file diff --git a/generators/Methods/EqualityTestMethodGenerator.cs b/generators/Methods/EqualityTestMethodGenerator.cs index 12fff036b2..dc39acb483 100644 --- a/generators/Methods/EqualityTestMethodGenerator.cs +++ b/generators/Methods/EqualityTestMethodGenerator.cs @@ -42,7 +42,7 @@ protected virtual string FormattedExpectedVariable if (lines.Length == 1) return lines[0]; - return "\n" + string.Join("\n", lines.Select(line => $"{Tab}{line}")); + return "\n" + string.Join("\n", lines.Select(line => $"{line}")); } } diff --git a/generators/Methods/TestMethodGenerator.cs b/generators/Methods/TestMethodGenerator.cs index 8e8a2e70c7..f924db66b2 100644 --- a/generators/Methods/TestMethodGenerator.cs +++ b/generators/Methods/TestMethodGenerator.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Generators.Helpers; using Humanizer; using To = Generators.Helpers.To; @@ -8,8 +7,6 @@ namespace Generators.Methods { public abstract class TestMethodGenerator { - protected const string Tab = " "; - public TestMethod Create(TestMethodData testMethodData) { TestMethodData = testMethodData; From 2a27dacf38295e279650fe7a86c053092b935db3 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 10:26:31 +0200 Subject: [PATCH 05/22] Namespace refactoring --- .../Classes/TestClassNameTransformer.cs | 9 ------ .../Classes/TestedClassNameTransformer.cs | 9 ------ generators/Exercises/BeerSong.cs | 4 +-- generators/Exercises/BooleanExercise.cs | 2 +- generators/Exercises/EqualityExercise.cs | 2 +- generators/Exercises/Exercise.cs | 20 ++++--------- generators/Exercises/FoodChain.cs | 4 +-- generators/Exercises/PerfectNumbers.cs | 4 +-- generators/Exercises/RomanNumerals.cs | 4 +-- generators/Helpers/To.cs | 13 -------- generators/{Data => Input}/CanonicalData.cs | 2 +- .../{Data => Input}/CanonicalDataCase.cs | 2 +- .../CanonicalDataCaseJsonConverter.cs | 2 +- .../CanonicalDataCasesJsonConverter.cs | 2 +- .../{Data => Input}/CanonicalDataParser.cs | 2 +- .../{Data => Input}/ExerciseCollection.cs | 2 +- .../Methods/TestMethodNameTransformer.cs | 23 -------------- .../Methods/TestedMethodNameTransformer.cs | 9 ------ .../BooleanTestMethodGenerator.cs | 3 +- .../EqualityTestMethodGenerator.cs | 2 +- .../ExceptionTestMethodGenerator.cs | 2 +- .../{Methods => Output}/ExpectedFormat.cs | 2 +- generators/Output/NameExtensions.cs | 30 +++++++++++++++++++ .../{Helpers => Output}/StringExtensions.cs | 5 +--- generators/{Classes => Output}/TestClass.cs | 3 +- .../{Classes => Output}/TestClassRenderer.cs | 3 +- generators/{Methods => Output}/TestMethod.cs | 2 +- .../{Methods => Output}/TestMethodData.cs | 4 +-- .../TestMethodGenerator.cs | 10 +++---- .../{Methods => Output}/TestMethodOptions.cs | 5 ++-- .../{Methods => Output}/TestMethodRenderer.cs | 2 +- .../{Methods => Output}/TestedMethodType.cs | 2 +- generators/Program.cs | 2 +- generators/TestFileGenerator.cs | 4 +-- 34 files changed, 73 insertions(+), 123 deletions(-) delete mode 100644 generators/Classes/TestClassNameTransformer.cs delete mode 100644 generators/Classes/TestedClassNameTransformer.cs delete mode 100644 generators/Helpers/To.cs rename generators/{Data => Input}/CanonicalData.cs (93%) rename generators/{Data => Input}/CanonicalDataCase.cs (94%) rename generators/{Data => Input}/CanonicalDataCaseJsonConverter.cs (97%) rename generators/{Data => Input}/CanonicalDataCasesJsonConverter.cs (97%) rename generators/{Data => Input}/CanonicalDataParser.cs (97%) rename generators/{Data => Input}/ExerciseCollection.cs (96%) delete mode 100644 generators/Methods/TestMethodNameTransformer.cs delete mode 100644 generators/Methods/TestedMethodNameTransformer.cs rename generators/{Methods => Output}/BooleanTestMethodGenerator.cs (95%) rename generators/{Methods => Output}/EqualityTestMethodGenerator.cs (98%) rename generators/{Methods => Output}/ExceptionTestMethodGenerator.cs (97%) rename generators/{Methods => Output}/ExpectedFormat.cs (80%) create mode 100644 generators/Output/NameExtensions.cs rename generators/{Helpers => Output}/StringExtensions.cs (57%) rename generators/{Classes => Output}/TestClass.cs (85%) rename generators/{Classes => Output}/TestClassRenderer.cs (94%) rename generators/{Methods => Output}/TestMethod.cs (91%) rename generators/{Methods => Output}/TestMethodData.cs (84%) rename generators/{Methods => Output}/TestMethodGenerator.cs (84%) rename generators/{Methods => Output}/TestMethodOptions.cs (79%) rename generators/{Methods => Output}/TestMethodRenderer.cs (96%) rename generators/{Methods => Output}/TestedMethodType.cs (77%) diff --git a/generators/Classes/TestClassNameTransformer.cs b/generators/Classes/TestClassNameTransformer.cs deleted file mode 100644 index d6f69e61b4..0000000000 --- a/generators/Classes/TestClassNameTransformer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Humanizer; - -namespace Generators.Classes -{ - public class TestClassNameTransformer : IStringTransformer - { - public string Transform(string input) => $"{input.Dehumanize()}Test"; - } -} \ No newline at end of file diff --git a/generators/Classes/TestedClassNameTransformer.cs b/generators/Classes/TestedClassNameTransformer.cs deleted file mode 100644 index 3d12c3a30e..0000000000 --- a/generators/Classes/TestedClassNameTransformer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Humanizer; - -namespace Generators.Classes -{ - public class TestedClassNameTransformer : IStringTransformer - { - public string Transform(string input) => input.Dehumanize(); - } -} \ No newline at end of file diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index e6f917f1cb..f99ffbbf04 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -1,5 +1,5 @@ -using Generators.Data; -using Generators.Methods; +using Generators.Input; +using Generators.Output; namespace Generators.Exercises { diff --git a/generators/Exercises/BooleanExercise.cs b/generators/Exercises/BooleanExercise.cs index 6e7fa484cb..1f9747d9f8 100644 --- a/generators/Exercises/BooleanExercise.cs +++ b/generators/Exercises/BooleanExercise.cs @@ -1,4 +1,4 @@ -using Generators.Methods; +using Generators.Output; namespace Generators.Exercises { diff --git a/generators/Exercises/EqualityExercise.cs b/generators/Exercises/EqualityExercise.cs index fcfc531721..7a69381955 100644 --- a/generators/Exercises/EqualityExercise.cs +++ b/generators/Exercises/EqualityExercise.cs @@ -1,4 +1,4 @@ -using Generators.Methods; +using Generators.Output; namespace Generators.Exercises { diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 883296ee55..94bc8a2c00 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -1,11 +1,8 @@ using System.Collections.Generic; using System.Linq; -using Generators.Classes; -using Generators.Data; -using Generators.Methods; +using Generators.Input; +using Generators.Output; using Humanizer; -using Newtonsoft.Json.Linq; -using To = Generators.Helpers.To; namespace Generators.Exercises { @@ -29,7 +26,7 @@ public TestClass CreateTestClass(CanonicalData canonicalData) { var testClass = new TestClass { - ClassName = Name.Transform(To.TestClassName), + ClassName = Name.ToTestClassName(), TestMethods = CreateTestMethods(canonicalData).ToArray(), CanonicalDataVersion = canonicalData.Version }; @@ -50,15 +47,8 @@ private static void AddTestMethodUsingNamespaces(TestClass testClass) protected virtual IEnumerable CreateTestMethods(CanonicalData canonicalData) => canonicalData.Cases.Select((t, i) => CreateTestMethod(canonicalData, t, i)); - protected virtual TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - { - var testMethodData = CreateTestMethodData(canonicalData, canonicalDataCase, index); - - if (testMethodData.CanonicalDataCase.Expected is JObject) - return ExceptionTestMethodGenerator.Create(testMethodData); - - return CreateTestMethod(testMethodData); - } + protected virtual TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + => CreateTestMethod(CreateTestMethodData(canonicalData, canonicalDataCase, index)); protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) => new TestMethodData diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index 8f33262b4d..9f051d87dd 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -1,5 +1,5 @@ -using Generators.Data; -using Generators.Methods; +using Generators.Input; +using Generators.Output; namespace Generators.Exercises { diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index 59a64c250c..ef597cb971 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -1,6 +1,6 @@ using System; -using Generators.Data; -using Generators.Methods; +using Generators.Input; +using Generators.Output; using Humanizer; namespace Generators.Exercises diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index 6fd9374d1d..b8653cb902 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -1,5 +1,5 @@ -using Generators.Data; -using Generators.Methods; +using Generators.Input; +using Generators.Output; namespace Generators.Exercises { diff --git a/generators/Helpers/To.cs b/generators/Helpers/To.cs deleted file mode 100644 index b1a03ca62e..0000000000 --- a/generators/Helpers/To.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Generators.Classes; -using Generators.Methods; - -namespace Generators.Helpers -{ - public static class To - { - public static readonly TestedClassNameTransformer TestedClassName = new TestedClassNameTransformer(); - public static readonly TestClassNameTransformer TestClassName = new TestClassNameTransformer(); - public static readonly TestedMethodNameTransformer TestedMethodName = new TestedMethodNameTransformer(); - public static readonly TestMethodNameTransformer TestMethodName = new TestMethodNameTransformer(); - } -} \ No newline at end of file diff --git a/generators/Data/CanonicalData.cs b/generators/Input/CanonicalData.cs similarity index 93% rename from generators/Data/CanonicalData.cs rename to generators/Input/CanonicalData.cs index 8d8dbe3b1e..eacb64aabe 100644 --- a/generators/Data/CanonicalData.cs +++ b/generators/Input/CanonicalData.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; -namespace Generators.Data +namespace Generators.Input { public class CanonicalData { diff --git a/generators/Data/CanonicalDataCase.cs b/generators/Input/CanonicalDataCase.cs similarity index 94% rename from generators/Data/CanonicalDataCase.cs rename to generators/Input/CanonicalDataCase.cs index 307c90b926..162f9089d0 100644 --- a/generators/Data/CanonicalDataCase.cs +++ b/generators/Input/CanonicalDataCase.cs @@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; -namespace Generators.Data +namespace Generators.Input { [JsonConverter(typeof(CanonicalDataCaseJsonConverter))] public class CanonicalDataCase diff --git a/generators/Data/CanonicalDataCaseJsonConverter.cs b/generators/Input/CanonicalDataCaseJsonConverter.cs similarity index 97% rename from generators/Data/CanonicalDataCaseJsonConverter.cs rename to generators/Input/CanonicalDataCaseJsonConverter.cs index 25b03d57da..d59948bd17 100644 --- a/generators/Data/CanonicalDataCaseJsonConverter.cs +++ b/generators/Input/CanonicalDataCaseJsonConverter.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Generators.Data +namespace Generators.Input { public class CanonicalDataCaseJsonConverter : JsonConverter { diff --git a/generators/Data/CanonicalDataCasesJsonConverter.cs b/generators/Input/CanonicalDataCasesJsonConverter.cs similarity index 97% rename from generators/Data/CanonicalDataCasesJsonConverter.cs rename to generators/Input/CanonicalDataCasesJsonConverter.cs index ab2bcf33fe..273149c41b 100644 --- a/generators/Data/CanonicalDataCasesJsonConverter.cs +++ b/generators/Input/CanonicalDataCasesJsonConverter.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Generators.Data +namespace Generators.Input { public class CanonicalDataCasesJsonConverter : JsonConverter { diff --git a/generators/Data/CanonicalDataParser.cs b/generators/Input/CanonicalDataParser.cs similarity index 97% rename from generators/Data/CanonicalDataParser.cs rename to generators/Input/CanonicalDataParser.cs index d804eacaeb..5fffcf7c0f 100644 --- a/generators/Data/CanonicalDataParser.cs +++ b/generators/Input/CanonicalDataParser.cs @@ -3,7 +3,7 @@ using System.Net.Http; using Newtonsoft.Json; -namespace Generators.Data +namespace Generators.Input { public static class CanonicalDataParser { diff --git a/generators/Data/ExerciseCollection.cs b/generators/Input/ExerciseCollection.cs similarity index 96% rename from generators/Data/ExerciseCollection.cs rename to generators/Input/ExerciseCollection.cs index b486505008..d63e3d0bfb 100644 --- a/generators/Data/ExerciseCollection.cs +++ b/generators/Input/ExerciseCollection.cs @@ -5,7 +5,7 @@ using System.Reflection; using Generators.Exercises; -namespace Generators.Data +namespace Generators.Input { public class ExerciseCollection : IEnumerable { diff --git a/generators/Methods/TestMethodNameTransformer.cs b/generators/Methods/TestMethodNameTransformer.cs deleted file mode 100644 index f75685bc9c..0000000000 --- a/generators/Methods/TestMethodNameTransformer.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Text.RegularExpressions; -using Humanizer; - -namespace Generators.Methods -{ - public class TestMethodNameTransformer : IStringTransformer - { - public string Transform(string input) - { - var methodName = Regex.Replace(input, @"[^\w]+", "_", RegexOptions.Compiled) - .Underscore() - .Transform(To.TitleCase); - - if (char.IsDigit(methodName[0])) - return "Number_" + methodName; - - if (!char.IsLetter(methodName[0])) - return "Test_"; - - return methodName; - } - } -} \ No newline at end of file diff --git a/generators/Methods/TestedMethodNameTransformer.cs b/generators/Methods/TestedMethodNameTransformer.cs deleted file mode 100644 index 1417d33b52..0000000000 --- a/generators/Methods/TestedMethodNameTransformer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Humanizer; - -namespace Generators.Methods -{ - public class TestedMethodNameTransformer : IStringTransformer - { - public string Transform(string input) => input.Dehumanize(); - } -} \ No newline at end of file diff --git a/generators/Methods/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs similarity index 95% rename from generators/Methods/BooleanTestMethodGenerator.cs rename to generators/Output/BooleanTestMethodGenerator.cs index e47f02aefc..6f86a61828 100644 --- a/generators/Methods/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -using Generators.Helpers; -namespace Generators.Methods +namespace Generators.Output { public class BooleanTestMethodGenerator : TestMethodGenerator { diff --git a/generators/Methods/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs similarity index 98% rename from generators/Methods/EqualityTestMethodGenerator.cs rename to generators/Output/EqualityTestMethodGenerator.cs index dc39acb483..84290587dc 100644 --- a/generators/Methods/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -3,7 +3,7 @@ using System.Linq; using Newtonsoft.Json.Linq; -namespace Generators.Methods +namespace Generators.Output { public class EqualityTestMethodGenerator : TestMethodGenerator { diff --git a/generators/Methods/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs similarity index 97% rename from generators/Methods/ExceptionTestMethodGenerator.cs rename to generators/Output/ExceptionTestMethodGenerator.cs index cef7769ae3..a592b2356c 100644 --- a/generators/Methods/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Generators.Methods +namespace Generators.Output { public class ExceptionTestMethodGenerator : TestMethodGenerator { diff --git a/generators/Methods/ExpectedFormat.cs b/generators/Output/ExpectedFormat.cs similarity index 80% rename from generators/Methods/ExpectedFormat.cs rename to generators/Output/ExpectedFormat.cs index 1aa23d05fd..bda252b931 100644 --- a/generators/Methods/ExpectedFormat.cs +++ b/generators/Output/ExpectedFormat.cs @@ -1,4 +1,4 @@ -namespace Generators.Methods +namespace Generators.Output { public enum ExpectedFormat { diff --git a/generators/Output/NameExtensions.cs b/generators/Output/NameExtensions.cs new file mode 100644 index 0000000000..84066b8b1b --- /dev/null +++ b/generators/Output/NameExtensions.cs @@ -0,0 +1,30 @@ +using System.Text.RegularExpressions; +using Humanizer; + +namespace Generators.Output +{ + public static class NameExtensions + { + public static string ToTestClassName(this string input) => $"{input.Dehumanize()}Test"; + + public static string ToTestedClassName(this string input) => input.Dehumanize(); + + public static string ToTestMethodName(this string input) + { + var methodName = + Regex.Replace(input.Replace(":", " is"), @"[^\w]+", "_", RegexOptions.Compiled) + .Underscore() + .Transform(To.TitleCase); + + if (char.IsDigit(methodName[0])) + return "Number_" + methodName; + + if (!char.IsLetter(methodName[0])) + return "Test_"; + + return methodName; + } + + public static string ToTestedMethodName(this string input) => input.Dehumanize(); + } +} \ No newline at end of file diff --git a/generators/Helpers/StringExtensions.cs b/generators/Output/StringExtensions.cs similarity index 57% rename from generators/Helpers/StringExtensions.cs rename to generators/Output/StringExtensions.cs index adf230c32c..eb50188cff 100644 --- a/generators/Helpers/StringExtensions.cs +++ b/generators/Output/StringExtensions.cs @@ -1,11 +1,8 @@ -namespace Generators.Helpers +namespace Generators.Output { public static class StringExtensions { public static string EnsureStartsWith(this string str, string value) => str.StartsWith(value) ? str : value + str; - - public static bool IsQuoted(this string str) - => str.StartsWith("\"") && str.EndsWith("\""); } } \ No newline at end of file diff --git a/generators/Classes/TestClass.cs b/generators/Output/TestClass.cs similarity index 85% rename from generators/Classes/TestClass.cs rename to generators/Output/TestClass.cs index 8bd4513b9a..8bc6cd6f41 100644 --- a/generators/Classes/TestClass.cs +++ b/generators/Output/TestClass.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; -using Generators.Methods; -namespace Generators.Classes +namespace Generators.Output { public class TestClass { diff --git a/generators/Classes/TestClassRenderer.cs b/generators/Output/TestClassRenderer.cs similarity index 94% rename from generators/Classes/TestClassRenderer.cs rename to generators/Output/TestClassRenderer.cs index 306444961a..9d210fb6e9 100644 --- a/generators/Classes/TestClassRenderer.cs +++ b/generators/Output/TestClassRenderer.cs @@ -1,7 +1,6 @@ using System.Linq; -using Generators.Methods; -namespace Generators.Classes +namespace Generators.Output { public static class TestClassRenderer { diff --git a/generators/Methods/TestMethod.cs b/generators/Output/TestMethod.cs similarity index 91% rename from generators/Methods/TestMethod.cs rename to generators/Output/TestMethod.cs index 3fbe802e45..f7f3a80158 100644 --- a/generators/Methods/TestMethod.cs +++ b/generators/Output/TestMethod.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Generators.Methods +namespace Generators.Output { public class TestMethod { diff --git a/generators/Methods/TestMethodData.cs b/generators/Output/TestMethodData.cs similarity index 84% rename from generators/Methods/TestMethodData.cs rename to generators/Output/TestMethodData.cs index c60e011000..c13f54bb42 100644 --- a/generators/Methods/TestMethodData.cs +++ b/generators/Output/TestMethodData.cs @@ -1,6 +1,6 @@ -using Generators.Data; +using Generators.Input; -namespace Generators.Methods +namespace Generators.Output { public class TestMethodData { diff --git a/generators/Methods/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs similarity index 84% rename from generators/Methods/TestMethodGenerator.cs rename to generators/Output/TestMethodGenerator.cs index f924db66b2..f968eb1c8f 100644 --- a/generators/Methods/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; using System.Linq; -using Humanizer; -using To = Generators.Helpers.To; -namespace Generators.Methods +namespace Generators.Output { public abstract class TestMethodGenerator { @@ -28,13 +26,13 @@ protected virtual ISet UsingNamespaces => new HashSet(); protected virtual string MethodName - => TestMethodData.CanonicalDataCase.Description.Replace(":", " is").Transform(To.TestMethodName); + => TestMethodData.CanonicalDataCase.Description.ToTestMethodName(); protected virtual string TestedClassName - => TestMethodData.CanonicalData.Exercise.Transform(To.TestedClassName); + => TestMethodData.CanonicalData.Exercise.ToTestedClassName(); protected virtual string TestedMethod - => TestMethodData.CanonicalDataCase.Property.Transform(To.TestedMethodName); + => TestMethodData.CanonicalDataCase.Property.ToTestedMethodName(); protected virtual object Input => FormatInputValue(TestMethodData.CanonicalDataCase.Input); diff --git a/generators/Methods/TestMethodOptions.cs b/generators/Output/TestMethodOptions.cs similarity index 79% rename from generators/Methods/TestMethodOptions.cs rename to generators/Output/TestMethodOptions.cs index c95c172a8f..87d777d875 100644 --- a/generators/Methods/TestMethodOptions.cs +++ b/generators/Output/TestMethodOptions.cs @@ -1,12 +1,13 @@ using System; +using Newtonsoft.Json.Linq; -namespace Generators.Methods +namespace Generators.Output { public class TestMethodOptions { public ExpectedFormat ExpectedFormat { get; set; } = ExpectedFormat.Formatted; public Type ExceptionType { get; set; } = typeof(ArgumentException); public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.Static; - public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = x => false; + public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = x => x is JObject; } } \ No newline at end of file diff --git a/generators/Methods/TestMethodRenderer.cs b/generators/Output/TestMethodRenderer.cs similarity index 96% rename from generators/Methods/TestMethodRenderer.cs rename to generators/Output/TestMethodRenderer.cs index fbd71f1c28..14fa9bd1b5 100644 --- a/generators/Methods/TestMethodRenderer.cs +++ b/generators/Output/TestMethodRenderer.cs @@ -1,6 +1,6 @@ using System.Linq; -namespace Generators.Methods +namespace Generators.Output { public static class TestMethodRenderer { diff --git a/generators/Methods/TestedMethodType.cs b/generators/Output/TestedMethodType.cs similarity index 77% rename from generators/Methods/TestedMethodType.cs rename to generators/Output/TestedMethodType.cs index 90a66e2875..95c9c2becc 100644 --- a/generators/Methods/TestedMethodType.cs +++ b/generators/Output/TestedMethodType.cs @@ -1,4 +1,4 @@ -namespace Generators.Methods +namespace Generators.Output { public enum TestedMethodType { diff --git a/generators/Program.cs b/generators/Program.cs index 1aa55ea12a..c2f06a10cb 100644 --- a/generators/Program.cs +++ b/generators/Program.cs @@ -1,4 +1,4 @@ -using Generators.Data; +using Generators.Input; using Serilog; namespace Generators diff --git a/generators/TestFileGenerator.cs b/generators/TestFileGenerator.cs index 41224a14b8..3310d1f067 100644 --- a/generators/TestFileGenerator.cs +++ b/generators/TestFileGenerator.cs @@ -1,7 +1,7 @@ using System.IO; -using Generators.Classes; -using Generators.Data; using Generators.Exercises; +using Generators.Input; +using Generators.Output; using Serilog; namespace Generators From ee45af0f30d660893c733821e0b246edf2304d54 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 11:20:37 +0200 Subject: [PATCH 06/22] Use dotliquid template engine --- exercises/beer-song/BeerSongTest.cs | 16 ++++---- exercises/food-chain/FoodChainTest.cs | 20 +++++----- generators/Exercises/Exercise.cs | 6 +-- generators/Generators.csproj | 6 +++ .../Output/BooleanTestMethodGenerator.cs | 2 +- .../Output/EqualityTestMethodGenerator.cs | 8 ++-- .../Output/ExceptionTestMethodGenerator.cs | 2 +- generators/Output/TestClass.liquid | 20 ++++++++++ generators/Output/TestClassRenderer.cs | 38 +++++++++---------- generators/Output/TestMethodRenderer.cs | 26 ------------- 10 files changed, 70 insertions(+), 74 deletions(-) create mode 100644 generators/Output/TestClass.liquid delete mode 100644 generators/Output/TestMethodRenderer.cs diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index 29292e7783..babc74aceb 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -11,7 +11,7 @@ public void First_generic_verse() ""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" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verse(99)); } [Fact(Skip = "Remove to run test")] @@ -21,7 +21,7 @@ public void Last_generic_verse() ""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" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verse(3)); } [Fact(Skip = "Remove to run test")] @@ -31,7 +31,7 @@ public void Verse_2() ""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" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verse(2)); } [Fact(Skip = "Remove to run test")] @@ -41,7 +41,7 @@ public void Verse_1() ""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" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verse(1)); } [Fact(Skip = "Remove to run test")] @@ -51,7 +51,7 @@ public void Verse_0() ""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.\n" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verse(0)); } [Fact(Skip = "Remove to run test")] @@ -64,7 +64,7 @@ public void First_two_verses() "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" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verses(99, 98)); } [Fact(Skip = "Remove to run test")] @@ -80,7 +80,7 @@ public void Last_three_verses() "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.\n" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verses(2, 0)); } [Fact(Skip = "Remove to run test")] @@ -387,6 +387,6 @@ public void All_verses() "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.\n" + """; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, BeerSong.Verses(99, 0)); } } \ No newline at end of file diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index 8fbff3e65f..6597a943aa 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -10,7 +10,7 @@ public void Fly() var expected = "I know an old lady who swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(1)); } [Fact(Skip = "Remove to run test")] @@ -21,7 +21,7 @@ public void Spider() "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(2)); } [Fact(Skip = "Remove to run test")] @@ -33,7 +33,7 @@ public void Bird() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(3)); } [Fact(Skip = "Remove to run test")] @@ -46,7 +46,7 @@ public void Cat() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(4)); } [Fact(Skip = "Remove to run test")] @@ -60,7 +60,7 @@ public void Dog() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(5)); } [Fact(Skip = "Remove to run test")] @@ -75,7 +75,7 @@ public void Goat() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(6)); } [Fact(Skip = "Remove to run test")] @@ -91,7 +91,7 @@ public void Cow() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(7)); } [Fact(Skip = "Remove to run test")] @@ -100,7 +100,7 @@ public void Horse() var expected = "I know an old lady who swallowed a horse.\n" + "She's dead, of course!"; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(8)); } [Fact(Skip = "Remove to run test")] @@ -120,7 +120,7 @@ public void Multiple_verses() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(1, 3)); } [Fact(Skip = "Remove to run test")] @@ -177,6 +177,6 @@ public void Full_song() "\n" + "I know an old lady who swallowed a horse.\n" + "She's dead, of course!"; - Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input})); + Assert.Equal(expected, FoodChain.Verse(1, 8)); } } \ No newline at end of file diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 94bc8a2c00..865aad9fc3 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -44,10 +44,10 @@ private static void AddTestMethodUsingNamespaces(TestClass testClass) protected abstract TestMethod CreateTestMethod(TestMethodData testMethodData); - protected virtual IEnumerable CreateTestMethods(CanonicalData canonicalData) + private IEnumerable CreateTestMethods(CanonicalData canonicalData) => canonicalData.Cases.Select((t, i) => CreateTestMethod(canonicalData, t, i)); - - protected virtual TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + + private TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) => CreateTestMethod(CreateTestMethodData(canonicalData, canonicalDataCase, index)); protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) diff --git a/generators/Generators.csproj b/generators/Generators.csproj index 463f556f48..4668aa5edc 100644 --- a/generators/Generators.csproj +++ b/generators/Generators.csproj @@ -4,9 +4,15 @@ netcoreapp1.1 + + + + Always + + \ No newline at end of file diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index 6f86a61828..c71d6fbd4f 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -14,7 +14,7 @@ protected override IEnumerable Body case TestedMethodType.Static: return new[] { $"{Assertion}({TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: - return new[] { $"var sut = new {TestedClassName}();", "{Assertion}(sut.{TestedMethod}({Input}));" }; + return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethod}({Input}));" }; case TestedMethodType.Extension: return new[] { $"{Assertion}({Input}.{TestedMethod}());" }; default: diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index 84290587dc..099a55d725 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -15,17 +15,17 @@ protected override IEnumerable Body { case TestedMethodType.Static: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", "Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input}));" }; + return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input}));" }; return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", "var sut = new {TestedClassName}();", "Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; + return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; - return new[] { $"var sut = new {TestedClassName}();", "Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; + return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; case TestedMethodType.Extension: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", "Assert.Equal(expected, {Input}.{TestedMethod}());" }; + return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethod}());" }; return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethod}());" }; default: diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index a592b2356c..121610961d 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -14,7 +14,7 @@ protected override IEnumerable Body case TestedMethodType.Static: return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethod}({Input}));" }; case TestedMethodType.Instance: - return new[] { $"var sut = new {TestedClassName}();", "Assert.Throws<{ExceptionType}>(() => sut.{TestedMethod}({Input}));;" }; + return new[] { $"var sut = new {TestedClassName}();", $"Assert.Throws<{ExceptionType}>(() => sut.{TestedMethod}({Input}));;" }; case TestedMethodType.Extension: return new[] { $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethod}());" }; default: diff --git a/generators/Output/TestClass.liquid b/generators/Output/TestClass.liquid new file mode 100644 index 0000000000..c779f058e0 --- /dev/null +++ b/generators/Output/TestClass.liquid @@ -0,0 +1,20 @@ +// This file was auto-generated based on version {{CanonicalDataVersion}} of the canonical data. + +{%- for namespace in UsingNamespaces -%} +using {{ namespace }}; +{%- endfor -%} + +public class {{ClassName}} +{ +{%- for testMethod in TestMethods -%} + [Fact{% if forloop.first == false %}(Skip = "Remove to run test"){% endif %}] + public void {{testMethod.Name}}() + { + {%- for line in testMethod.Body -%} + {{ line }} + {%- endfor -%} + } +{%- if forloop.last == false %} +{% endif -%} +{%- endfor -%} +} \ No newline at end of file diff --git a/generators/Output/TestClassRenderer.cs b/generators/Output/TestClassRenderer.cs index 9d210fb6e9..52ddf707d8 100644 --- a/generators/Output/TestClassRenderer.cs +++ b/generators/Output/TestClassRenderer.cs @@ -1,30 +1,26 @@ -using System.Linq; +using System.IO; +using System.Linq; +using DotLiquid; namespace Generators.Output { public static class TestClassRenderer { - private const string TestClassTemplate = -@"// This file was auto-generated based on version {CanonicalDataVersion} of the canonical data. + private static readonly Template TestClassTemplate = Template.Parse(GetTemplateContents()); -{UsingNamespaces} + public static string Render(TestClass testClass) + { + var templateData = new + { + CanonicalDataVersion = testClass.CanonicalDataVersion, + UsingNamespaces = testClass.UsingNamespaces, + ClassName = testClass.ClassName, + TestMethods = testClass.TestMethods.Select(testMethod => new { Name = testMethod.MethodName, Body = testMethod.Body }) + }; + + return TestClassTemplate.Render(Hash.FromAnonymousObject(templateData)); + } -public class {ClassName} -{ -{Body} -}"; - - public static string Render(TestClass testClass) => - TestClassTemplate - .Replace("{CanonicalDataVersion}", testClass.CanonicalDataVersion) - .Replace("{UsingNamespaces}", RenderUsingNamespaces(testClass)) - .Replace("{ClassName}", testClass.ClassName) - .Replace("{Body}", RenderBody(testClass)); - - private static string RenderUsingNamespaces(TestClass testClass) => - string.Join("\n", testClass.UsingNamespaces.Select(usingNamespace => $"using {usingNamespace};")); - - private static string RenderBody(TestClass testClass) => - string.Join("\n\n", testClass.TestMethods.Select(TestMethodRenderer.Render)); + private static string GetTemplateContents() => File.ReadAllText(Path.Combine("Output", "TestClass.liquid")); } } diff --git a/generators/Output/TestMethodRenderer.cs b/generators/Output/TestMethodRenderer.cs deleted file mode 100644 index 14fa9bd1b5..0000000000 --- a/generators/Output/TestMethodRenderer.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Linq; - -namespace Generators.Output -{ - public static class TestMethodRenderer - { - private const string Tab = " "; - - private const string TestMethodTemplate = -@"{Tab}[Fact{Skip}] -{Tab}public void {Name}() -{Tab}{ -{Body} -{Tab}}"; - - public static string Render(TestMethod testMethod) => - TestMethodTemplate - .Replace("{Tab}", Tab) - .Replace("{Name}", testMethod.MethodName) - .Replace("{Body}", RenderBody(testMethod)) - .Replace("{Skip}", testMethod.Index == 0 ? "" : "(Skip = \"Remove to run test\")"); - - private static string RenderBody(TestMethod testMethod) - => string.Join("\n", testMethod.Body.Select(line => $"{Tab}{Tab}{line}")); - } -} From 952face2de1229698ad4d4d2fc15ada7013211c6 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 11:31:15 +0200 Subject: [PATCH 07/22] Remove unused body --- generators/Exercises/BeerSong.cs | 4 ++-- generators/Exercises/Exercise.cs | 15 +++++---------- generators/Exercises/FoodChain.cs | 4 ++-- generators/Exercises/PerfectNumbers.cs | 4 ++-- generators/Exercises/RomanNumerals.cs | 4 ++-- generators/Output/TestMethod.cs | 1 - generators/Output/TestMethodData.cs | 1 - generators/Output/TestMethodGenerator.cs | 5 ++--- 8 files changed, 15 insertions(+), 23 deletions(-) diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index f99ffbbf04..0240040cb1 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -5,9 +5,9 @@ namespace Generators.Exercises { public class BeerSong : EqualityExercise { - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); + var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); testMethodData.Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; return testMethodData; diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 865aad9fc3..165bdcc830 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Generators.Input; using Generators.Output; using Humanizer; @@ -27,7 +26,7 @@ public TestClass CreateTestClass(CanonicalData canonicalData) var testClass = new TestClass { ClassName = Name.ToTestClassName(), - TestMethods = CreateTestMethods(canonicalData).ToArray(), + TestMethods = canonicalData.Cases.Select((t, i) => CreateTestMethod(canonicalData, t)).ToArray(), CanonicalDataVersion = canonicalData.Version }; @@ -44,18 +43,14 @@ private static void AddTestMethodUsingNamespaces(TestClass testClass) protected abstract TestMethod CreateTestMethod(TestMethodData testMethodData); - private IEnumerable CreateTestMethods(CanonicalData canonicalData) - => canonicalData.Cases.Select((t, i) => CreateTestMethod(canonicalData, t, i)); + private TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) + => CreateTestMethod(CreateTestMethodData(canonicalData, canonicalDataCase)); - private TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) - => CreateTestMethod(CreateTestMethodData(canonicalData, canonicalDataCase, index)); - - protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) => new TestMethodData { CanonicalData = canonicalData, CanonicalDataCase = canonicalDataCase, - Index = index, Options = Options }; } diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index 9f051d87dd..f2cc64df99 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -5,9 +5,9 @@ namespace Generators.Exercises { public class FoodChain : EqualityExercise { - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); + var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); testMethodData.Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; return testMethodData; diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index ef597cb971..2eac8aef51 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -7,9 +7,9 @@ namespace Generators.Exercises { public class PerfectNumbers : EqualityExercise { - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); + var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); testMethodData.Options.ExceptionType = typeof(ArgumentOutOfRangeException); testMethodData.Options.ExpectedFormat = ExpectedFormat.Unformatted; diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index b8653cb902..7b8a683fc2 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -10,9 +10,9 @@ public RomanNumerals() Options.TestedMethodType = TestedMethodType.Extension; } - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index); + var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); testMethodData.CanonicalDataCase.Property = "ToRoman"; testMethodData.CanonicalDataCase.Description = "Number_" + testMethodData.CanonicalDataCase.Description; diff --git a/generators/Output/TestMethod.cs b/generators/Output/TestMethod.cs index f7f3a80158..ff7856984d 100644 --- a/generators/Output/TestMethod.cs +++ b/generators/Output/TestMethod.cs @@ -7,6 +7,5 @@ public class TestMethod public ISet UsingNamespaces { get; set; } = new HashSet(); public string MethodName { get; set; } public IEnumerable Body { get; set; } - public int Index { get; set; } } } \ No newline at end of file diff --git a/generators/Output/TestMethodData.cs b/generators/Output/TestMethodData.cs index c13f54bb42..4b2f2f0e1a 100644 --- a/generators/Output/TestMethodData.cs +++ b/generators/Output/TestMethodData.cs @@ -6,7 +6,6 @@ public class TestMethodData { public CanonicalData CanonicalData { get; set; } public CanonicalDataCase CanonicalDataCase { get; set;} - public int Index { get; set; } public TestMethodOptions Options { get; set; } = new TestMethodOptions(); } } \ No newline at end of file diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index f968eb1c8f..ac7958253c 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -11,10 +11,9 @@ public TestMethod Create(TestMethodData testMethodData) return new TestMethod { + UsingNamespaces = UsingNamespaces, MethodName = MethodName, - Body = Body, - Index = TestMethodData.Index, - UsingNamespaces = UsingNamespaces + Body = Body }; } From 6f4d4a0b02160a45183f96aa9bd349341c557d45 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 12:00:48 +0200 Subject: [PATCH 08/22] Simplify options --- exercises/leap/LeapTest.cs | 8 +++--- exercises/luhn/LuhnTest.cs | 26 +++++++++---------- generators/Exercises/BeerSong.cs | 10 +++---- generators/Exercises/FoodChain.cs | 10 +++---- generators/Exercises/PerfectNumbers.cs | 8 ++++-- .../Output/BooleanTestMethodGenerator.cs | 8 +++--- .../Output/EqualityTestMethodGenerator.cs | 12 ++++----- .../Output/ExceptionTestMethodGenerator.cs | 6 ++--- generators/Output/TestMethodGenerator.cs | 21 +++++++-------- 9 files changed, 50 insertions(+), 59 deletions(-) diff --git a/exercises/leap/LeapTest.cs b/exercises/leap/LeapTest.cs index e4676a3ad8..2ca2bf479f 100644 --- a/exercises/leap/LeapTest.cs +++ b/exercises/leap/LeapTest.cs @@ -7,24 +7,24 @@ public class LeapTest [Fact] public void Year_not_divisible_by_4_is_common_year() { - Assert.False(Leap.IsLeapYear(2015)); + Assert.False(Leap.LeapYear(2015)); } [Fact(Skip = "Remove to run test")] public void Year_divisible_by_4_not_divisible_by_100_is_leap_year() { - Assert.True(Leap.IsLeapYear(2016)); + Assert.True(Leap.LeapYear(2016)); } [Fact(Skip = "Remove to run test")] public void Year_divisible_by_100_not_divisible_by_400_is_common_year() { - Assert.False(Leap.IsLeapYear(2100)); + Assert.False(Leap.LeapYear(2100)); } [Fact(Skip = "Remove to run test")] public void Year_divisible_by_400_is_leap_year() { - Assert.True(Leap.IsLeapYear(2000)); + Assert.True(Leap.LeapYear(2000)); } } \ No newline at end of file diff --git a/exercises/luhn/LuhnTest.cs b/exercises/luhn/LuhnTest.cs index 6f48d6f9bc..56a2576aeb 100644 --- a/exercises/luhn/LuhnTest.cs +++ b/exercises/luhn/LuhnTest.cs @@ -7,78 +7,78 @@ public class LuhnTest [Fact] public void Single_digit_strings_can_not_be_valid() { - Assert.False(Luhn.IsValid("1")); + Assert.False(Luhn.Valid("1")); } [Fact(Skip = "Remove to run test")] public void A_single_zero_is_invalid() { - Assert.False(Luhn.IsValid("0")); + Assert.False(Luhn.Valid("0")); } [Fact(Skip = "Remove to run test")] public void A_simple_valid_sin_that_remains_valid_if_reversed() { - Assert.True(Luhn.IsValid("059")); + Assert.True(Luhn.Valid("059")); } [Fact(Skip = "Remove to run test")] public void A_simple_valid_sin_that_becomes_invalid_if_reversed() { - Assert.True(Luhn.IsValid("59")); + Assert.True(Luhn.Valid("59")); } [Fact(Skip = "Remove to run test")] public void A_valid_canadian_sin() { - Assert.True(Luhn.IsValid("055 444 285")); + Assert.True(Luhn.Valid("055 444 285")); } [Fact(Skip = "Remove to run test")] public void Invalid_canadian_sin() { - Assert.False(Luhn.IsValid("055 444 286")); + Assert.False(Luhn.Valid("055 444 286")); } [Fact(Skip = "Remove to run test")] public void Invalid_credit_card() { - Assert.False(Luhn.IsValid("8273 1232 7352 0569")); + Assert.False(Luhn.Valid("8273 1232 7352 0569")); } [Fact(Skip = "Remove to run test")] public void Valid_strings_with_a_non_digit_included_become_invalid() { - Assert.False(Luhn.IsValid("055a 444 285")); + Assert.False(Luhn.Valid("055a 444 285")); } [Fact(Skip = "Remove to run test")] public void Valid_strings_with_punctuation_included_become_invalid() { - Assert.False(Luhn.IsValid("055-444-285")); + Assert.False(Luhn.Valid("055-444-285")); } [Fact(Skip = "Remove to run test")] public void Valid_strings_with_symbols_included_become_invalid() { - Assert.False(Luhn.IsValid("055£ 444$ 285")); + Assert.False(Luhn.Valid("055£ 444$ 285")); } [Fact(Skip = "Remove to run test")] public void Single_zero_with_space_is_invalid() { - Assert.False(Luhn.IsValid(" 0")); + Assert.False(Luhn.Valid(" 0")); } [Fact(Skip = "Remove to run test")] public void More_than_a_single_zero_is_valid() { - Assert.True(Luhn.IsValid("0000 0")); + Assert.True(Luhn.Valid("0000 0")); } [Fact(Skip = "Remove to run test")] public void Input_digit_9_is_correctly_converted_to_output_digit_9() { - Assert.True(Luhn.IsValid("091")); + Assert.True(Luhn.Valid("091")); } } \ No newline at end of file diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index 0240040cb1..c6d932e63d 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -1,16 +1,12 @@ -using Generators.Input; -using Generators.Output; +using Generators.Output; namespace Generators.Exercises { public class BeerSong : EqualityExercise { - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) + public BeerSong() { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); - testMethodData.Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; - - return testMethodData; + Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; } } } \ No newline at end of file diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index f2cc64df99..30c11c0248 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -1,16 +1,12 @@ -using Generators.Input; -using Generators.Output; +using Generators.Output; namespace Generators.Exercises { public class FoodChain : EqualityExercise { - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) + public FoodChain() { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); - testMethodData.Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; - - return testMethodData; + Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; } } } \ No newline at end of file diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index 2eac8aef51..ad5dff83e7 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -7,11 +7,15 @@ namespace Generators.Exercises { public class PerfectNumbers : EqualityExercise { + public PerfectNumbers() + { + Options.ExceptionType = typeof(ArgumentOutOfRangeException); + Options.ExpectedFormat = ExpectedFormat.Unformatted; + } + protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) { var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); - testMethodData.Options.ExceptionType = typeof(ArgumentOutOfRangeException); - testMethodData.Options.ExpectedFormat = ExpectedFormat.Unformatted; if (testMethodData.CanonicalDataCase.Expected is string classificationType) testMethodData.CanonicalDataCase.Expected = GetClassification(classificationType); diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index c71d6fbd4f..ca614a4716 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -12,11 +12,11 @@ protected override IEnumerable Body switch (TestMethodData.Options.TestedMethodType) { case TestedMethodType.Static: - return new[] { $"{Assertion}({TestedClassName}.{TestedMethod}({Input}));" }; + return new[] { $"{Assertion}({TestedClassName}.{TestedMethodName}({Input}));" }; case TestedMethodType.Instance: - return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethod}({Input}));" }; + return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethodName}({Input}));" }; case TestedMethodType.Extension: - return new[] { $"{Assertion}({Input}.{TestedMethod}());" }; + return new[] { $"{Assertion}({Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); } @@ -24,7 +24,5 @@ protected override IEnumerable Body } private string Assertion => $"Assert.{Convert.ToBoolean(TestMethodData.CanonicalDataCase.Expected)}"; - - protected override string TestedMethod => base.TestedMethod.EnsureStartsWith("Is"); } } \ No newline at end of file diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index 099a55d725..b06832f05f 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -15,19 +15,19 @@ protected override IEnumerable Body { case TestedMethodType.Static: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethod}({Input}));" }; + return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethodName}({Input}));" }; - return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethod}({Input}));" }; + return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethodName}({Input}));" }; case TestedMethodType.Instance: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; + return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; - return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethod}({Input}));" }; + return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; case TestedMethodType.Extension: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethod}());" }; + return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethodName}());" }; - return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethod}());" }; + return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); } diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index 121610961d..81a5ca5ba1 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -12,11 +12,11 @@ protected override IEnumerable Body switch (TestMethodData.Options.TestedMethodType) { case TestedMethodType.Static: - return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethod}({Input}));" }; + return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethodName}({Input}));" }; case TestedMethodType.Instance: - return new[] { $"var sut = new {TestedClassName}();", $"Assert.Throws<{ExceptionType}>(() => sut.{TestedMethod}({Input}));;" }; + return new[] { $"var sut = new {TestedClassName}();", $"Assert.Throws<{ExceptionType}>(() => sut.{TestedMethodName}({Input}));;" }; case TestedMethodType.Extension: - return new[] { $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethod}());" }; + return new[] { $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); } diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index ac7958253c..2709cabec5 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -24,18 +24,15 @@ public TestMethod Create(TestMethodData testMethodData) protected virtual ISet UsingNamespaces => new HashSet(); - protected virtual string MethodName - => TestMethodData.CanonicalDataCase.Description.ToTestMethodName(); + protected string TestedClassName => TestMethodData.CanonicalData.Exercise.ToTestedClassName(); - protected virtual string TestedClassName - => TestMethodData.CanonicalData.Exercise.ToTestedClassName(); + protected string TestedMethodName => TestMethodData.CanonicalDataCase.Property.ToTestedMethodName(); - protected virtual string TestedMethod - => TestMethodData.CanonicalDataCase.Property.ToTestedMethodName(); + protected object Input => FormatInputValue(TestMethodData.CanonicalDataCase.Input); - protected virtual object Input => FormatInputValue(TestMethodData.CanonicalDataCase.Input); - - protected virtual object FormatInputValue(object val) + protected string MethodName => TestMethodData.CanonicalDataCase.Description.ToTestMethodName(); + + protected object FormatInputValue(object val) { switch (val) { @@ -48,12 +45,12 @@ protected virtual object FormatInputValue(object val) } } - protected virtual object Expected => - TestMethodData.Options.ExpectedFormat == ExpectedFormat.Unformatted + protected object Expected => + TestMethodData.Options.ExpectedFormat == ExpectedFormat.Unformatted ? TestMethodData.CanonicalDataCase.Expected : FormatExpectedValue(TestMethodData.CanonicalDataCase.Expected); - protected virtual object FormatExpectedValue(object val) + protected object FormatExpectedValue(object val) { switch (val) { From 3be3c844be15c26da7f17c20a01dfc1edba2bece Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 12:15:08 +0200 Subject: [PATCH 09/22] Simplified objects --- generators/Exercises/BooleanExercise.cs | 4 +-- generators/Exercises/EqualityExercise.cs | 4 +-- generators/Exercises/Exercise.cs | 33 ++++++++++---------- generators/Exercises/PerfectNumbers.cs | 18 ++++------- generators/Exercises/RomanNumerals.cs | 16 ++++------ generators/{ => Output}/TestFileGenerator.cs | 12 ++----- generators/Output/TestMethodGenerator.cs | 9 +++--- generators/Program.cs | 1 + 8 files changed, 39 insertions(+), 58 deletions(-) rename generators/{ => Output}/TestFileGenerator.cs (75%) diff --git a/generators/Exercises/BooleanExercise.cs b/generators/Exercises/BooleanExercise.cs index 1f9747d9f8..7c0af6f9c1 100644 --- a/generators/Exercises/BooleanExercise.cs +++ b/generators/Exercises/BooleanExercise.cs @@ -7,9 +7,9 @@ public abstract class BooleanExercise : Exercise protected override TestMethod CreateTestMethod(TestMethodData testMethodData) { if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return ExceptionTestMethodGenerator.Create(testMethodData); + return ExceptionTestMethod.Create(testMethodData); - return BooleanTestMethodGenerator.Create(testMethodData); + return BooleanTestMethod.Create(testMethodData); } } } \ No newline at end of file diff --git a/generators/Exercises/EqualityExercise.cs b/generators/Exercises/EqualityExercise.cs index 7a69381955..2b042de6d9 100644 --- a/generators/Exercises/EqualityExercise.cs +++ b/generators/Exercises/EqualityExercise.cs @@ -7,9 +7,9 @@ public abstract class EqualityExercise : Exercise protected override TestMethod CreateTestMethod(TestMethodData testMethodData) { if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return ExceptionTestMethodGenerator.Create(testMethodData); + return ExceptionTestMethod.Create(testMethodData); - return EqualityTestMethodGenerator.Create(testMethodData); + return EqualityTestMethod.Create(testMethodData); } } } \ No newline at end of file diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 165bdcc830..f2f670d292 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -7,27 +7,28 @@ namespace Generators.Exercises { public abstract class Exercise { - protected static readonly BooleanTestMethodGenerator BooleanTestMethodGenerator = new BooleanTestMethodGenerator(); - protected static readonly EqualityTestMethodGenerator EqualityTestMethodGenerator = new EqualityTestMethodGenerator(); - protected static readonly ExceptionTestMethodGenerator ExceptionTestMethodGenerator = new ExceptionTestMethodGenerator(); + protected static readonly BooleanTestMethodGenerator BooleanTestMethod = new BooleanTestMethodGenerator(); + protected static readonly EqualityTestMethodGenerator EqualityTestMethod = new EqualityTestMethodGenerator(); + protected static readonly ExceptionTestMethodGenerator ExceptionTestMethod = new ExceptionTestMethodGenerator(); protected Exercise() { Name = GetType().Name.Kebaberize(); + CanonicalData = CanonicalDataParser.Parse(Name); Options = new TestMethodOptions(); } public string Name { get; } + public CanonicalData CanonicalData { get; } + public TestMethodOptions Options { get; } - protected TestMethodOptions Options { get; } - - public TestClass CreateTestClass(CanonicalData canonicalData) + public TestClass CreateTestClass() { var testClass = new TestClass { ClassName = Name.ToTestClassName(), - TestMethods = canonicalData.Cases.Select((t, i) => CreateTestMethod(canonicalData, t)).ToArray(), - CanonicalDataVersion = canonicalData.Version + TestMethods = CanonicalData.Cases.Select(CreateTestMethod).ToArray(), + CanonicalDataVersion = CanonicalData.Version }; AddTestMethodUsingNamespaces(testClass); @@ -43,15 +44,13 @@ private static void AddTestMethodUsingNamespaces(TestClass testClass) protected abstract TestMethod CreateTestMethod(TestMethodData testMethodData); - private TestMethod CreateTestMethod(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) - => CreateTestMethod(CreateTestMethodData(canonicalData, canonicalDataCase)); + private TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase) => CreateTestMethod(CreateTestMethodData(canonicalDataCase)); - protected virtual TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) - => new TestMethodData - { - CanonicalData = canonicalData, - CanonicalDataCase = canonicalDataCase, - Options = Options - }; + private TestMethodData CreateTestMethodData(CanonicalDataCase canonicalDataCase) => new TestMethodData + { + CanonicalData = CanonicalData, + CanonicalDataCase = canonicalDataCase, + Options = Options + }; } } \ No newline at end of file diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index ad5dff83e7..552fc5953a 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -1,5 +1,4 @@ using System; -using Generators.Input; using Generators.Output; using Humanizer; @@ -11,19 +10,14 @@ public PerfectNumbers() { Options.ExceptionType = typeof(ArgumentOutOfRangeException); Options.ExpectedFormat = ExpectedFormat.Unformatted; - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) - { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); - - if (testMethodData.CanonicalDataCase.Expected is string classificationType) - testMethodData.CanonicalDataCase.Expected = GetClassification(classificationType); - return testMethodData; + foreach (var canonicalDataCase in CanonicalData.Cases) + { + if (canonicalDataCase.Expected is string classificationType) + canonicalDataCase.Expected = GetClassification(classificationType); + } } - private static string GetClassification(string classificationType) - => $"Classification.{classificationType.Transform(To.TitleCase)}"; + private static string GetClassification(string classificationType) => $"Classification.{classificationType.Transform(To.TitleCase)}"; } } \ No newline at end of file diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index 7b8a683fc2..c51a8426ed 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -1,5 +1,4 @@ -using Generators.Input; -using Generators.Output; +using Generators.Output; namespace Generators.Exercises { @@ -8,15 +7,12 @@ public class RomanNumerals : EqualityExercise public RomanNumerals() { Options.TestedMethodType = TestedMethodType.Extension; - } - - protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase) - { - var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase); - testMethodData.CanonicalDataCase.Property = "ToRoman"; - testMethodData.CanonicalDataCase.Description = "Number_" + testMethodData.CanonicalDataCase.Description; - return testMethodData; + foreach (var canonicalDataCase in CanonicalData.Cases) + { + canonicalDataCase.Property = "ToRoman"; + canonicalDataCase.Description = "Number_" + canonicalDataCase.Description; + } } } } \ No newline at end of file diff --git a/generators/TestFileGenerator.cs b/generators/Output/TestFileGenerator.cs similarity index 75% rename from generators/TestFileGenerator.cs rename to generators/Output/TestFileGenerator.cs index 3310d1f067..5a552baf45 100644 --- a/generators/TestFileGenerator.cs +++ b/generators/Output/TestFileGenerator.cs @@ -1,16 +1,14 @@ using System.IO; using Generators.Exercises; -using Generators.Input; -using Generators.Output; using Serilog; -namespace Generators +namespace Generators.Output { public static class TestFileGenerator { public static void Generate(Exercise exercise) { - var testClass = CreateTestClass(exercise); + var testClass = exercise.CreateTestClass(); var testClassContents = TestClassRenderer.Render(testClass); var testClassFilePath = TestFilePath(exercise, testClass); @@ -18,12 +16,6 @@ public static void Generate(Exercise exercise) Log.Information("Generated tests for {Exercise} exercise in {TestFile}.", exercise.Name, testClassFilePath); } - private static TestClass CreateTestClass(Exercise exercise) - { - var canonicalData = CanonicalDataParser.Parse(exercise.Name); - return exercise.CreateTestClass(canonicalData); - } - private static void SaveTestClassContentsToFile(string testClassFilePath, string testClassContents) { Directory.CreateDirectory(Path.GetDirectoryName(testClassFilePath)); diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index 2709cabec5..9e3572a750 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -12,7 +12,7 @@ public TestMethod Create(TestMethodData testMethodData) return new TestMethod { UsingNamespaces = UsingNamespaces, - MethodName = MethodName, + MethodName = TestMethodName, Body = Body }; } @@ -21,16 +21,15 @@ public TestMethod Create(TestMethodData testMethodData) protected abstract IEnumerable Body { get; } - protected virtual ISet UsingNamespaces - => new HashSet(); + protected virtual ISet UsingNamespaces => new HashSet(); + + protected string TestMethodName => TestMethodData.CanonicalDataCase.Description.ToTestMethodName(); protected string TestedClassName => TestMethodData.CanonicalData.Exercise.ToTestedClassName(); protected string TestedMethodName => TestMethodData.CanonicalDataCase.Property.ToTestedMethodName(); protected object Input => FormatInputValue(TestMethodData.CanonicalDataCase.Input); - - protected string MethodName => TestMethodData.CanonicalDataCase.Description.ToTestMethodName(); protected object FormatInputValue(object val) { diff --git a/generators/Program.cs b/generators/Program.cs index c2f06a10cb..ae0239b832 100644 --- a/generators/Program.cs +++ b/generators/Program.cs @@ -1,4 +1,5 @@ using Generators.Input; +using Generators.Output; using Serilog; namespace Generators From 64b5006e98bf2705f40da073e3172714e7de1a80 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 19:53:40 +0200 Subject: [PATCH 10/22] Remove exercise inheritance --- generators/Exercises/Acronym.cs | 2 +- generators/Exercises/AtbashCipher.cs | 2 +- generators/Exercises/BeerSong.cs | 2 +- generators/Exercises/Bob.cs | 2 +- generators/Exercises/BooleanExercise.cs | 15 --------------- generators/Exercises/EqualityExercise.cs | 15 --------------- generators/Exercises/Exercise.cs | 15 ++++++++++++--- .../ExerciseConfiguration.cs} | 8 +++++--- generators/Exercises/FoodChain.cs | 2 +- generators/Exercises/HelloWorld.cs | 2 +- generators/Exercises/Isogram.cs | 8 +++++++- generators/Exercises/Leap.cs | 10 ++++++++-- generators/Exercises/Luhn.cs | 8 +++++++- generators/Exercises/NthPrime.cs | 2 +- generators/Exercises/PerfectNumbers.cs | 2 +- generators/Exercises/PigLatin.cs | 2 +- generators/Exercises/Raindrops.cs | 2 +- generators/Exercises/RomanNumerals.cs | 4 ++-- generators/Exercises/RotationalCipher.cs | 2 +- generators/Exercises/Wordy.cs | 2 +- generators/Output/BooleanTestMethodGenerator.cs | 8 ++++---- generators/Output/EqualityTestMethodGenerator.cs | 8 ++++---- generators/Output/ExceptionTestMethodGenerator.cs | 8 ++++---- generators/Output/TestMethodData.cs | 3 ++- generators/Output/TestedMethodFormat.cs | 9 +++++++++ generators/Output/TestedMethodType.cs | 5 ++--- 26 files changed, 78 insertions(+), 70 deletions(-) delete mode 100644 generators/Exercises/BooleanExercise.cs delete mode 100644 generators/Exercises/EqualityExercise.cs rename generators/{Output/TestMethodOptions.cs => Exercises/ExerciseConfiguration.cs} (63%) create mode 100644 generators/Output/TestedMethodFormat.cs diff --git a/generators/Exercises/Acronym.cs b/generators/Exercises/Acronym.cs index 45c57a8757..6a8b12c4f9 100644 --- a/generators/Exercises/Acronym.cs +++ b/generators/Exercises/Acronym.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class Acronym : EqualityExercise + public class Acronym : Exercise { } } \ No newline at end of file diff --git a/generators/Exercises/AtbashCipher.cs b/generators/Exercises/AtbashCipher.cs index 819f800e25..b1f8eca832 100644 --- a/generators/Exercises/AtbashCipher.cs +++ b/generators/Exercises/AtbashCipher.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class AtbashCipher : EqualityExercise + public class AtbashCipher : Exercise { } } \ No newline at end of file diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index c6d932e63d..16f7e785dd 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -2,7 +2,7 @@ namespace Generators.Exercises { - public class BeerSong : EqualityExercise + public class BeerSong : Exercise { public BeerSong() { diff --git a/generators/Exercises/Bob.cs b/generators/Exercises/Bob.cs index af91138b16..14c27bf0d9 100644 --- a/generators/Exercises/Bob.cs +++ b/generators/Exercises/Bob.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class Bob : EqualityExercise + public class Bob : Exercise { } } \ No newline at end of file diff --git a/generators/Exercises/BooleanExercise.cs b/generators/Exercises/BooleanExercise.cs deleted file mode 100644 index 7c0af6f9c1..0000000000 --- a/generators/Exercises/BooleanExercise.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Generators.Output; - -namespace Generators.Exercises -{ - public abstract class BooleanExercise : Exercise - { - protected override TestMethod CreateTestMethod(TestMethodData testMethodData) - { - if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return ExceptionTestMethod.Create(testMethodData); - - return BooleanTestMethod.Create(testMethodData); - } - } -} \ No newline at end of file diff --git a/generators/Exercises/EqualityExercise.cs b/generators/Exercises/EqualityExercise.cs deleted file mode 100644 index 2b042de6d9..0000000000 --- a/generators/Exercises/EqualityExercise.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Generators.Output; - -namespace Generators.Exercises -{ - public abstract class EqualityExercise : Exercise - { - protected override TestMethod CreateTestMethod(TestMethodData testMethodData) - { - if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return ExceptionTestMethod.Create(testMethodData); - - return EqualityTestMethod.Create(testMethodData); - } - } -} \ No newline at end of file diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index f2f670d292..8868675e0d 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -15,12 +15,12 @@ protected Exercise() { Name = GetType().Name.Kebaberize(); CanonicalData = CanonicalDataParser.Parse(Name); - Options = new TestMethodOptions(); + Options = new ExerciseConfiguration(); } public string Name { get; } public CanonicalData CanonicalData { get; } - public TestMethodOptions Options { get; } + public ExerciseConfiguration Options { get; } public TestClass CreateTestClass() { @@ -42,7 +42,16 @@ private static void AddTestMethodUsingNamespaces(TestClass testClass) testClass.UsingNamespaces.UnionWith(testMethod.UsingNamespaces); } - protected abstract TestMethod CreateTestMethod(TestMethodData testMethodData); + private static TestMethod CreateTestMethod(TestMethodData testMethodData) + { + if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) + return ExceptionTestMethod.Create(testMethodData); + + if (testMethodData.Options.TestedMethodType == TestedMethodType.BooleanComparison) + return BooleanTestMethod.Create(testMethodData); + + return EqualityTestMethod.Create(testMethodData); + } private TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase) => CreateTestMethod(CreateTestMethodData(canonicalDataCase)); diff --git a/generators/Output/TestMethodOptions.cs b/generators/Exercises/ExerciseConfiguration.cs similarity index 63% rename from generators/Output/TestMethodOptions.cs rename to generators/Exercises/ExerciseConfiguration.cs index 87d777d875..14d1d4cef3 100644 --- a/generators/Output/TestMethodOptions.cs +++ b/generators/Exercises/ExerciseConfiguration.cs @@ -1,13 +1,15 @@ using System; +using Generators.Output; using Newtonsoft.Json.Linq; -namespace Generators.Output +namespace Generators.Exercises { - public class TestMethodOptions + public class ExerciseConfiguration { public ExpectedFormat ExpectedFormat { get; set; } = ExpectedFormat.Formatted; public Type ExceptionType { get; set; } = typeof(ArgumentException); - public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.Static; + public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.EqualityCheck; + public TestedMethodFormat TestedMethodFormat { get; set; } = TestedMethodFormat.Static; public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = x => x is JObject; } } \ No newline at end of file diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index 30c11c0248..a920d301b9 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -2,7 +2,7 @@ namespace Generators.Exercises { - public class FoodChain : EqualityExercise + public class FoodChain : Exercise { public FoodChain() { diff --git a/generators/Exercises/HelloWorld.cs b/generators/Exercises/HelloWorld.cs index c5103ce0f2..db5c5ea266 100644 --- a/generators/Exercises/HelloWorld.cs +++ b/generators/Exercises/HelloWorld.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class HelloWorld : EqualityExercise + public class HelloWorld : Exercise { } } diff --git a/generators/Exercises/Isogram.cs b/generators/Exercises/Isogram.cs index 1fae877b6c..98d5de7e57 100644 --- a/generators/Exercises/Isogram.cs +++ b/generators/Exercises/Isogram.cs @@ -1,6 +1,12 @@ +using Generators.Output; + namespace Generators.Exercises { - public class Isogram : BooleanExercise + public class Isogram : Exercise { + public Isogram() + { + Options.TestedMethodType = TestedMethodType.BooleanComparison; + } } } \ No newline at end of file diff --git a/generators/Exercises/Leap.cs b/generators/Exercises/Leap.cs index d068ef653c..a91bb8a490 100644 --- a/generators/Exercises/Leap.cs +++ b/generators/Exercises/Leap.cs @@ -1,6 +1,12 @@ -namespace Generators.Exercises +using Generators.Output; + +namespace Generators.Exercises { - public class Leap : BooleanExercise + public class Leap : Exercise { + public Leap() + { + Options.TestedMethodType = TestedMethodType.BooleanComparison; + } } } \ No newline at end of file diff --git a/generators/Exercises/Luhn.cs b/generators/Exercises/Luhn.cs index e39608097e..37a1b00443 100644 --- a/generators/Exercises/Luhn.cs +++ b/generators/Exercises/Luhn.cs @@ -1,6 +1,12 @@ +using Generators.Output; + namespace Generators.Exercises { - public class Luhn : BooleanExercise + public class Luhn : Exercise { + public Luhn() + { + Options.TestedMethodType = TestedMethodType.BooleanComparison; + } } } diff --git a/generators/Exercises/NthPrime.cs b/generators/Exercises/NthPrime.cs index c79fb74fb9..9670683add 100644 --- a/generators/Exercises/NthPrime.cs +++ b/generators/Exercises/NthPrime.cs @@ -2,7 +2,7 @@ namespace Generators.Exercises { - public class NthPrime : EqualityExercise + public class NthPrime : Exercise { public NthPrime() { diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index 552fc5953a..69720b8be0 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -4,7 +4,7 @@ namespace Generators.Exercises { - public class PerfectNumbers : EqualityExercise + public class PerfectNumbers : Exercise { public PerfectNumbers() { diff --git a/generators/Exercises/PigLatin.cs b/generators/Exercises/PigLatin.cs index d9a6bc1fd7..3f3c88e13c 100644 --- a/generators/Exercises/PigLatin.cs +++ b/generators/Exercises/PigLatin.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class PigLatin : EqualityExercise + public class PigLatin : Exercise { } } \ No newline at end of file diff --git a/generators/Exercises/Raindrops.cs b/generators/Exercises/Raindrops.cs index 0169452ac6..27a80b7112 100644 --- a/generators/Exercises/Raindrops.cs +++ b/generators/Exercises/Raindrops.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class Raindrops : EqualityExercise + public class Raindrops : Exercise { } } \ No newline at end of file diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index c51a8426ed..2fc9429ad3 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -2,11 +2,11 @@ namespace Generators.Exercises { - public class RomanNumerals : EqualityExercise + public class RomanNumerals : Exercise { public RomanNumerals() { - Options.TestedMethodType = TestedMethodType.Extension; + Options.TestedMethodFormat = TestedMethodFormat.Extension; foreach (var canonicalDataCase in CanonicalData.Cases) { diff --git a/generators/Exercises/RotationalCipher.cs b/generators/Exercises/RotationalCipher.cs index 33d12e94d7..6f71e13a4b 100644 --- a/generators/Exercises/RotationalCipher.cs +++ b/generators/Exercises/RotationalCipher.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class RotationalCipher : EqualityExercise + public class RotationalCipher : Exercise { } } \ No newline at end of file diff --git a/generators/Exercises/Wordy.cs b/generators/Exercises/Wordy.cs index 8228db878d..fee212c27b 100644 --- a/generators/Exercises/Wordy.cs +++ b/generators/Exercises/Wordy.cs @@ -1,6 +1,6 @@ namespace Generators.Exercises { - public class Wordy : EqualityExercise + public class Wordy : Exercise { public Wordy() { diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index ca614a4716..21fa0bf645 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -9,13 +9,13 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Options.TestedMethodType) + switch (TestMethodData.Options.TestedMethodFormat) { - case TestedMethodType.Static: + case TestedMethodFormat.Static: return new[] { $"{Assertion}({TestedClassName}.{TestedMethodName}({Input}));" }; - case TestedMethodType.Instance: + case TestedMethodFormat.Instance: return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethodName}({Input}));" }; - case TestedMethodType.Extension: + case TestedMethodFormat.Extension: return new[] { $"{Assertion}({Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index b06832f05f..b78f1cfc44 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -11,19 +11,19 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Options.TestedMethodType) + switch (TestMethodData.Options.TestedMethodFormat) { - case TestedMethodType.Static: + case TestedMethodFormat.Static: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethodName}({Input}));" }; return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethodName}({Input}));" }; - case TestedMethodType.Instance: + case TestedMethodFormat.Instance: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; - case TestedMethodType.Extension: + case TestedMethodFormat.Extension: if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethodName}());" }; diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index 81a5ca5ba1..c36c5fbfe1 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -9,13 +9,13 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Options.TestedMethodType) + switch (TestMethodData.Options.TestedMethodFormat) { - case TestedMethodType.Static: + case TestedMethodFormat.Static: return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethodName}({Input}));" }; - case TestedMethodType.Instance: + case TestedMethodFormat.Instance: return new[] { $"var sut = new {TestedClassName}();", $"Assert.Throws<{ExceptionType}>(() => sut.{TestedMethodName}({Input}));;" }; - case TestedMethodType.Extension: + case TestedMethodFormat.Extension: return new[] { $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); diff --git a/generators/Output/TestMethodData.cs b/generators/Output/TestMethodData.cs index 4b2f2f0e1a..bcc179f4d7 100644 --- a/generators/Output/TestMethodData.cs +++ b/generators/Output/TestMethodData.cs @@ -1,3 +1,4 @@ +using Generators.Exercises; using Generators.Input; namespace Generators.Output @@ -6,6 +7,6 @@ public class TestMethodData { public CanonicalData CanonicalData { get; set; } public CanonicalDataCase CanonicalDataCase { get; set;} - public TestMethodOptions Options { get; set; } = new TestMethodOptions(); + public ExerciseConfiguration Options { get; set; } = new ExerciseConfiguration(); } } \ No newline at end of file diff --git a/generators/Output/TestedMethodFormat.cs b/generators/Output/TestedMethodFormat.cs new file mode 100644 index 0000000000..7d9c483ec8 --- /dev/null +++ b/generators/Output/TestedMethodFormat.cs @@ -0,0 +1,9 @@ +namespace Generators.Output +{ + public enum TestedMethodFormat + { + Static = 0, + Instance, + Extension + } +} \ No newline at end of file diff --git a/generators/Output/TestedMethodType.cs b/generators/Output/TestedMethodType.cs index 95c9c2becc..10eac4a882 100644 --- a/generators/Output/TestedMethodType.cs +++ b/generators/Output/TestedMethodType.cs @@ -2,8 +2,7 @@ namespace Generators.Output { public enum TestedMethodType { - Static, - Instance, - Extension + EqualityCheck = 0, + BooleanComparison } } \ No newline at end of file From 13f85ec3ed8f522fa9ed9969183f939e2d9e08a5 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 20:05:42 +0200 Subject: [PATCH 11/22] Extracted test class generator --- generators/Exercises/BeerSong.cs | 2 +- generators/Exercises/Exercise.cs | 52 ++---------------- generators/Exercises/FoodChain.cs | 2 +- generators/Exercises/Isogram.cs | 2 +- generators/Exercises/Leap.cs | 2 +- generators/Exercises/Luhn.cs | 2 +- generators/Exercises/NthPrime.cs | 4 +- generators/Exercises/PerfectNumbers.cs | 8 ++- generators/Exercises/RomanNumerals.cs | 2 +- generators/Exercises/Wordy.cs | 2 +- .../Output/BooleanTestMethodGenerator.cs | 2 +- .../Output/EqualityTestMethodGenerator.cs | 8 +-- .../Output/ExceptionTestMethodGenerator.cs | 6 +-- generators/Output/TestClassGenerator.cs | 53 +++++++++++++++++++ generators/Output/TestClassRenderer.cs | 6 +-- generators/Output/TestFileGenerator.cs | 2 +- generators/Output/TestMethodData.cs | 2 +- generators/Output/TestMethodGenerator.cs | 2 +- 18 files changed, 82 insertions(+), 77 deletions(-) create mode 100644 generators/Output/TestClassGenerator.cs diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index 16f7e785dd..4b3b47e46a 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -6,7 +6,7 @@ public class BeerSong : Exercise { public BeerSong() { - Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; + Configuration.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; } } } \ No newline at end of file diff --git a/generators/Exercises/Exercise.cs b/generators/Exercises/Exercise.cs index 8868675e0d..f52489644f 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercises/Exercise.cs @@ -1,65 +1,19 @@ -using System.Linq; -using Generators.Input; -using Generators.Output; +using Generators.Input; using Humanizer; namespace Generators.Exercises { public abstract class Exercise { - protected static readonly BooleanTestMethodGenerator BooleanTestMethod = new BooleanTestMethodGenerator(); - protected static readonly EqualityTestMethodGenerator EqualityTestMethod = new EqualityTestMethodGenerator(); - protected static readonly ExceptionTestMethodGenerator ExceptionTestMethod = new ExceptionTestMethodGenerator(); - protected Exercise() { Name = GetType().Name.Kebaberize(); CanonicalData = CanonicalDataParser.Parse(Name); - Options = new ExerciseConfiguration(); + Configuration = new ExerciseConfiguration(); } public string Name { get; } public CanonicalData CanonicalData { get; } - public ExerciseConfiguration Options { get; } - - public TestClass CreateTestClass() - { - var testClass = new TestClass - { - ClassName = Name.ToTestClassName(), - TestMethods = CanonicalData.Cases.Select(CreateTestMethod).ToArray(), - CanonicalDataVersion = CanonicalData.Version - }; - - AddTestMethodUsingNamespaces(testClass); - - return testClass; - } - - private static void AddTestMethodUsingNamespaces(TestClass testClass) - { - foreach (var testMethod in testClass.TestMethods) - testClass.UsingNamespaces.UnionWith(testMethod.UsingNamespaces); - } - - private static TestMethod CreateTestMethod(TestMethodData testMethodData) - { - if (testMethodData.Options.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return ExceptionTestMethod.Create(testMethodData); - - if (testMethodData.Options.TestedMethodType == TestedMethodType.BooleanComparison) - return BooleanTestMethod.Create(testMethodData); - - return EqualityTestMethod.Create(testMethodData); - } - - private TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase) => CreateTestMethod(CreateTestMethodData(canonicalDataCase)); - - private TestMethodData CreateTestMethodData(CanonicalDataCase canonicalDataCase) => new TestMethodData - { - CanonicalData = CanonicalData, - CanonicalDataCase = canonicalDataCase, - Options = Options - }; + public ExerciseConfiguration Configuration { get; } } } \ No newline at end of file diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index a920d301b9..ab6d39768e 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -6,7 +6,7 @@ public class FoodChain : Exercise { public FoodChain() { - Options.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; + Configuration.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; } } } \ No newline at end of file diff --git a/generators/Exercises/Isogram.cs b/generators/Exercises/Isogram.cs index 98d5de7e57..cf718b632e 100644 --- a/generators/Exercises/Isogram.cs +++ b/generators/Exercises/Isogram.cs @@ -6,7 +6,7 @@ public class Isogram : Exercise { public Isogram() { - Options.TestedMethodType = TestedMethodType.BooleanComparison; + Configuration.TestedMethodType = TestedMethodType.BooleanComparison; } } } \ No newline at end of file diff --git a/generators/Exercises/Leap.cs b/generators/Exercises/Leap.cs index a91bb8a490..a9f938c447 100644 --- a/generators/Exercises/Leap.cs +++ b/generators/Exercises/Leap.cs @@ -6,7 +6,7 @@ public class Leap : Exercise { public Leap() { - Options.TestedMethodType = TestedMethodType.BooleanComparison; + Configuration.TestedMethodType = TestedMethodType.BooleanComparison; } } } \ No newline at end of file diff --git a/generators/Exercises/Luhn.cs b/generators/Exercises/Luhn.cs index 37a1b00443..e23bc52d9b 100644 --- a/generators/Exercises/Luhn.cs +++ b/generators/Exercises/Luhn.cs @@ -6,7 +6,7 @@ public class Luhn : Exercise { public Luhn() { - Options.TestedMethodType = TestedMethodType.BooleanComparison; + Configuration.TestedMethodType = TestedMethodType.BooleanComparison; } } } diff --git a/generators/Exercises/NthPrime.cs b/generators/Exercises/NthPrime.cs index 9670683add..8b80055aca 100644 --- a/generators/Exercises/NthPrime.cs +++ b/generators/Exercises/NthPrime.cs @@ -6,8 +6,8 @@ public class NthPrime : Exercise { public NthPrime() { - Options.ExceptionType = typeof(ArgumentOutOfRangeException); - Options.ThrowExceptionWhenExpectedValueEquals = x => x is bool; + Configuration.ExceptionType = typeof(ArgumentOutOfRangeException); + Configuration.ThrowExceptionWhenExpectedValueEquals = x => x is bool; } } } \ No newline at end of file diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index 69720b8be0..fdfc9e9ff6 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -8,16 +8,14 @@ public class PerfectNumbers : Exercise { public PerfectNumbers() { - Options.ExceptionType = typeof(ArgumentOutOfRangeException); - Options.ExpectedFormat = ExpectedFormat.Unformatted; + Configuration.ExceptionType = typeof(ArgumentOutOfRangeException); + Configuration.ExpectedFormat = ExpectedFormat.Unformatted; foreach (var canonicalDataCase in CanonicalData.Cases) { if (canonicalDataCase.Expected is string classificationType) - canonicalDataCase.Expected = GetClassification(classificationType); + canonicalDataCase.Expected = $"Classification.{classificationType.Transform(To.TitleCase)}"; } } - - private static string GetClassification(string classificationType) => $"Classification.{classificationType.Transform(To.TitleCase)}"; } } \ No newline at end of file diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index 2fc9429ad3..d5a3b100ba 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -6,7 +6,7 @@ public class RomanNumerals : Exercise { public RomanNumerals() { - Options.TestedMethodFormat = TestedMethodFormat.Extension; + Configuration.TestedMethodFormat = TestedMethodFormat.Extension; foreach (var canonicalDataCase in CanonicalData.Cases) { diff --git a/generators/Exercises/Wordy.cs b/generators/Exercises/Wordy.cs index fee212c27b..fc234ad7b5 100644 --- a/generators/Exercises/Wordy.cs +++ b/generators/Exercises/Wordy.cs @@ -4,7 +4,7 @@ public class Wordy : Exercise { public Wordy() { - Options.ThrowExceptionWhenExpectedValueEquals = x => x is bool; + Configuration.ThrowExceptionWhenExpectedValueEquals = x => x is bool; } } } \ No newline at end of file diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index 21fa0bf645..36a9ffdfcc 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -9,7 +9,7 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Options.TestedMethodFormat) + switch (TestMethodData.Configuration.TestedMethodFormat) { case TestedMethodFormat.Static: return new[] { $"{Assertion}({TestedClassName}.{TestedMethodName}({Input}));" }; diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index b78f1cfc44..a27ad2d8ee 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -11,20 +11,20 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Options.TestedMethodFormat) + switch (TestMethodData.Configuration.TestedMethodFormat) { case TestedMethodFormat.Static: - if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) + if (TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethodName}({Input}));" }; return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethodName}({Input}));" }; case TestedMethodFormat.Instance: - if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) + if (TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; case TestedMethodFormat.Extension: - if (TestMethodData.Options.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) + if (TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethodName}());" }; return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethodName}());" }; diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index c36c5fbfe1..60f88fc426 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -9,7 +9,7 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Options.TestedMethodFormat) + switch (TestMethodData.Configuration.TestedMethodFormat) { case TestedMethodFormat.Static: return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethodName}({Input}));" }; @@ -23,8 +23,8 @@ protected override IEnumerable Body } } - protected override ISet UsingNamespaces => new HashSet { TestMethodData.Options.ExceptionType.Namespace }; + protected override ISet UsingNamespaces => new HashSet { TestMethodData.Configuration.ExceptionType.Namespace }; - protected virtual string ExceptionType => TestMethodData.Options.ExceptionType.Name; + protected virtual string ExceptionType => TestMethodData.Configuration.ExceptionType.Name; } } \ No newline at end of file diff --git a/generators/Output/TestClassGenerator.cs b/generators/Output/TestClassGenerator.cs new file mode 100644 index 0000000000..9aa509ef6d --- /dev/null +++ b/generators/Output/TestClassGenerator.cs @@ -0,0 +1,53 @@ +using System.Linq; +using Generators.Exercises; +using Generators.Input; + +namespace Generators.Output +{ + public static class TestClassGenerator + { + private static readonly BooleanTestMethodGenerator BooleanTestMethod = new BooleanTestMethodGenerator(); + private static readonly EqualityTestMethodGenerator EqualityTestMethod = new EqualityTestMethodGenerator(); + private static readonly ExceptionTestMethodGenerator ExceptionTestMethod = new ExceptionTestMethodGenerator(); + + public static TestClass Create(Exercise exercise) + { + var testClass = new TestClass + { + ClassName = exercise.Name.ToTestClassName(), + TestMethods = exercise.CanonicalData.Cases.Select(canonicalDataCase => CreateTestMethod(canonicalDataCase, exercise)).ToArray(), + CanonicalDataVersion = exercise.CanonicalData.Version + }; + + AddTestMethodUsingNamespaces(testClass); + + return testClass; + } + + private static void AddTestMethodUsingNamespaces(TestClass testClass) + { + foreach (var testMethod in testClass.TestMethods) + testClass.UsingNamespaces.UnionWith(testMethod.UsingNamespaces); + } + + private static TestMethod CreateTestMethod(TestMethodData testMethodData) + { + if (testMethodData.Configuration.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) + return ExceptionTestMethod.Create(testMethodData); + + if (testMethodData.Configuration.TestedMethodType == TestedMethodType.BooleanComparison) + return BooleanTestMethod.Create(testMethodData); + + return EqualityTestMethod.Create(testMethodData); + } + + private static TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, Exercise exercise) => CreateTestMethod(CreateTestMethodData(canonicalDataCase, exercise)); + + private static TestMethodData CreateTestMethodData(CanonicalDataCase canonicalDataCase, Exercise exercise) => new TestMethodData + { + CanonicalData = exercise.CanonicalData, + CanonicalDataCase = canonicalDataCase, + Configuration = exercise.Configuration + }; + } +} diff --git a/generators/Output/TestClassRenderer.cs b/generators/Output/TestClassRenderer.cs index 52ddf707d8..8cf155dc43 100644 --- a/generators/Output/TestClassRenderer.cs +++ b/generators/Output/TestClassRenderer.cs @@ -6,7 +6,9 @@ namespace Generators.Output { public static class TestClassRenderer { - private static readonly Template TestClassTemplate = Template.Parse(GetTemplateContents()); + private static readonly string TemplateContents = File.ReadAllText(Path.Combine("Output", "TestClass.liquid")); + + private static readonly Template TestClassTemplate = Template.Parse(TemplateContents); public static string Render(TestClass testClass) { @@ -20,7 +22,5 @@ public static string Render(TestClass testClass) return TestClassTemplate.Render(Hash.FromAnonymousObject(templateData)); } - - private static string GetTemplateContents() => File.ReadAllText(Path.Combine("Output", "TestClass.liquid")); } } diff --git a/generators/Output/TestFileGenerator.cs b/generators/Output/TestFileGenerator.cs index 5a552baf45..76a720636b 100644 --- a/generators/Output/TestFileGenerator.cs +++ b/generators/Output/TestFileGenerator.cs @@ -8,7 +8,7 @@ public static class TestFileGenerator { public static void Generate(Exercise exercise) { - var testClass = exercise.CreateTestClass(); + var testClass = TestClassGenerator.Create(exercise); var testClassContents = TestClassRenderer.Render(testClass); var testClassFilePath = TestFilePath(exercise, testClass); diff --git a/generators/Output/TestMethodData.cs b/generators/Output/TestMethodData.cs index bcc179f4d7..2a8b3d6363 100644 --- a/generators/Output/TestMethodData.cs +++ b/generators/Output/TestMethodData.cs @@ -7,6 +7,6 @@ public class TestMethodData { public CanonicalData CanonicalData { get; set; } public CanonicalDataCase CanonicalDataCase { get; set;} - public ExerciseConfiguration Options { get; set; } = new ExerciseConfiguration(); + public ExerciseConfiguration Configuration { get; set; } = new ExerciseConfiguration(); } } \ No newline at end of file diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index 9e3572a750..03165cae91 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -45,7 +45,7 @@ protected object FormatInputValue(object val) } protected object Expected => - TestMethodData.Options.ExpectedFormat == ExpectedFormat.Unformatted + TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.Unformatted ? TestMethodData.CanonicalDataCase.Expected : FormatExpectedValue(TestMethodData.CanonicalDataCase.Expected); From 189d35d396206e067b233e888fdbb5c99929df96 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 19 Jun 2017 20:33:21 +0200 Subject: [PATCH 12/22] Make generators simpler --- exercises/nth-prime/NthPrimeTest.cs | 1 - .../perfect-numbers/PerfectNumbersTest.cs | 1 - exercises/wordy/WordyTest.cs | 1 - .../Output/BooleanTestMethodGenerator.cs | 4 +- .../Output/EqualityTestMethodGenerator.cs | 8 +-- .../Output/ExceptionTestMethodGenerator.cs | 6 +-- generators/Output/TestClassGenerator.cs | 54 +++++++------------ generators/Output/TestMethod.cs | 1 - generators/Output/TestMethodGenerator.cs | 39 +++++++------- generators/Output/TestedMethodFormat.cs | 2 +- generators/Output/TestedMethodType.cs | 2 +- 11 files changed, 48 insertions(+), 71 deletions(-) diff --git a/exercises/nth-prime/NthPrimeTest.cs b/exercises/nth-prime/NthPrimeTest.cs index 0ed1699694..a6dde1f82d 100644 --- a/exercises/nth-prime/NthPrimeTest.cs +++ b/exercises/nth-prime/NthPrimeTest.cs @@ -1,7 +1,6 @@ // This file was auto-generated based on version 1.0.0 of the canonical data. using Xunit; -using System; public class NthPrimeTest { diff --git a/exercises/perfect-numbers/PerfectNumbersTest.cs b/exercises/perfect-numbers/PerfectNumbersTest.cs index 01b2a9e6df..8b4a6dc702 100644 --- a/exercises/perfect-numbers/PerfectNumbersTest.cs +++ b/exercises/perfect-numbers/PerfectNumbersTest.cs @@ -1,7 +1,6 @@ // This file was auto-generated based on version 1.0.1 of the canonical data. using Xunit; -using System; public class PerfectNumbersTest { diff --git a/exercises/wordy/WordyTest.cs b/exercises/wordy/WordyTest.cs index 2b76cab6cf..1c3b564684 100644 --- a/exercises/wordy/WordyTest.cs +++ b/exercises/wordy/WordyTest.cs @@ -1,7 +1,6 @@ // This file was auto-generated based on version 1.0.0 of the canonical data. using Xunit; -using System; public class WordyTest { diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index 36a9ffdfcc..8c02b0c730 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -9,7 +9,7 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Configuration.TestedMethodFormat) + switch (Configuration.TestedMethodFormat) { case TestedMethodFormat.Static: return new[] { $"{Assertion}({TestedClassName}.{TestedMethodName}({Input}));" }; @@ -23,6 +23,6 @@ protected override IEnumerable Body } } - private string Assertion => $"Assert.{Convert.ToBoolean(TestMethodData.CanonicalDataCase.Expected)}"; + private string Assertion => $"Assert.{Convert.ToBoolean(CanonicalDataCase.Expected)}"; } } \ No newline at end of file diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index a27ad2d8ee..e2b3595e65 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -11,20 +11,20 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Configuration.TestedMethodFormat) + switch (Configuration.TestedMethodFormat) { case TestedMethodFormat.Static: - if (TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) + if (Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethodName}({Input}));" }; return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethodName}({Input}));" }; case TestedMethodFormat.Instance: - if (TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) + if (Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; case TestedMethodFormat.Extension: - if (TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) + if (Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethodName}());" }; return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethodName}());" }; diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index 60f88fc426..8121651aa2 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -9,7 +9,7 @@ protected override IEnumerable Body { get { - switch (TestMethodData.Configuration.TestedMethodFormat) + switch (Configuration.TestedMethodFormat) { case TestedMethodFormat.Static: return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethodName}({Input}));" }; @@ -23,8 +23,6 @@ protected override IEnumerable Body } } - protected override ISet UsingNamespaces => new HashSet { TestMethodData.Configuration.ExceptionType.Namespace }; - - protected virtual string ExceptionType => TestMethodData.Configuration.ExceptionType.Name; + protected virtual string ExceptionType => Configuration.ExceptionType.Name; } } \ No newline at end of file diff --git a/generators/Output/TestClassGenerator.cs b/generators/Output/TestClassGenerator.cs index 9aa509ef6d..01de55e21a 100644 --- a/generators/Output/TestClassGenerator.cs +++ b/generators/Output/TestClassGenerator.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Generators.Exercises; using Generators.Input; @@ -10,44 +11,27 @@ public static class TestClassGenerator private static readonly EqualityTestMethodGenerator EqualityTestMethod = new EqualityTestMethodGenerator(); private static readonly ExceptionTestMethodGenerator ExceptionTestMethod = new ExceptionTestMethodGenerator(); - public static TestClass Create(Exercise exercise) + public static TestClass Create(Exercise exercise) => new TestClass { - var testClass = new TestClass - { - ClassName = exercise.Name.ToTestClassName(), - TestMethods = exercise.CanonicalData.Cases.Select(canonicalDataCase => CreateTestMethod(canonicalDataCase, exercise)).ToArray(), - CanonicalDataVersion = exercise.CanonicalData.Version - }; - - AddTestMethodUsingNamespaces(testClass); - - return testClass; - } - - private static void AddTestMethodUsingNamespaces(TestClass testClass) - { - foreach (var testMethod in testClass.TestMethods) - testClass.UsingNamespaces.UnionWith(testMethod.UsingNamespaces); - } + ClassName = exercise.Name.ToTestClassName(), + TestMethods = exercise.CanonicalData.Cases.Select(canonicalDataCase => CreateTestMethod(canonicalDataCase, exercise)).ToArray(), + CanonicalDataVersion = exercise.CanonicalData.Version + }; - private static TestMethod CreateTestMethod(TestMethodData testMethodData) + private static TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, Exercise exercise) { - if (testMethodData.Configuration.ThrowExceptionWhenExpectedValueEquals(testMethodData.CanonicalDataCase.Expected)) - return ExceptionTestMethod.Create(testMethodData); - - if (testMethodData.Configuration.TestedMethodType == TestedMethodType.BooleanComparison) - return BooleanTestMethod.Create(testMethodData); + if (exercise.Configuration.ThrowExceptionWhenExpectedValueEquals(canonicalDataCase.Expected)) + return ExceptionTestMethod.Create(canonicalDataCase, exercise); - return EqualityTestMethod.Create(testMethodData); + switch (exercise.Configuration.TestedMethodType) + { + case TestedMethodType.EqualityCheck: + return EqualityTestMethod.Create(canonicalDataCase, exercise); + case TestedMethodType.BooleanComparison: + return BooleanTestMethod.Create(canonicalDataCase, exercise); + default: + throw new ArgumentOutOfRangeException(); + } } - - private static TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, Exercise exercise) => CreateTestMethod(CreateTestMethodData(canonicalDataCase, exercise)); - - private static TestMethodData CreateTestMethodData(CanonicalDataCase canonicalDataCase, Exercise exercise) => new TestMethodData - { - CanonicalData = exercise.CanonicalData, - CanonicalDataCase = canonicalDataCase, - Configuration = exercise.Configuration - }; } } diff --git a/generators/Output/TestMethod.cs b/generators/Output/TestMethod.cs index ff7856984d..bd60ff910b 100644 --- a/generators/Output/TestMethod.cs +++ b/generators/Output/TestMethod.cs @@ -4,7 +4,6 @@ namespace Generators.Output { public class TestMethod { - public ISet UsingNamespaces { get; set; } = new HashSet(); public string MethodName { get; set; } public IEnumerable Body { get; set; } } diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index 03165cae91..1593b72ee7 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -1,35 +1,34 @@ using System.Collections.Generic; using System.Linq; +using Generators.Exercises; +using Generators.Input; namespace Generators.Output { public abstract class TestMethodGenerator { - public TestMethod Create(TestMethodData testMethodData) + public TestMethod Create(CanonicalDataCase canonicalDataCase, Exercise exercise) { - TestMethodData = testMethodData; + CanonicalDataCase = canonicalDataCase; + CanonicalData = exercise.CanonicalData; + Configuration = exercise.Configuration; - return new TestMethod - { - UsingNamespaces = UsingNamespaces, - MethodName = TestMethodName, - Body = Body - }; + return new TestMethod { MethodName = TestMethodName, Body = Body }; } - - protected TestMethodData TestMethodData { get; private set; } + + protected CanonicalDataCase CanonicalDataCase { get; private set; } + protected CanonicalData CanonicalData { get; private set; } + protected ExerciseConfiguration Configuration { get; private set; } protected abstract IEnumerable Body { get; } - protected virtual ISet UsingNamespaces => new HashSet(); - - protected string TestMethodName => TestMethodData.CanonicalDataCase.Description.ToTestMethodName(); + protected string TestMethodName => CanonicalDataCase.Description.ToTestMethodName(); - protected string TestedClassName => TestMethodData.CanonicalData.Exercise.ToTestedClassName(); + protected string TestedClassName => CanonicalData.Exercise.ToTestedClassName(); - protected string TestedMethodName => TestMethodData.CanonicalDataCase.Property.ToTestedMethodName(); + protected string TestedMethodName => CanonicalDataCase.Property.ToTestedMethodName(); - protected object Input => FormatInputValue(TestMethodData.CanonicalDataCase.Input); + protected object Input => FormatInputValue(CanonicalDataCase.Input); protected object FormatInputValue(object val) { @@ -44,10 +43,10 @@ protected object FormatInputValue(object val) } } - protected object Expected => - TestMethodData.Configuration.ExpectedFormat == ExpectedFormat.Unformatted - ? TestMethodData.CanonicalDataCase.Expected - : FormatExpectedValue(TestMethodData.CanonicalDataCase.Expected); + protected object Expected => + Configuration.ExpectedFormat == ExpectedFormat.Unformatted + ? CanonicalDataCase.Expected + : FormatExpectedValue(CanonicalDataCase.Expected); protected object FormatExpectedValue(object val) { diff --git a/generators/Output/TestedMethodFormat.cs b/generators/Output/TestedMethodFormat.cs index 7d9c483ec8..5f4bae5d18 100644 --- a/generators/Output/TestedMethodFormat.cs +++ b/generators/Output/TestedMethodFormat.cs @@ -2,7 +2,7 @@ namespace Generators.Output { public enum TestedMethodFormat { - Static = 0, + Static, Instance, Extension } diff --git a/generators/Output/TestedMethodType.cs b/generators/Output/TestedMethodType.cs index 10eac4a882..65c9c92966 100644 --- a/generators/Output/TestedMethodType.cs +++ b/generators/Output/TestedMethodType.cs @@ -2,7 +2,7 @@ namespace Generators.Output { public enum TestedMethodType { - EqualityCheck = 0, + EqualityCheck, BooleanComparison } } \ No newline at end of file From d4e3613dd0991f7c559c5dde7132e50c172f724d Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Tue, 20 Jun 2017 19:24:49 +0200 Subject: [PATCH 13/22] Infer expected test method type --- generators/Exercises/ExerciseConfiguration.cs | 1 - generators/Exercises/Isogram.cs | 6 ------ generators/Exercises/Leap.cs | 8 +------- generators/Exercises/Luhn.cs | 6 ------ generators/Output/TestClassGenerator.cs | 13 ++++--------- generators/Output/TestedMethodType.cs | 8 -------- 6 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 generators/Output/TestedMethodType.cs diff --git a/generators/Exercises/ExerciseConfiguration.cs b/generators/Exercises/ExerciseConfiguration.cs index 14d1d4cef3..e234f5539b 100644 --- a/generators/Exercises/ExerciseConfiguration.cs +++ b/generators/Exercises/ExerciseConfiguration.cs @@ -8,7 +8,6 @@ public class ExerciseConfiguration { public ExpectedFormat ExpectedFormat { get; set; } = ExpectedFormat.Formatted; public Type ExceptionType { get; set; } = typeof(ArgumentException); - public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.EqualityCheck; public TestedMethodFormat TestedMethodFormat { get; set; } = TestedMethodFormat.Static; public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = x => x is JObject; } diff --git a/generators/Exercises/Isogram.cs b/generators/Exercises/Isogram.cs index cf718b632e..9a1eb0d57c 100644 --- a/generators/Exercises/Isogram.cs +++ b/generators/Exercises/Isogram.cs @@ -1,12 +1,6 @@ -using Generators.Output; - namespace Generators.Exercises { public class Isogram : Exercise { - public Isogram() - { - Configuration.TestedMethodType = TestedMethodType.BooleanComparison; - } } } \ No newline at end of file diff --git a/generators/Exercises/Leap.cs b/generators/Exercises/Leap.cs index a9f938c447..71e9884329 100644 --- a/generators/Exercises/Leap.cs +++ b/generators/Exercises/Leap.cs @@ -1,12 +1,6 @@ -using Generators.Output; - -namespace Generators.Exercises +namespace Generators.Exercises { public class Leap : Exercise { - public Leap() - { - Configuration.TestedMethodType = TestedMethodType.BooleanComparison; - } } } \ No newline at end of file diff --git a/generators/Exercises/Luhn.cs b/generators/Exercises/Luhn.cs index e23bc52d9b..51e7ce5c8b 100644 --- a/generators/Exercises/Luhn.cs +++ b/generators/Exercises/Luhn.cs @@ -1,12 +1,6 @@ -using Generators.Output; - namespace Generators.Exercises { public class Luhn : Exercise { - public Luhn() - { - Configuration.TestedMethodType = TestedMethodType.BooleanComparison; - } } } diff --git a/generators/Output/TestClassGenerator.cs b/generators/Output/TestClassGenerator.cs index 01de55e21a..33ac36aa0e 100644 --- a/generators/Output/TestClassGenerator.cs +++ b/generators/Output/TestClassGenerator.cs @@ -23,15 +23,10 @@ private static TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, if (exercise.Configuration.ThrowExceptionWhenExpectedValueEquals(canonicalDataCase.Expected)) return ExceptionTestMethod.Create(canonicalDataCase, exercise); - switch (exercise.Configuration.TestedMethodType) - { - case TestedMethodType.EqualityCheck: - return EqualityTestMethod.Create(canonicalDataCase, exercise); - case TestedMethodType.BooleanComparison: - return BooleanTestMethod.Create(canonicalDataCase, exercise); - default: - throw new ArgumentOutOfRangeException(); - } + if (canonicalDataCase.Expected is bool) + return BooleanTestMethod.Create(canonicalDataCase, exercise); + + return EqualityTestMethod.Create(canonicalDataCase, exercise); } } } diff --git a/generators/Output/TestedMethodType.cs b/generators/Output/TestedMethodType.cs deleted file mode 100644 index 65c9c92966..0000000000 --- a/generators/Output/TestedMethodType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Generators.Output -{ - public enum TestedMethodType - { - EqualityCheck, - BooleanComparison - } -} \ No newline at end of file From 8b70d77b285b8799e549826306ba2a0804b39a93 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Tue, 20 Jun 2017 19:30:31 +0200 Subject: [PATCH 14/22] Remove unused using statement --- generators/Output/TestClassGenerator.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/generators/Output/TestClassGenerator.cs b/generators/Output/TestClassGenerator.cs index 33ac36aa0e..f18fb29e54 100644 --- a/generators/Output/TestClassGenerator.cs +++ b/generators/Output/TestClassGenerator.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using Generators.Exercises; using Generators.Input; From 153a703728389c527b8aa927aa0e4ca5537c473f Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Tue, 20 Jun 2017 20:53:22 +0200 Subject: [PATCH 15/22] Simplify value formatting --- exercises/beer-song/BeerSongTest.cs | 354 +----------------- exercises/food-chain/FoodChainTest.cs | 136 +------ generators/{Exercises => }/Exercise.cs | 2 +- .../{Exercises => }/ExerciseConfiguration.cs | 6 +- generators/Exercises/BeerSong.cs | 8 +- generators/Exercises/FoodChain.cs | 5 +- generators/Exercises/PerfectNumbers.cs | 12 +- generators/Exercises/RomanNumerals.cs | 2 +- .../Output/BooleanTestMethodGenerator.cs | 8 +- .../Output/EqualityTestMethodGenerator.cs | 45 +-- .../Output/ExceptionTestMethodGenerator.cs | 10 +- generators/Output/ExpectedFormat.cs | 9 - generators/Output/StringExtensions.cs | 8 - generators/Output/TestMethodGenerator.cs | 46 +-- generators/Output/ValueFormatter.cs | 29 ++ ...tedMethodFormat.cs => TestedMethodType.cs} | 4 +- 16 files changed, 84 insertions(+), 600 deletions(-) rename generators/{Exercises => }/Exercise.cs (93%) rename generators/{Exercises => }/ExerciseConfiguration.cs (54%) delete mode 100644 generators/Output/ExpectedFormat.cs delete mode 100644 generators/Output/StringExtensions.cs create mode 100644 generators/Output/ValueFormatter.cs rename generators/{Output/TestedMethodFormat.cs => TestedMethodType.cs} (51%) diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index babc74aceb..f17edba7e6 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -7,386 +7,48 @@ public class BeerSongTest [Fact] public void First_generic_verse() { - 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" + -"""; - Assert.Equal(expected, BeerSong.Verse(99)); + Assert.Equal("99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n", BeerSong.Verse(99)); } [Fact(Skip = "Remove to run test")] public void Last_generic_verse() { - 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.\n" + -"""; - Assert.Equal(expected, BeerSong.Verse(3)); + Assert.Equal("3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n", BeerSong.Verse(3)); } [Fact(Skip = "Remove to run test")] public void Verse_2() { - 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" + -"""; - Assert.Equal(expected, BeerSong.Verse(2)); + Assert.Equal("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", BeerSong.Verse(2)); } [Fact(Skip = "Remove to run test")] public void Verse_1() { - 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.\n" + -"""; - Assert.Equal(expected, BeerSong.Verse(1)); + Assert.Equal("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", BeerSong.Verse(1)); } [Fact(Skip = "Remove to run test")] public void Verse_0() { - 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.\n" + -"""; - Assert.Equal(expected, BeerSong.Verse(0)); + Assert.Equal("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", BeerSong.Verse(0)); } [Fact(Skip = "Remove to run test")] public void First_two_verses() { - 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" + -"""; - Assert.Equal(expected, BeerSong.Verses(99, 98)); + Assert.Equal("99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n", BeerSong.Verses(99, 98)); } [Fact(Skip = "Remove to run test")] public void Last_three_verses() { - 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.\n" + -"""; - Assert.Equal(expected, BeerSong.Verses(2, 0)); + Assert.Equal("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\n1 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\nNo 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", BeerSong.Verses(2, 0)); } [Fact(Skip = "Remove to run test")] public void All_verses() { - 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.\n" + -"""; - Assert.Equal(expected, BeerSong.Verses(99, 0)); + Assert.Equal("99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n\n97 bottles of beer on the wall, 97 bottles of beer.\nTake one down and pass it around, 96 bottles of beer on the wall.\n\n96 bottles of beer on the wall, 96 bottles of beer.\nTake one down and pass it around, 95 bottles of beer on the wall.\n\n95 bottles of beer on the wall, 95 bottles of beer.\nTake one down and pass it around, 94 bottles of beer on the wall.\n\n94 bottles of beer on the wall, 94 bottles of beer.\nTake one down and pass it around, 93 bottles of beer on the wall.\n\n93 bottles of beer on the wall, 93 bottles of beer.\nTake one down and pass it around, 92 bottles of beer on the wall.\n\n92 bottles of beer on the wall, 92 bottles of beer.\nTake one down and pass it around, 91 bottles of beer on the wall.\n\n91 bottles of beer on the wall, 91 bottles of beer.\nTake one down and pass it around, 90 bottles of beer on the wall.\n\n90 bottles of beer on the wall, 90 bottles of beer.\nTake one down and pass it around, 89 bottles of beer on the wall.\n\n89 bottles of beer on the wall, 89 bottles of beer.\nTake one down and pass it around, 88 bottles of beer on the wall.\n\n88 bottles of beer on the wall, 88 bottles of beer.\nTake one down and pass it around, 87 bottles of beer on the wall.\n\n87 bottles of beer on the wall, 87 bottles of beer.\nTake one down and pass it around, 86 bottles of beer on the wall.\n\n86 bottles of beer on the wall, 86 bottles of beer.\nTake one down and pass it around, 85 bottles of beer on the wall.\n\n85 bottles of beer on the wall, 85 bottles of beer.\nTake one down and pass it around, 84 bottles of beer on the wall.\n\n84 bottles of beer on the wall, 84 bottles of beer.\nTake one down and pass it around, 83 bottles of beer on the wall.\n\n83 bottles of beer on the wall, 83 bottles of beer.\nTake one down and pass it around, 82 bottles of beer on the wall.\n\n82 bottles of beer on the wall, 82 bottles of beer.\nTake one down and pass it around, 81 bottles of beer on the wall.\n\n81 bottles of beer on the wall, 81 bottles of beer.\nTake one down and pass it around, 80 bottles of beer on the wall.\n\n80 bottles of beer on the wall, 80 bottles of beer.\nTake one down and pass it around, 79 bottles of beer on the wall.\n\n79 bottles of beer on the wall, 79 bottles of beer.\nTake one down and pass it around, 78 bottles of beer on the wall.\n\n78 bottles of beer on the wall, 78 bottles of beer.\nTake one down and pass it around, 77 bottles of beer on the wall.\n\n77 bottles of beer on the wall, 77 bottles of beer.\nTake one down and pass it around, 76 bottles of beer on the wall.\n\n76 bottles of beer on the wall, 76 bottles of beer.\nTake one down and pass it around, 75 bottles of beer on the wall.\n\n75 bottles of beer on the wall, 75 bottles of beer.\nTake one down and pass it around, 74 bottles of beer on the wall.\n\n74 bottles of beer on the wall, 74 bottles of beer.\nTake one down and pass it around, 73 bottles of beer on the wall.\n\n73 bottles of beer on the wall, 73 bottles of beer.\nTake one down and pass it around, 72 bottles of beer on the wall.\n\n72 bottles of beer on the wall, 72 bottles of beer.\nTake one down and pass it around, 71 bottles of beer on the wall.\n\n71 bottles of beer on the wall, 71 bottles of beer.\nTake one down and pass it around, 70 bottles of beer on the wall.\n\n70 bottles of beer on the wall, 70 bottles of beer.\nTake one down and pass it around, 69 bottles of beer on the wall.\n\n69 bottles of beer on the wall, 69 bottles of beer.\nTake one down and pass it around, 68 bottles of beer on the wall.\n\n68 bottles of beer on the wall, 68 bottles of beer.\nTake one down and pass it around, 67 bottles of beer on the wall.\n\n67 bottles of beer on the wall, 67 bottles of beer.\nTake one down and pass it around, 66 bottles of beer on the wall.\n\n66 bottles of beer on the wall, 66 bottles of beer.\nTake one down and pass it around, 65 bottles of beer on the wall.\n\n65 bottles of beer on the wall, 65 bottles of beer.\nTake one down and pass it around, 64 bottles of beer on the wall.\n\n64 bottles of beer on the wall, 64 bottles of beer.\nTake one down and pass it around, 63 bottles of beer on the wall.\n\n63 bottles of beer on the wall, 63 bottles of beer.\nTake one down and pass it around, 62 bottles of beer on the wall.\n\n62 bottles of beer on the wall, 62 bottles of beer.\nTake one down and pass it around, 61 bottles of beer on the wall.\n\n61 bottles of beer on the wall, 61 bottles of beer.\nTake one down and pass it around, 60 bottles of beer on the wall.\n\n60 bottles of beer on the wall, 60 bottles of beer.\nTake one down and pass it around, 59 bottles of beer on the wall.\n\n59 bottles of beer on the wall, 59 bottles of beer.\nTake one down and pass it around, 58 bottles of beer on the wall.\n\n58 bottles of beer on the wall, 58 bottles of beer.\nTake one down and pass it around, 57 bottles of beer on the wall.\n\n57 bottles of beer on the wall, 57 bottles of beer.\nTake one down and pass it around, 56 bottles of beer on the wall.\n\n56 bottles of beer on the wall, 56 bottles of beer.\nTake one down and pass it around, 55 bottles of beer on the wall.\n\n55 bottles of beer on the wall, 55 bottles of beer.\nTake one down and pass it around, 54 bottles of beer on the wall.\n\n54 bottles of beer on the wall, 54 bottles of beer.\nTake one down and pass it around, 53 bottles of beer on the wall.\n\n53 bottles of beer on the wall, 53 bottles of beer.\nTake one down and pass it around, 52 bottles of beer on the wall.\n\n52 bottles of beer on the wall, 52 bottles of beer.\nTake one down and pass it around, 51 bottles of beer on the wall.\n\n51 bottles of beer on the wall, 51 bottles of beer.\nTake one down and pass it around, 50 bottles of beer on the wall.\n\n50 bottles of beer on the wall, 50 bottles of beer.\nTake one down and pass it around, 49 bottles of beer on the wall.\n\n49 bottles of beer on the wall, 49 bottles of beer.\nTake one down and pass it around, 48 bottles of beer on the wall.\n\n48 bottles of beer on the wall, 48 bottles of beer.\nTake one down and pass it around, 47 bottles of beer on the wall.\n\n47 bottles of beer on the wall, 47 bottles of beer.\nTake one down and pass it around, 46 bottles of beer on the wall.\n\n46 bottles of beer on the wall, 46 bottles of beer.\nTake one down and pass it around, 45 bottles of beer on the wall.\n\n45 bottles of beer on the wall, 45 bottles of beer.\nTake one down and pass it around, 44 bottles of beer on the wall.\n\n44 bottles of beer on the wall, 44 bottles of beer.\nTake one down and pass it around, 43 bottles of beer on the wall.\n\n43 bottles of beer on the wall, 43 bottles of beer.\nTake one down and pass it around, 42 bottles of beer on the wall.\n\n42 bottles of beer on the wall, 42 bottles of beer.\nTake one down and pass it around, 41 bottles of beer on the wall.\n\n41 bottles of beer on the wall, 41 bottles of beer.\nTake one down and pass it around, 40 bottles of beer on the wall.\n\n40 bottles of beer on the wall, 40 bottles of beer.\nTake one down and pass it around, 39 bottles of beer on the wall.\n\n39 bottles of beer on the wall, 39 bottles of beer.\nTake one down and pass it around, 38 bottles of beer on the wall.\n\n38 bottles of beer on the wall, 38 bottles of beer.\nTake one down and pass it around, 37 bottles of beer on the wall.\n\n37 bottles of beer on the wall, 37 bottles of beer.\nTake one down and pass it around, 36 bottles of beer on the wall.\n\n36 bottles of beer on the wall, 36 bottles of beer.\nTake one down and pass it around, 35 bottles of beer on the wall.\n\n35 bottles of beer on the wall, 35 bottles of beer.\nTake one down and pass it around, 34 bottles of beer on the wall.\n\n34 bottles of beer on the wall, 34 bottles of beer.\nTake one down and pass it around, 33 bottles of beer on the wall.\n\n33 bottles of beer on the wall, 33 bottles of beer.\nTake one down and pass it around, 32 bottles of beer on the wall.\n\n32 bottles of beer on the wall, 32 bottles of beer.\nTake one down and pass it around, 31 bottles of beer on the wall.\n\n31 bottles of beer on the wall, 31 bottles of beer.\nTake one down and pass it around, 30 bottles of beer on the wall.\n\n30 bottles of beer on the wall, 30 bottles of beer.\nTake one down and pass it around, 29 bottles of beer on the wall.\n\n29 bottles of beer on the wall, 29 bottles of beer.\nTake one down and pass it around, 28 bottles of beer on the wall.\n\n28 bottles of beer on the wall, 28 bottles of beer.\nTake one down and pass it around, 27 bottles of beer on the wall.\n\n27 bottles of beer on the wall, 27 bottles of beer.\nTake one down and pass it around, 26 bottles of beer on the wall.\n\n26 bottles of beer on the wall, 26 bottles of beer.\nTake one down and pass it around, 25 bottles of beer on the wall.\n\n25 bottles of beer on the wall, 25 bottles of beer.\nTake one down and pass it around, 24 bottles of beer on the wall.\n\n24 bottles of beer on the wall, 24 bottles of beer.\nTake one down and pass it around, 23 bottles of beer on the wall.\n\n23 bottles of beer on the wall, 23 bottles of beer.\nTake one down and pass it around, 22 bottles of beer on the wall.\n\n22 bottles of beer on the wall, 22 bottles of beer.\nTake one down and pass it around, 21 bottles of beer on the wall.\n\n21 bottles of beer on the wall, 21 bottles of beer.\nTake one down and pass it around, 20 bottles of beer on the wall.\n\n20 bottles of beer on the wall, 20 bottles of beer.\nTake one down and pass it around, 19 bottles of beer on the wall.\n\n19 bottles of beer on the wall, 19 bottles of beer.\nTake one down and pass it around, 18 bottles of beer on the wall.\n\n18 bottles of beer on the wall, 18 bottles of beer.\nTake one down and pass it around, 17 bottles of beer on the wall.\n\n17 bottles of beer on the wall, 17 bottles of beer.\nTake one down and pass it around, 16 bottles of beer on the wall.\n\n16 bottles of beer on the wall, 16 bottles of beer.\nTake one down and pass it around, 15 bottles of beer on the wall.\n\n15 bottles of beer on the wall, 15 bottles of beer.\nTake one down and pass it around, 14 bottles of beer on the wall.\n\n14 bottles of beer on the wall, 14 bottles of beer.\nTake one down and pass it around, 13 bottles of beer on the wall.\n\n13 bottles of beer on the wall, 13 bottles of beer.\nTake one down and pass it around, 12 bottles of beer on the wall.\n\n12 bottles of beer on the wall, 12 bottles of beer.\nTake one down and pass it around, 11 bottles of beer on the wall.\n\n11 bottles of beer on the wall, 11 bottles of beer.\nTake one down and pass it around, 10 bottles of beer on the wall.\n\n10 bottles of beer on the wall, 10 bottles of beer.\nTake one down and pass it around, 9 bottles of beer on the wall.\n\n9 bottles of beer on the wall, 9 bottles of beer.\nTake one down and pass it around, 8 bottles of beer on the wall.\n\n8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n\n7 bottles of beer on the wall, 7 bottles of beer.\nTake one down and pass it around, 6 bottles of beer on the wall.\n\n6 bottles of beer on the wall, 6 bottles of beer.\nTake one down and pass it around, 5 bottles of beer on the wall.\n\n5 bottles of beer on the wall, 5 bottles of beer.\nTake one down and pass it around, 4 bottles of beer on the wall.\n\n4 bottles of beer on the wall, 4 bottles of beer.\nTake one down and pass it around, 3 bottles of beer on the wall.\n\n3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n\n2 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\n1 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\nNo 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", BeerSong.Verses(99, 0)); } } \ No newline at end of file diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index 6597a943aa..282d266764 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -7,176 +7,60 @@ public class FoodChainTest [Fact] public void Fly() { - var expected = -"I know an old lady who swallowed a fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(1)); + Assert.Equal("I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(1)); } [Fact(Skip = "Remove to run test")] public void Spider() { - var expected = -"I know an old lady who swallowed a spider.\n" + -"It wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(2)); + Assert.Equal("I know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(2)); } [Fact(Skip = "Remove to run test")] public void Bird() { - var expected = -"I know an old lady who swallowed a bird.\n" + -"How absurd to swallow a bird!\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(3)); + Assert.Equal("I know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(3)); } [Fact(Skip = "Remove to run test")] public void Cat() { - var expected = -"I know an old lady who swallowed a cat.\n" + -"Imagine that, to swallow a cat!\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(4)); + Assert.Equal("I know an old lady who swallowed a cat.\nImagine that, to swallow a cat!\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(4)); } [Fact(Skip = "Remove to run test")] public void Dog() { - var expected = -"I know an old lady who swallowed a dog.\n" + -"What a hog, to swallow a dog!\n" + -"She swallowed the dog to catch the cat.\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(5)); + Assert.Equal("I know an old lady who swallowed a dog.\nWhat a hog, to swallow a dog!\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(5)); } [Fact(Skip = "Remove to run test")] public void Goat() { - var expected = -"I know an old lady who swallowed a goat.\n" + -"Just opened her throat and swallowed a goat!\n" + -"She swallowed the goat to catch the dog.\n" + -"She swallowed the dog to catch the cat.\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(6)); + Assert.Equal("I know an old lady who swallowed a goat.\nJust opened her throat and swallowed a goat!\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(6)); } [Fact(Skip = "Remove to run test")] public void Cow() { - var expected = -"I know an old lady who swallowed a cow.\n" + -"I don't know how she swallowed a cow!\n" + -"She swallowed the cow to catch the goat.\n" + -"She swallowed the goat to catch the dog.\n" + -"She swallowed the dog to catch the cat.\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(7)); + Assert.Equal("I know an old lady who swallowed a cow.\nI don't know how she swallowed a cow!\nShe swallowed the cow to catch the goat.\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(7)); } [Fact(Skip = "Remove to run test")] public void Horse() { - var expected = -"I know an old lady who swallowed a horse.\n" + -"She's dead, of course!"; - Assert.Equal(expected, FoodChain.Verse(8)); + Assert.Equal("I know an old lady who swallowed a horse.\nShe's dead, of course!", FoodChain.Verse(8)); } [Fact(Skip = "Remove to run test")] public void Multiple_verses() { - var expected = -"I know an old lady who swallowed a fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a spider.\n" + -"It wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a bird.\n" + -"How absurd to swallow a bird!\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Verse(1, 3)); + Assert.Equal("I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(1, 3)); } [Fact(Skip = "Remove to run test")] public void Full_song() { - var expected = -"I know an old lady who swallowed a fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a spider.\n" + -"It wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a bird.\n" + -"How absurd to swallow a bird!\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a cat.\n" + -"Imagine that, to swallow a cat!\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a dog.\n" + -"What a hog, to swallow a dog!\n" + -"She swallowed the dog to catch the cat.\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a goat.\n" + -"Just opened her throat and swallowed a goat!\n" + -"She swallowed the goat to catch the dog.\n" + -"She swallowed the dog to catch the cat.\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a cow.\n" + -"I don't know how she swallowed a cow!\n" + -"She swallowed the cow to catch the goat.\n" + -"She swallowed the goat to catch the dog.\n" + -"She swallowed the dog to catch the cat.\n" + -"She swallowed the cat to catch the bird.\n" + -"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + -"She swallowed the spider to catch the fly.\n" + -"I don't know why she swallowed the fly. Perhaps she'll die.\n" + -"\n" + -"I know an old lady who swallowed a horse.\n" + -"She's dead, of course!"; - Assert.Equal(expected, FoodChain.Verse(1, 8)); + Assert.Equal("I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a cat.\nImagine that, to swallow a cat!\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a dog.\nWhat a hog, to swallow a dog!\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a goat.\nJust opened her throat and swallowed a goat!\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a cow.\nI don't know how she swallowed a cow!\nShe swallowed the cow to catch the goat.\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a horse.\nShe's dead, of course!", FoodChain.Verse(1, 8)); } } \ No newline at end of file diff --git a/generators/Exercises/Exercise.cs b/generators/Exercise.cs similarity index 93% rename from generators/Exercises/Exercise.cs rename to generators/Exercise.cs index f52489644f..12ca05dc44 100644 --- a/generators/Exercises/Exercise.cs +++ b/generators/Exercise.cs @@ -1,7 +1,7 @@ using Generators.Input; using Humanizer; -namespace Generators.Exercises +namespace Generators { public abstract class Exercise { diff --git a/generators/Exercises/ExerciseConfiguration.cs b/generators/ExerciseConfiguration.cs similarity index 54% rename from generators/Exercises/ExerciseConfiguration.cs rename to generators/ExerciseConfiguration.cs index e234f5539b..4d280556ab 100644 --- a/generators/Exercises/ExerciseConfiguration.cs +++ b/generators/ExerciseConfiguration.cs @@ -1,14 +1,12 @@ using System; -using Generators.Output; using Newtonsoft.Json.Linq; -namespace Generators.Exercises +namespace Generators { public class ExerciseConfiguration { - public ExpectedFormat ExpectedFormat { get; set; } = ExpectedFormat.Formatted; + public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.Static; public Type ExceptionType { get; set; } = typeof(ArgumentException); - public TestedMethodFormat TestedMethodFormat { get; set; } = TestedMethodFormat.Static; public Func ThrowExceptionWhenExpectedValueEquals { get; set; } = x => x is JObject; } } \ No newline at end of file diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index 4b3b47e46a..5c8c333eef 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -1,12 +1,6 @@ -using Generators.Output; - -namespace Generators.Exercises +namespace Generators.Exercises { public class BeerSong : Exercise { - public BeerSong() - { - Configuration.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; - } } } \ No newline at end of file diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index ab6d39768e..5171d1f13a 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -1,4 +1,4 @@ -using Generators.Output; +using Newtonsoft.Json.Linq; namespace Generators.Exercises { @@ -6,7 +6,8 @@ public class FoodChain : Exercise { public FoodChain() { - Configuration.ExpectedFormat = ExpectedFormat.FormattedAsMultilineString; + foreach (var canonicalDataCase in CanonicalData.Cases) + canonicalDataCase.Expected = string.Join("\n", ((JArray)canonicalDataCase.Expected).Values()); } } } \ No newline at end of file diff --git a/generators/Exercises/PerfectNumbers.cs b/generators/Exercises/PerfectNumbers.cs index fdfc9e9ff6..13d511c421 100644 --- a/generators/Exercises/PerfectNumbers.cs +++ b/generators/Exercises/PerfectNumbers.cs @@ -1,6 +1,4 @@ using System; -using Generators.Output; -using Humanizer; namespace Generators.Exercises { @@ -9,13 +7,19 @@ public class PerfectNumbers : Exercise public PerfectNumbers() { Configuration.ExceptionType = typeof(ArgumentOutOfRangeException); - Configuration.ExpectedFormat = ExpectedFormat.Unformatted; foreach (var canonicalDataCase in CanonicalData.Cases) { if (canonicalDataCase.Expected is string classificationType) - canonicalDataCase.Expected = $"Classification.{classificationType.Transform(To.TitleCase)}"; + canonicalDataCase.Expected = Enum.Parse(typeof(Classification), classificationType, true); } } + + private enum Classification + { + Abundant, + Deficient, + Perfect, + } } } \ No newline at end of file diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index d5a3b100ba..3877d6396e 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -6,7 +6,7 @@ public class RomanNumerals : Exercise { public RomanNumerals() { - Configuration.TestedMethodFormat = TestedMethodFormat.Extension; + Configuration.TestedMethodType = TestedMethodType.Extension; foreach (var canonicalDataCase in CanonicalData.Cases) { diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index 8c02b0c730..8ab6adaac8 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -9,13 +9,13 @@ protected override IEnumerable Body { get { - switch (Configuration.TestedMethodFormat) + switch (Configuration.TestedMethodType) { - case TestedMethodFormat.Static: + case TestedMethodType.Static: return new[] { $"{Assertion}({TestedClassName}.{TestedMethodName}({Input}));" }; - case TestedMethodFormat.Instance: + case TestedMethodType.Instance: return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethodName}({Input}));" }; - case TestedMethodFormat.Extension: + case TestedMethodType.Extension: return new[] { $"{Assertion}({Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index e2b3595e65..fb1a8373c0 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Linq; namespace Generators.Output { @@ -11,22 +9,13 @@ protected override IEnumerable Body { get { - switch (Configuration.TestedMethodFormat) + switch (Configuration.TestedMethodType) { - case TestedMethodFormat.Static: - if (Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {TestedClassName}.{TestedMethodName}({Input}));" }; - + case TestedMethodType.Static: return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethodName}({Input}));" }; - case TestedMethodFormat.Instance: - if (Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; - + case TestedMethodType.Instance: return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; - case TestedMethodFormat.Extension: - if (Configuration.ExpectedFormat == ExpectedFormat.FormattedAsMultilineString) - return new[] { $"var expected = {FormattedExpectedVariable};", $"Assert.Equal(expected, {Input}.{TestedMethodName}());" }; - + case TestedMethodType.Extension: return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); @@ -34,31 +23,5 @@ protected override IEnumerable Body } } - protected virtual string FormattedExpectedVariable - { - get - { - var lines = ExpectedToMultiLineString(Expected).Split('\n'); - if (lines.Length == 1) - return lines[0]; - - return "\n" + string.Join("\n", lines.Select(line => $"{line}")); - } - } - - private string ExpectedToMultiLineString(object expected) - { - switch (expected) - { - case JArray jarray: - return ExpectedToMultiLineString(jarray.Values()); - case IEnumerable enumerable: - return string.Join(" + \"\\n\" +\n", enumerable.Select(FormatExpectedValue)).Replace("\" + \"\\n", "\\n"); - case string str: - return ExpectedToMultiLineString(str.Split('\n')); - default: - throw new ArgumentException("Cannot convert expected value to multiline string."); - } - } } } \ No newline at end of file diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index 8121651aa2..a0b709b8c4 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -9,13 +9,13 @@ protected override IEnumerable Body { get { - switch (Configuration.TestedMethodFormat) + switch (Configuration.TestedMethodType) { - case TestedMethodFormat.Static: + case TestedMethodType.Static: return new[] { $"Assert.Throws<{ExceptionType}>(() => {TestedClassName}.{TestedMethodName}({Input}));" }; - case TestedMethodFormat.Instance: - return new[] { $"var sut = new {TestedClassName}();", $"Assert.Throws<{ExceptionType}>(() => sut.{TestedMethodName}({Input}));;" }; - case TestedMethodFormat.Extension: + case TestedMethodType.Instance: + return new[] { $"var sut = new {TestedClassName}();", $"Assert.Throws<{ExceptionType}>(() => sut.{TestedMethodName}({Input}));" }; + case TestedMethodType.Extension: return new[] { $"Assert.Throws<{ExceptionType}>(() => {Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); diff --git a/generators/Output/ExpectedFormat.cs b/generators/Output/ExpectedFormat.cs deleted file mode 100644 index bda252b931..0000000000 --- a/generators/Output/ExpectedFormat.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Generators.Output -{ - public enum ExpectedFormat - { - Formatted, - FormattedAsMultilineString, - Unformatted - } -} \ No newline at end of file diff --git a/generators/Output/StringExtensions.cs b/generators/Output/StringExtensions.cs deleted file mode 100644 index eb50188cff..0000000000 --- a/generators/Output/StringExtensions.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Generators.Output -{ - public static class StringExtensions - { - public static string EnsureStartsWith(this string str, string value) - => str.StartsWith(value) ? str : value + str; - } -} \ No newline at end of file diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index 1593b72ee7..0309a893d5 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Linq; -using Generators.Exercises; using Generators.Input; namespace Generators.Output @@ -15,50 +13,18 @@ public TestMethod Create(CanonicalDataCase canonicalDataCase, Exercise exercise) return new TestMethod { MethodName = TestMethodName, Body = Body }; } - - protected CanonicalDataCase CanonicalDataCase { get; private set; } - protected CanonicalData CanonicalData { get; private set; } - protected ExerciseConfiguration Configuration { get; private set; } protected abstract IEnumerable Body { get; } + protected CanonicalDataCase CanonicalDataCase { get; private set; } + protected CanonicalData CanonicalData { get; private set; } + protected ExerciseConfiguration Configuration { get; private set; } + protected string TestMethodName => CanonicalDataCase.Description.ToTestMethodName(); - protected string TestedClassName => CanonicalData.Exercise.ToTestedClassName(); - protected string TestedMethodName => CanonicalDataCase.Property.ToTestedMethodName(); - protected object Input => FormatInputValue(CanonicalDataCase.Input); - - protected object FormatInputValue(object val) - { - switch (val) - { - case IDictionary dict: - return string.Join(", ", dict.Values.Select(FormatInputValue)); - case string s: - return $"\"{s.Replace("\n", "\\n").Replace("\t", "\\t").Replace("\r", "\\r")}\""; - default: - return val; - } - } - - protected object Expected => - Configuration.ExpectedFormat == ExpectedFormat.Unformatted - ? CanonicalDataCase.Expected - : FormatExpectedValue(CanonicalDataCase.Expected); - - protected object FormatExpectedValue(object val) - { - switch (val) - { - case string s: - return $"\"{s}\""; - case IEnumerable enumerable: - return enumerable.Select(FormatExpectedValue); - default: - return val; - } - } + protected object Input => ValueFormatter.Format(CanonicalDataCase.Input); + protected object Expected => ValueFormatter.Format(CanonicalDataCase.Expected); } } \ No newline at end of file diff --git a/generators/Output/ValueFormatter.cs b/generators/Output/ValueFormatter.cs new file mode 100644 index 0000000000..ae33e4acbe --- /dev/null +++ b/generators/Output/ValueFormatter.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Generators.Output +{ + public static class ValueFormatter + { + public static object Format(object val) + { + switch (val) + { + case IDictionary dict: + return string.Join(", ", dict.Values.Select(Format)); + case Enum e: + return $"{e.GetType().Name}.{e}"; + case string s: + return $"\"{s.EscapeControlCharacters()}\""; + default: + return val; + } + } + + private static string EscapeControlCharacters(this string s) + => s.Replace("\n", "\\n") + .Replace("\t", "\\t") + .Replace("\r", "\\r"); + } +} \ No newline at end of file diff --git a/generators/Output/TestedMethodFormat.cs b/generators/TestedMethodType.cs similarity index 51% rename from generators/Output/TestedMethodFormat.cs rename to generators/TestedMethodType.cs index 5f4bae5d18..0e8938029d 100644 --- a/generators/Output/TestedMethodFormat.cs +++ b/generators/TestedMethodType.cs @@ -1,6 +1,6 @@ -namespace Generators.Output +namespace Generators { - public enum TestedMethodFormat + public enum TestedMethodType { Static, Instance, From 1358b8ef6dffda3e5a16092fd08c9b08274c8a28 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Tue, 20 Jun 2017 20:59:51 +0200 Subject: [PATCH 16/22] Fix unknown exception type namespaces --- exercises/nth-prime/NthPrimeTest.cs | 2 +- exercises/perfect-numbers/PerfectNumbersTest.cs | 4 ++-- exercises/wordy/WordyTest.cs | 4 ++-- generators/Output/ExceptionTestMethodGenerator.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exercises/nth-prime/NthPrimeTest.cs b/exercises/nth-prime/NthPrimeTest.cs index a6dde1f82d..74885010b7 100644 --- a/exercises/nth-prime/NthPrimeTest.cs +++ b/exercises/nth-prime/NthPrimeTest.cs @@ -31,6 +31,6 @@ public void Big_prime() [Fact(Skip = "Remove to run test")] public void There_is_no_zeroth_prime() { - Assert.Throws(() => NthPrime.Prime(0)); + Assert.Throws(() => NthPrime.Prime(0)); } } \ No newline at end of file diff --git a/exercises/perfect-numbers/PerfectNumbersTest.cs b/exercises/perfect-numbers/PerfectNumbersTest.cs index 8b4a6dc702..3f380e8c20 100644 --- a/exercises/perfect-numbers/PerfectNumbersTest.cs +++ b/exercises/perfect-numbers/PerfectNumbersTest.cs @@ -73,12 +73,12 @@ public void Edge_case_no_factors_other_than_itself_is_classified_correctly() [Fact(Skip = "Remove to run test")] public void Zero_is_rejected_not_a_natural_number_() { - Assert.Throws(() => PerfectNumbers.Classify(0)); + Assert.Throws(() => PerfectNumbers.Classify(0)); } [Fact(Skip = "Remove to run test")] public void Negative_integer_is_rejected_not_a_natural_number_() { - Assert.Throws(() => PerfectNumbers.Classify(-1)); + Assert.Throws(() => PerfectNumbers.Classify(-1)); } } \ No newline at end of file diff --git a/exercises/wordy/WordyTest.cs b/exercises/wordy/WordyTest.cs index 1c3b564684..a96a5709c4 100644 --- a/exercises/wordy/WordyTest.cs +++ b/exercises/wordy/WordyTest.cs @@ -91,12 +91,12 @@ public void Multiple_division() [Fact(Skip = "Remove to run test")] public void Unknown_operation() { - Assert.Throws(() => Wordy.Answer("What is 52 cubed?")); + Assert.Throws(() => Wordy.Answer("What is 52 cubed?")); } [Fact(Skip = "Remove to run test")] public void Non_math_question() { - Assert.Throws(() => Wordy.Answer("Who is the President of the United States?")); + Assert.Throws(() => Wordy.Answer("Who is the President of the United States?")); } } \ No newline at end of file diff --git a/generators/Output/ExceptionTestMethodGenerator.cs b/generators/Output/ExceptionTestMethodGenerator.cs index a0b709b8c4..56b0908fc0 100644 --- a/generators/Output/ExceptionTestMethodGenerator.cs +++ b/generators/Output/ExceptionTestMethodGenerator.cs @@ -23,6 +23,6 @@ protected override IEnumerable Body } } - protected virtual string ExceptionType => Configuration.ExceptionType.Name; + protected virtual string ExceptionType => Configuration.ExceptionType.FullName; } } \ No newline at end of file From 3946fbc244938eab7af70de5f00e0abf2d5b2c4a Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Tue, 20 Jun 2017 21:03:13 +0200 Subject: [PATCH 17/22] Prefix Luhn property with "Is" --- exercises/luhn/LuhnTest.cs | 26 +++++++++++++------------- generators/Exercises/Luhn.cs | 5 +++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/exercises/luhn/LuhnTest.cs b/exercises/luhn/LuhnTest.cs index 56a2576aeb..6f48d6f9bc 100644 --- a/exercises/luhn/LuhnTest.cs +++ b/exercises/luhn/LuhnTest.cs @@ -7,78 +7,78 @@ public class LuhnTest [Fact] public void Single_digit_strings_can_not_be_valid() { - Assert.False(Luhn.Valid("1")); + Assert.False(Luhn.IsValid("1")); } [Fact(Skip = "Remove to run test")] public void A_single_zero_is_invalid() { - Assert.False(Luhn.Valid("0")); + Assert.False(Luhn.IsValid("0")); } [Fact(Skip = "Remove to run test")] public void A_simple_valid_sin_that_remains_valid_if_reversed() { - Assert.True(Luhn.Valid("059")); + Assert.True(Luhn.IsValid("059")); } [Fact(Skip = "Remove to run test")] public void A_simple_valid_sin_that_becomes_invalid_if_reversed() { - Assert.True(Luhn.Valid("59")); + Assert.True(Luhn.IsValid("59")); } [Fact(Skip = "Remove to run test")] public void A_valid_canadian_sin() { - Assert.True(Luhn.Valid("055 444 285")); + Assert.True(Luhn.IsValid("055 444 285")); } [Fact(Skip = "Remove to run test")] public void Invalid_canadian_sin() { - Assert.False(Luhn.Valid("055 444 286")); + Assert.False(Luhn.IsValid("055 444 286")); } [Fact(Skip = "Remove to run test")] public void Invalid_credit_card() { - Assert.False(Luhn.Valid("8273 1232 7352 0569")); + Assert.False(Luhn.IsValid("8273 1232 7352 0569")); } [Fact(Skip = "Remove to run test")] public void Valid_strings_with_a_non_digit_included_become_invalid() { - Assert.False(Luhn.Valid("055a 444 285")); + Assert.False(Luhn.IsValid("055a 444 285")); } [Fact(Skip = "Remove to run test")] public void Valid_strings_with_punctuation_included_become_invalid() { - Assert.False(Luhn.Valid("055-444-285")); + Assert.False(Luhn.IsValid("055-444-285")); } [Fact(Skip = "Remove to run test")] public void Valid_strings_with_symbols_included_become_invalid() { - Assert.False(Luhn.Valid("055£ 444$ 285")); + Assert.False(Luhn.IsValid("055£ 444$ 285")); } [Fact(Skip = "Remove to run test")] public void Single_zero_with_space_is_invalid() { - Assert.False(Luhn.Valid(" 0")); + Assert.False(Luhn.IsValid(" 0")); } [Fact(Skip = "Remove to run test")] public void More_than_a_single_zero_is_valid() { - Assert.True(Luhn.Valid("0000 0")); + Assert.True(Luhn.IsValid("0000 0")); } [Fact(Skip = "Remove to run test")] public void Input_digit_9_is_correctly_converted_to_output_digit_9() { - Assert.True(Luhn.Valid("091")); + Assert.True(Luhn.IsValid("091")); } } \ No newline at end of file diff --git a/generators/Exercises/Luhn.cs b/generators/Exercises/Luhn.cs index 51e7ce5c8b..8ca010450c 100644 --- a/generators/Exercises/Luhn.cs +++ b/generators/Exercises/Luhn.cs @@ -2,5 +2,10 @@ namespace Generators.Exercises { public class Luhn : Exercise { + public Luhn() + { + foreach (var canonicalDataCase in CanonicalData.Cases) + canonicalDataCase.Property = "IsValid"; + } } } From 8001026717aedaa9a946bd85b29bc9cc97ea411d Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 21 Jun 2017 18:40:20 +0200 Subject: [PATCH 18/22] Fix leap exercise --- exercises/leap/LeapTest.cs | 8 ++++---- generators/Exercises/Leap.cs | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/exercises/leap/LeapTest.cs b/exercises/leap/LeapTest.cs index 2ca2bf479f..e4676a3ad8 100644 --- a/exercises/leap/LeapTest.cs +++ b/exercises/leap/LeapTest.cs @@ -7,24 +7,24 @@ public class LeapTest [Fact] public void Year_not_divisible_by_4_is_common_year() { - Assert.False(Leap.LeapYear(2015)); + Assert.False(Leap.IsLeapYear(2015)); } [Fact(Skip = "Remove to run test")] public void Year_divisible_by_4_not_divisible_by_100_is_leap_year() { - Assert.True(Leap.LeapYear(2016)); + Assert.True(Leap.IsLeapYear(2016)); } [Fact(Skip = "Remove to run test")] public void Year_divisible_by_100_not_divisible_by_400_is_common_year() { - Assert.False(Leap.LeapYear(2100)); + Assert.False(Leap.IsLeapYear(2100)); } [Fact(Skip = "Remove to run test")] public void Year_divisible_by_400_is_leap_year() { - Assert.True(Leap.LeapYear(2000)); + Assert.True(Leap.IsLeapYear(2000)); } } \ No newline at end of file diff --git a/generators/Exercises/Leap.cs b/generators/Exercises/Leap.cs index 71e9884329..867aef2c78 100644 --- a/generators/Exercises/Leap.cs +++ b/generators/Exercises/Leap.cs @@ -2,5 +2,10 @@ { public class Leap : Exercise { + public Leap() + { + foreach (var canonicalDataCase in CanonicalData.Cases) + canonicalDataCase.Property = "IsLeapYear"; + } } } \ No newline at end of file From 2e5ec9cc664900d9d686c5663a9431abdc270eec Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 21 Jun 2017 19:15:26 +0200 Subject: [PATCH 19/22] Remove unused code --- generators/Exercises/RomanNumerals.cs | 4 +--- generators/Input/ExerciseCollection.cs | 1 - generators/Output/BooleanTestMethodGenerator.cs | 2 +- generators/Output/TestClassGenerator.cs | 1 - generators/Output/TestFileGenerator.cs | 1 - generators/Output/TestMethodData.cs | 12 ------------ 6 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 generators/Output/TestMethodData.cs diff --git a/generators/Exercises/RomanNumerals.cs b/generators/Exercises/RomanNumerals.cs index 3877d6396e..770595495e 100644 --- a/generators/Exercises/RomanNumerals.cs +++ b/generators/Exercises/RomanNumerals.cs @@ -1,6 +1,4 @@ -using Generators.Output; - -namespace Generators.Exercises +namespace Generators.Exercises { public class RomanNumerals : Exercise { diff --git a/generators/Input/ExerciseCollection.cs b/generators/Input/ExerciseCollection.cs index d63e3d0bfb..0437ef226b 100644 --- a/generators/Input/ExerciseCollection.cs +++ b/generators/Input/ExerciseCollection.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using Generators.Exercises; namespace Generators.Input { diff --git a/generators/Output/BooleanTestMethodGenerator.cs b/generators/Output/BooleanTestMethodGenerator.cs index 8ab6adaac8..7d20334190 100644 --- a/generators/Output/BooleanTestMethodGenerator.cs +++ b/generators/Output/BooleanTestMethodGenerator.cs @@ -16,7 +16,7 @@ protected override IEnumerable Body case TestedMethodType.Instance: return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethodName}({Input}));" }; case TestedMethodType.Extension: - return new[] { $"{Assertion}({Input}.{TestedMethodName}());" }; + return new[] { $"{Assertion}({Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); } diff --git a/generators/Output/TestClassGenerator.cs b/generators/Output/TestClassGenerator.cs index f18fb29e54..7c610260fd 100644 --- a/generators/Output/TestClassGenerator.cs +++ b/generators/Output/TestClassGenerator.cs @@ -1,5 +1,4 @@ using System.Linq; -using Generators.Exercises; using Generators.Input; namespace Generators.Output diff --git a/generators/Output/TestFileGenerator.cs b/generators/Output/TestFileGenerator.cs index 76a720636b..49d9397365 100644 --- a/generators/Output/TestFileGenerator.cs +++ b/generators/Output/TestFileGenerator.cs @@ -1,5 +1,4 @@ using System.IO; -using Generators.Exercises; using Serilog; namespace Generators.Output diff --git a/generators/Output/TestMethodData.cs b/generators/Output/TestMethodData.cs deleted file mode 100644 index 2a8b3d6363..0000000000 --- a/generators/Output/TestMethodData.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Generators.Exercises; -using Generators.Input; - -namespace Generators.Output -{ - public class TestMethodData - { - public CanonicalData CanonicalData { get; set; } - public CanonicalDataCase CanonicalDataCase { get; set;} - public ExerciseConfiguration Configuration { get; set; } = new ExerciseConfiguration(); - } -} \ No newline at end of file From d4b14d966911026df8a81e15c2d9ee5f7db7a60b Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 22 Jun 2017 19:42:32 +0200 Subject: [PATCH 20/22] Fix multi-line variables --- exercises/beer-song/BeerSongTest.cs | 354 +++++++++++++++++- exercises/food-chain/FoodChainTest.cs | 136 ++++++- generators/Exercises/BeerSong.cs | 9 +- generators/Exercises/FoodChain.cs | 5 +- .../Output/EqualityTestMethodGenerator.cs | 11 +- generators/Output/MultiLineString.cs | 20 + generators/Output/TestMethodGenerator.cs | 2 + generators/Output/ValueFormatter.cs | 32 +- 8 files changed, 542 insertions(+), 27 deletions(-) create mode 100644 generators/Output/MultiLineString.cs diff --git a/exercises/beer-song/BeerSongTest.cs b/exercises/beer-song/BeerSongTest.cs index f17edba7e6..cd3341390a 100755 --- a/exercises/beer-song/BeerSongTest.cs +++ b/exercises/beer-song/BeerSongTest.cs @@ -7,48 +7,386 @@ public class BeerSongTest [Fact] public void First_generic_verse() { - Assert.Equal("99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n", BeerSong.Verse(99)); + 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" + + ""; + Assert.Equal(expected, BeerSong.Verse(99)); } [Fact(Skip = "Remove to run test")] public void Last_generic_verse() { - Assert.Equal("3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n", BeerSong.Verse(3)); + 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.\n" + + ""; + Assert.Equal(expected, BeerSong.Verse(3)); } [Fact(Skip = "Remove to run test")] public void Verse_2() { - Assert.Equal("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", BeerSong.Verse(2)); + 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" + + ""; + Assert.Equal(expected, BeerSong.Verse(2)); } [Fact(Skip = "Remove to run test")] public void Verse_1() { - Assert.Equal("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", BeerSong.Verse(1)); + 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.\n" + + ""; + Assert.Equal(expected, BeerSong.Verse(1)); } [Fact(Skip = "Remove to run test")] public void Verse_0() { - Assert.Equal("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", BeerSong.Verse(0)); + 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.\n" + + ""; + Assert.Equal(expected, BeerSong.Verse(0)); } [Fact(Skip = "Remove to run test")] public void First_two_verses() { - Assert.Equal("99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n", BeerSong.Verses(99, 98)); + 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" + + ""; + Assert.Equal(expected, BeerSong.Verses(99, 98)); } [Fact(Skip = "Remove to run test")] public void Last_three_verses() { - Assert.Equal("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\n1 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\nNo 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", BeerSong.Verses(2, 0)); + 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.\n" + + ""; + Assert.Equal(expected, BeerSong.Verses(2, 0)); } [Fact(Skip = "Remove to run test")] public void All_verses() { - Assert.Equal("99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n\n97 bottles of beer on the wall, 97 bottles of beer.\nTake one down and pass it around, 96 bottles of beer on the wall.\n\n96 bottles of beer on the wall, 96 bottles of beer.\nTake one down and pass it around, 95 bottles of beer on the wall.\n\n95 bottles of beer on the wall, 95 bottles of beer.\nTake one down and pass it around, 94 bottles of beer on the wall.\n\n94 bottles of beer on the wall, 94 bottles of beer.\nTake one down and pass it around, 93 bottles of beer on the wall.\n\n93 bottles of beer on the wall, 93 bottles of beer.\nTake one down and pass it around, 92 bottles of beer on the wall.\n\n92 bottles of beer on the wall, 92 bottles of beer.\nTake one down and pass it around, 91 bottles of beer on the wall.\n\n91 bottles of beer on the wall, 91 bottles of beer.\nTake one down and pass it around, 90 bottles of beer on the wall.\n\n90 bottles of beer on the wall, 90 bottles of beer.\nTake one down and pass it around, 89 bottles of beer on the wall.\n\n89 bottles of beer on the wall, 89 bottles of beer.\nTake one down and pass it around, 88 bottles of beer on the wall.\n\n88 bottles of beer on the wall, 88 bottles of beer.\nTake one down and pass it around, 87 bottles of beer on the wall.\n\n87 bottles of beer on the wall, 87 bottles of beer.\nTake one down and pass it around, 86 bottles of beer on the wall.\n\n86 bottles of beer on the wall, 86 bottles of beer.\nTake one down and pass it around, 85 bottles of beer on the wall.\n\n85 bottles of beer on the wall, 85 bottles of beer.\nTake one down and pass it around, 84 bottles of beer on the wall.\n\n84 bottles of beer on the wall, 84 bottles of beer.\nTake one down and pass it around, 83 bottles of beer on the wall.\n\n83 bottles of beer on the wall, 83 bottles of beer.\nTake one down and pass it around, 82 bottles of beer on the wall.\n\n82 bottles of beer on the wall, 82 bottles of beer.\nTake one down and pass it around, 81 bottles of beer on the wall.\n\n81 bottles of beer on the wall, 81 bottles of beer.\nTake one down and pass it around, 80 bottles of beer on the wall.\n\n80 bottles of beer on the wall, 80 bottles of beer.\nTake one down and pass it around, 79 bottles of beer on the wall.\n\n79 bottles of beer on the wall, 79 bottles of beer.\nTake one down and pass it around, 78 bottles of beer on the wall.\n\n78 bottles of beer on the wall, 78 bottles of beer.\nTake one down and pass it around, 77 bottles of beer on the wall.\n\n77 bottles of beer on the wall, 77 bottles of beer.\nTake one down and pass it around, 76 bottles of beer on the wall.\n\n76 bottles of beer on the wall, 76 bottles of beer.\nTake one down and pass it around, 75 bottles of beer on the wall.\n\n75 bottles of beer on the wall, 75 bottles of beer.\nTake one down and pass it around, 74 bottles of beer on the wall.\n\n74 bottles of beer on the wall, 74 bottles of beer.\nTake one down and pass it around, 73 bottles of beer on the wall.\n\n73 bottles of beer on the wall, 73 bottles of beer.\nTake one down and pass it around, 72 bottles of beer on the wall.\n\n72 bottles of beer on the wall, 72 bottles of beer.\nTake one down and pass it around, 71 bottles of beer on the wall.\n\n71 bottles of beer on the wall, 71 bottles of beer.\nTake one down and pass it around, 70 bottles of beer on the wall.\n\n70 bottles of beer on the wall, 70 bottles of beer.\nTake one down and pass it around, 69 bottles of beer on the wall.\n\n69 bottles of beer on the wall, 69 bottles of beer.\nTake one down and pass it around, 68 bottles of beer on the wall.\n\n68 bottles of beer on the wall, 68 bottles of beer.\nTake one down and pass it around, 67 bottles of beer on the wall.\n\n67 bottles of beer on the wall, 67 bottles of beer.\nTake one down and pass it around, 66 bottles of beer on the wall.\n\n66 bottles of beer on the wall, 66 bottles of beer.\nTake one down and pass it around, 65 bottles of beer on the wall.\n\n65 bottles of beer on the wall, 65 bottles of beer.\nTake one down and pass it around, 64 bottles of beer on the wall.\n\n64 bottles of beer on the wall, 64 bottles of beer.\nTake one down and pass it around, 63 bottles of beer on the wall.\n\n63 bottles of beer on the wall, 63 bottles of beer.\nTake one down and pass it around, 62 bottles of beer on the wall.\n\n62 bottles of beer on the wall, 62 bottles of beer.\nTake one down and pass it around, 61 bottles of beer on the wall.\n\n61 bottles of beer on the wall, 61 bottles of beer.\nTake one down and pass it around, 60 bottles of beer on the wall.\n\n60 bottles of beer on the wall, 60 bottles of beer.\nTake one down and pass it around, 59 bottles of beer on the wall.\n\n59 bottles of beer on the wall, 59 bottles of beer.\nTake one down and pass it around, 58 bottles of beer on the wall.\n\n58 bottles of beer on the wall, 58 bottles of beer.\nTake one down and pass it around, 57 bottles of beer on the wall.\n\n57 bottles of beer on the wall, 57 bottles of beer.\nTake one down and pass it around, 56 bottles of beer on the wall.\n\n56 bottles of beer on the wall, 56 bottles of beer.\nTake one down and pass it around, 55 bottles of beer on the wall.\n\n55 bottles of beer on the wall, 55 bottles of beer.\nTake one down and pass it around, 54 bottles of beer on the wall.\n\n54 bottles of beer on the wall, 54 bottles of beer.\nTake one down and pass it around, 53 bottles of beer on the wall.\n\n53 bottles of beer on the wall, 53 bottles of beer.\nTake one down and pass it around, 52 bottles of beer on the wall.\n\n52 bottles of beer on the wall, 52 bottles of beer.\nTake one down and pass it around, 51 bottles of beer on the wall.\n\n51 bottles of beer on the wall, 51 bottles of beer.\nTake one down and pass it around, 50 bottles of beer on the wall.\n\n50 bottles of beer on the wall, 50 bottles of beer.\nTake one down and pass it around, 49 bottles of beer on the wall.\n\n49 bottles of beer on the wall, 49 bottles of beer.\nTake one down and pass it around, 48 bottles of beer on the wall.\n\n48 bottles of beer on the wall, 48 bottles of beer.\nTake one down and pass it around, 47 bottles of beer on the wall.\n\n47 bottles of beer on the wall, 47 bottles of beer.\nTake one down and pass it around, 46 bottles of beer on the wall.\n\n46 bottles of beer on the wall, 46 bottles of beer.\nTake one down and pass it around, 45 bottles of beer on the wall.\n\n45 bottles of beer on the wall, 45 bottles of beer.\nTake one down and pass it around, 44 bottles of beer on the wall.\n\n44 bottles of beer on the wall, 44 bottles of beer.\nTake one down and pass it around, 43 bottles of beer on the wall.\n\n43 bottles of beer on the wall, 43 bottles of beer.\nTake one down and pass it around, 42 bottles of beer on the wall.\n\n42 bottles of beer on the wall, 42 bottles of beer.\nTake one down and pass it around, 41 bottles of beer on the wall.\n\n41 bottles of beer on the wall, 41 bottles of beer.\nTake one down and pass it around, 40 bottles of beer on the wall.\n\n40 bottles of beer on the wall, 40 bottles of beer.\nTake one down and pass it around, 39 bottles of beer on the wall.\n\n39 bottles of beer on the wall, 39 bottles of beer.\nTake one down and pass it around, 38 bottles of beer on the wall.\n\n38 bottles of beer on the wall, 38 bottles of beer.\nTake one down and pass it around, 37 bottles of beer on the wall.\n\n37 bottles of beer on the wall, 37 bottles of beer.\nTake one down and pass it around, 36 bottles of beer on the wall.\n\n36 bottles of beer on the wall, 36 bottles of beer.\nTake one down and pass it around, 35 bottles of beer on the wall.\n\n35 bottles of beer on the wall, 35 bottles of beer.\nTake one down and pass it around, 34 bottles of beer on the wall.\n\n34 bottles of beer on the wall, 34 bottles of beer.\nTake one down and pass it around, 33 bottles of beer on the wall.\n\n33 bottles of beer on the wall, 33 bottles of beer.\nTake one down and pass it around, 32 bottles of beer on the wall.\n\n32 bottles of beer on the wall, 32 bottles of beer.\nTake one down and pass it around, 31 bottles of beer on the wall.\n\n31 bottles of beer on the wall, 31 bottles of beer.\nTake one down and pass it around, 30 bottles of beer on the wall.\n\n30 bottles of beer on the wall, 30 bottles of beer.\nTake one down and pass it around, 29 bottles of beer on the wall.\n\n29 bottles of beer on the wall, 29 bottles of beer.\nTake one down and pass it around, 28 bottles of beer on the wall.\n\n28 bottles of beer on the wall, 28 bottles of beer.\nTake one down and pass it around, 27 bottles of beer on the wall.\n\n27 bottles of beer on the wall, 27 bottles of beer.\nTake one down and pass it around, 26 bottles of beer on the wall.\n\n26 bottles of beer on the wall, 26 bottles of beer.\nTake one down and pass it around, 25 bottles of beer on the wall.\n\n25 bottles of beer on the wall, 25 bottles of beer.\nTake one down and pass it around, 24 bottles of beer on the wall.\n\n24 bottles of beer on the wall, 24 bottles of beer.\nTake one down and pass it around, 23 bottles of beer on the wall.\n\n23 bottles of beer on the wall, 23 bottles of beer.\nTake one down and pass it around, 22 bottles of beer on the wall.\n\n22 bottles of beer on the wall, 22 bottles of beer.\nTake one down and pass it around, 21 bottles of beer on the wall.\n\n21 bottles of beer on the wall, 21 bottles of beer.\nTake one down and pass it around, 20 bottles of beer on the wall.\n\n20 bottles of beer on the wall, 20 bottles of beer.\nTake one down and pass it around, 19 bottles of beer on the wall.\n\n19 bottles of beer on the wall, 19 bottles of beer.\nTake one down and pass it around, 18 bottles of beer on the wall.\n\n18 bottles of beer on the wall, 18 bottles of beer.\nTake one down and pass it around, 17 bottles of beer on the wall.\n\n17 bottles of beer on the wall, 17 bottles of beer.\nTake one down and pass it around, 16 bottles of beer on the wall.\n\n16 bottles of beer on the wall, 16 bottles of beer.\nTake one down and pass it around, 15 bottles of beer on the wall.\n\n15 bottles of beer on the wall, 15 bottles of beer.\nTake one down and pass it around, 14 bottles of beer on the wall.\n\n14 bottles of beer on the wall, 14 bottles of beer.\nTake one down and pass it around, 13 bottles of beer on the wall.\n\n13 bottles of beer on the wall, 13 bottles of beer.\nTake one down and pass it around, 12 bottles of beer on the wall.\n\n12 bottles of beer on the wall, 12 bottles of beer.\nTake one down and pass it around, 11 bottles of beer on the wall.\n\n11 bottles of beer on the wall, 11 bottles of beer.\nTake one down and pass it around, 10 bottles of beer on the wall.\n\n10 bottles of beer on the wall, 10 bottles of beer.\nTake one down and pass it around, 9 bottles of beer on the wall.\n\n9 bottles of beer on the wall, 9 bottles of beer.\nTake one down and pass it around, 8 bottles of beer on the wall.\n\n8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n\n7 bottles of beer on the wall, 7 bottles of beer.\nTake one down and pass it around, 6 bottles of beer on the wall.\n\n6 bottles of beer on the wall, 6 bottles of beer.\nTake one down and pass it around, 5 bottles of beer on the wall.\n\n5 bottles of beer on the wall, 5 bottles of beer.\nTake one down and pass it around, 4 bottles of beer on the wall.\n\n4 bottles of beer on the wall, 4 bottles of beer.\nTake one down and pass it around, 3 bottles of beer on the wall.\n\n3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n\n2 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\n1 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\nNo 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", BeerSong.Verses(99, 0)); + 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.\n" + + ""; + Assert.Equal(expected, BeerSong.Verses(99, 0)); } } \ No newline at end of file diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index 282d266764..51ffbbf297 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -7,60 +7,176 @@ public class FoodChainTest [Fact] public void Fly() { - Assert.Equal("I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(1)); + var expected = + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(1)); } [Fact(Skip = "Remove to run test")] public void Spider() { - Assert.Equal("I know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(2)); + var expected = + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(2)); } [Fact(Skip = "Remove to run test")] public void Bird() { - Assert.Equal("I know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(3)); + var expected = + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(3)); } [Fact(Skip = "Remove to run test")] public void Cat() { - Assert.Equal("I know an old lady who swallowed a cat.\nImagine that, to swallow a cat!\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(4)); + var expected = + "I know an old lady who swallowed a cat.\n" + + "Imagine that, to swallow a cat!\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(4)); } [Fact(Skip = "Remove to run test")] public void Dog() { - Assert.Equal("I know an old lady who swallowed a dog.\nWhat a hog, to swallow a dog!\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(5)); + var expected = + "I know an old lady who swallowed a dog.\n" + + "What a hog, to swallow a dog!\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(5)); } [Fact(Skip = "Remove to run test")] public void Goat() { - Assert.Equal("I know an old lady who swallowed a goat.\nJust opened her throat and swallowed a goat!\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(6)); + var expected = + "I know an old lady who swallowed a goat.\n" + + "Just opened her throat and swallowed a goat!\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(6)); } [Fact(Skip = "Remove to run test")] public void Cow() { - Assert.Equal("I know an old lady who swallowed a cow.\nI don't know how she swallowed a cow!\nShe swallowed the cow to catch the goat.\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(7)); + var expected = + "I know an old lady who swallowed a cow.\n" + + "I don't know how she swallowed a cow!\n" + + "She swallowed the cow to catch the goat.\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(7)); } [Fact(Skip = "Remove to run test")] public void Horse() { - Assert.Equal("I know an old lady who swallowed a horse.\nShe's dead, of course!", FoodChain.Verse(8)); + var expected = + "I know an old lady who swallowed a horse.\n" + + "She's dead, of course!"; + Assert.Equal(expected, FoodChain.Verse(8)); } [Fact(Skip = "Remove to run test")] public void Multiple_verses() { - Assert.Equal("I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.", FoodChain.Verse(1, 3)); + var expected = + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die."; + Assert.Equal(expected, FoodChain.Verse(1, 3)); } [Fact(Skip = "Remove to run test")] public void Full_song() { - Assert.Equal("I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a cat.\nImagine that, to swallow a cat!\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a dog.\nWhat a hog, to swallow a dog!\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a goat.\nJust opened her throat and swallowed a goat!\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a cow.\nI don't know how she swallowed a cow!\nShe swallowed the cow to catch the goat.\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\n\nI know an old lady who swallowed a horse.\nShe's dead, of course!", FoodChain.Verse(1, 8)); + var expected = + "I know an old lady who swallowed a fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a spider.\n" + + "It wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a bird.\n" + + "How absurd to swallow a bird!\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a cat.\n" + + "Imagine that, to swallow a cat!\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a dog.\n" + + "What a hog, to swallow a dog!\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a goat.\n" + + "Just opened her throat and swallowed a goat!\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a cow.\n" + + "I don't know how she swallowed a cow!\n" + + "She swallowed the cow to catch the goat.\n" + + "She swallowed the goat to catch the dog.\n" + + "She swallowed the dog to catch the cat.\n" + + "She swallowed the cat to catch the bird.\n" + + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + + "She swallowed the spider to catch the fly.\n" + + "I don't know why she swallowed the fly. Perhaps she'll die.\n" + + "\n" + + "I know an old lady who swallowed a horse.\n" + + "She's dead, of course!"; + Assert.Equal(expected, FoodChain.Verse(1, 8)); } } \ No newline at end of file diff --git a/generators/Exercises/BeerSong.cs b/generators/Exercises/BeerSong.cs index 5c8c333eef..0ece079243 100644 --- a/generators/Exercises/BeerSong.cs +++ b/generators/Exercises/BeerSong.cs @@ -1,6 +1,13 @@ -namespace Generators.Exercises +using Generators.Output; + +namespace Generators.Exercises { public class BeerSong : Exercise { + public BeerSong() + { + foreach (var canonicalDataCase in CanonicalData.Cases) + canonicalDataCase.Expected = new MultiLineString(canonicalDataCase.Expected.ToString()); + } } } \ No newline at end of file diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index 5171d1f13a..fb4ed432da 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using Generators.Output; +using Newtonsoft.Json.Linq; namespace Generators.Exercises { @@ -7,7 +8,7 @@ public class FoodChain : Exercise public FoodChain() { foreach (var canonicalDataCase in CanonicalData.Cases) - canonicalDataCase.Expected = string.Join("\n", ((JArray)canonicalDataCase.Expected).Values()); + canonicalDataCase.Expected = new MultiLineString(((JArray)canonicalDataCase.Expected).Values()); } } } \ No newline at end of file diff --git a/generators/Output/EqualityTestMethodGenerator.cs b/generators/Output/EqualityTestMethodGenerator.cs index fb1a8373c0..b46a1a42d0 100644 --- a/generators/Output/EqualityTestMethodGenerator.cs +++ b/generators/Output/EqualityTestMethodGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace Generators.Output { @@ -12,16 +13,24 @@ protected override IEnumerable Body switch (Configuration.TestedMethodType) { case TestedMethodType.Static: + if (UseVariableForExpected) + return ExpectedVariableDeclaration.Concat(new[] { $"Assert.Equal(expected, {TestedClassName}.{TestedMethodName}({Input}));" }); + return new[] { $"Assert.Equal({Expected}, {TestedClassName}.{TestedMethodName}({Input}));" }; case TestedMethodType.Instance: + if (UseVariableForExpected) + return ExpectedVariableDeclaration.Concat(new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal(expected, sut.{TestedMethodName}({Input}));" }); + return new[] { $"var sut = new {TestedClassName}();", $"Assert.Equal({Expected}, sut.{TestedMethodName}({Input}));" }; case TestedMethodType.Extension: + if (UseVariableForExpected) + return ExpectedVariableDeclaration.Concat(new[] { $"Assert.Equal(expected, {Input}.{TestedMethodName}());" }); + return new[] { $"Assert.Equal({Expected}, {Input}.{TestedMethodName}());" }; default: throw new ArgumentOutOfRangeException(); } } } - } } \ No newline at end of file diff --git a/generators/Output/MultiLineString.cs b/generators/Output/MultiLineString.cs new file mode 100644 index 0000000000..c56ef6c671 --- /dev/null +++ b/generators/Output/MultiLineString.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; + +namespace Generators.Output +{ + public class MultiLineString : IEnumerable + { + private readonly IEnumerable _lines; + + public MultiLineString(string str) : this(str.Split('\n')) + { + } + + public MultiLineString(IEnumerable lines) => _lines = lines; + + public IEnumerator GetEnumerator() => _lines.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} \ No newline at end of file diff --git a/generators/Output/TestMethodGenerator.cs b/generators/Output/TestMethodGenerator.cs index 0309a893d5..fa4d2600af 100644 --- a/generators/Output/TestMethodGenerator.cs +++ b/generators/Output/TestMethodGenerator.cs @@ -26,5 +26,7 @@ public TestMethod Create(CanonicalDataCase canonicalDataCase, Exercise exercise) protected object Input => ValueFormatter.Format(CanonicalDataCase.Input); protected object Expected => ValueFormatter.Format(CanonicalDataCase.Expected); + protected IEnumerable ExpectedVariableDeclaration => ValueFormatter.FormatVariable(CanonicalDataCase.Expected); + protected bool UseVariableForExpected => CanonicalDataCase.Expected is MultiLineString; } } \ No newline at end of file diff --git a/generators/Output/ValueFormatter.cs b/generators/Output/ValueFormatter.cs index ae33e4acbe..305765effc 100644 --- a/generators/Output/ValueFormatter.cs +++ b/generators/Output/ValueFormatter.cs @@ -12,18 +12,40 @@ public static object Format(object val) { case IDictionary dict: return string.Join(", ", dict.Values.Select(Format)); - case Enum e: - return $"{e.GetType().Name}.{e}"; - case string s: - return $"\"{s.EscapeControlCharacters()}\""; + case Enum enumeration: + return $"{enumeration.GetType().Name}.{enumeration}";; + case IEnumerable strings: + return strings.Select(FormatString); + case string str: + return str.FormatString(); default: return val; } } - private static string EscapeControlCharacters(this string s) + public static IEnumerable FormatVariable(object val) + { + switch (val) + { + case MultiLineString multiLineString: + var lines = new List {"var expected = "}; + return lines.Concat( + multiLineString + .Select((t, i) => i < multiLineString.Count() - 1 + ? $" {Format(t + "\n")} +" + : $" {Format(t)};")); + default: + return new[] {$"var expected = {Format(val)};"}; + } + } + + private static string FormatString(this string s) => s.EscapeControlCharacters().Quote(); + + private static string EscapeControlCharacters(this string s) => s.Replace("\n", "\\n") .Replace("\t", "\\t") .Replace("\r", "\\r"); + + private static string Quote(this string s) => $"\"{s}\""; } } \ No newline at end of file From 211eba49171496f5a6f714e9d3fa229e1fa23979 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 22 Jun 2017 20:10:34 +0200 Subject: [PATCH 21/22] Allow easy exercise extension points --- generators/Exercise.cs | 7 +++++ .../Input/CanonicalDataCaseJsonConverter.cs | 13 ++++++--- generators/Output/TestClass.cs | 4 +-- generators/Output/TestClassFile.cs | 22 +++++++++++++++ generators/Output/TestFileGenerator.cs | 28 ------------------- generators/Program.cs | 3 +- 6 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 generators/Output/TestClassFile.cs delete mode 100644 generators/Output/TestFileGenerator.cs diff --git a/generators/Exercise.cs b/generators/Exercise.cs index 12ca05dc44..48d254ad05 100644 --- a/generators/Exercise.cs +++ b/generators/Exercise.cs @@ -1,4 +1,5 @@ using Generators.Input; +using Generators.Output; using Humanizer; namespace Generators @@ -15,5 +16,11 @@ protected Exercise() public string Name { get; } public CanonicalData CanonicalData { get; } public ExerciseConfiguration Configuration { get; } + + public void Generate() => TestClassFile.Write(this, Render()); + + protected virtual string Render() => TestClassRenderer.Render(CreateTestClass()); + + protected virtual TestClass CreateTestClass() => TestClassGenerator.Create(this); } } \ No newline at end of file diff --git a/generators/Input/CanonicalDataCaseJsonConverter.cs b/generators/Input/CanonicalDataCaseJsonConverter.cs index d59948bd17..a4b8573bf9 100644 --- a/generators/Input/CanonicalDataCaseJsonConverter.cs +++ b/generators/Input/CanonicalDataCaseJsonConverter.cs @@ -17,15 +17,20 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var canonicalDataCase = new CanonicalDataCase(); serializer.Populate(new JTokenReader(jToken), canonicalDataCase); - + + canonicalDataCase.Input = GetInputProperties(jToken); + + return canonicalDataCase; + } + + private static IDictionary GetInputProperties(JToken jToken) + { var allProperties = jToken.ToObject>(); foreach (var nonInputProperty in NonInputProperties) allProperties.Remove(nonInputProperty); - canonicalDataCase.Input = allProperties; - - return canonicalDataCase; + return allProperties; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException(); diff --git a/generators/Output/TestClass.cs b/generators/Output/TestClass.cs index 8bc6cd6f41..f2fa1bd6e4 100644 --- a/generators/Output/TestClass.cs +++ b/generators/Output/TestClass.cs @@ -4,9 +4,9 @@ namespace Generators.Output { public class TestClass { - public ISet UsingNamespaces { get; set; } = new HashSet { "Xunit" }; public string ClassName { get; set; } - public TestMethod[] TestMethods { get; set; } public string CanonicalDataVersion { get; set; } + public TestMethod[] TestMethods { get; set; } + public ISet UsingNamespaces { get; } = new HashSet { "Xunit" }; } } \ No newline at end of file diff --git a/generators/Output/TestClassFile.cs b/generators/Output/TestClassFile.cs new file mode 100644 index 0000000000..bf1e90f06f --- /dev/null +++ b/generators/Output/TestClassFile.cs @@ -0,0 +1,22 @@ +using System.IO; +using Serilog; + +namespace Generators.Output +{ + public static class TestClassFile + { + public static void Write(Exercise exercise, string contents) + { + var testClassFilePath = TestClassFilePath(exercise); + + Directory.CreateDirectory(Path.GetDirectoryName(testClassFilePath)); + File.WriteAllText(testClassFilePath, contents); + + Log.Information("Generated tests for {Exercise} exercise in {TestFile}.", exercise.Name, testClassFilePath); + } + + private static string TestClassFilePath(Exercise exercise) => Path.Combine("..", "exercises", exercise.Name, TestClassFileName(exercise)); + + private static string TestClassFileName(Exercise exercise) => $"{exercise.Name.ToTestClassName()}.cs"; + } +} \ No newline at end of file diff --git a/generators/Output/TestFileGenerator.cs b/generators/Output/TestFileGenerator.cs deleted file mode 100644 index 49d9397365..0000000000 --- a/generators/Output/TestFileGenerator.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.IO; -using Serilog; - -namespace Generators.Output -{ - public static class TestFileGenerator - { - public static void Generate(Exercise exercise) - { - var testClass = TestClassGenerator.Create(exercise); - var testClassContents = TestClassRenderer.Render(testClass); - var testClassFilePath = TestFilePath(exercise, testClass); - - SaveTestClassContentsToFile(testClassFilePath, testClassContents); - Log.Information("Generated tests for {Exercise} exercise in {TestFile}.", exercise.Name, testClassFilePath); - } - - private static void SaveTestClassContentsToFile(string testClassFilePath, string testClassContents) - { - Directory.CreateDirectory(Path.GetDirectoryName(testClassFilePath)); - File.WriteAllText(testClassFilePath, testClassContents); - } - - private static string TestFilePath(Exercise exercise, TestClass testClass) => Path.Combine("..", "exercises", exercise.Name, TestFileName(testClass)); - - private static string TestFileName(TestClass testClass) => $"{testClass.ClassName}.cs"; - } -} \ No newline at end of file diff --git a/generators/Program.cs b/generators/Program.cs index ae0239b832..695dc8fcac 100644 --- a/generators/Program.cs +++ b/generators/Program.cs @@ -1,5 +1,4 @@ using Generators.Input; -using Generators.Output; using Serilog; namespace Generators @@ -24,7 +23,7 @@ private static void GenerateAll() Log.Information("Generating tests..."); foreach (var exercise in new ExerciseCollection()) - TestFileGenerator.Generate(exercise); + exercise.Generate(); Log.Information("Generated tests."); } From 217e60e6bee19de2105fde0ba075b743041891ec Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 22 Jun 2017 20:23:38 +0200 Subject: [PATCH 22/22] Update .NET CLI and Cake version in build script --- build.ps1 | 4 ++-- build.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.ps1 b/build.ps1 index 2a2706a8bf..1299bd1585 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,5 +1,5 @@ -$CakeVersion = "0.18.0" -$DotNetVersion = "1.0.1"; +$CakeVersion = "0.20.0" +$DotNetVersion = "1.0.4"; $DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1"; # Make sure tools folder exists diff --git a/build.sh b/build.sh index 53b611e53f..d3f79d470d 100755 --- a/build.sh +++ b/build.sh @@ -3,9 +3,9 @@ # Define directories. SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) TOOLS_DIR=$SCRIPT_DIR/tools -CAKE_VERSION=0.18.0 +CAKE_VERSION=0.20.0 CAKE_DLL=$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION/Cake.dll -DOTNET_VERSION=1.0.1 +DOTNET_VERSION=1.0.4 # Make sure the tools folder exist. if [ ! -d "$TOOLS_DIR" ]; then