Skip to content

Commit 5854b9b

Browse files
ErikSchierboomrobkeim
authored andcommitted
Simplify generators (#302)
* Simplify generators * Small refactoring * Use enumerable for body input * Simplify options * Namespace refactoring * Use dotliquid template engine * Remove unused body * Simplify options * Simplified objects * Remove exercise inheritance * Extracted test class generator * Make generators simpler * Infer expected test method type * Remove unused using statement * Simplify value formatting * Fix unknown exception type namespaces * Prefix Luhn property with "Is" * Fix leap exercise * Remove unused code * Fix multi-line variables * Allow easy exercise extension points * Update .NET CLI and Cake version in build script
1 parent 5bf182d commit 5854b9b

84 files changed

Lines changed: 1034 additions & 1354 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
$CakeVersion = "0.18.0"
2-
$DotNetVersion = "1.0.1";
1+
$CakeVersion = "0.20.0"
2+
$DotNetVersion = "1.0.4";
33
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
44

55
# Make sure tools folder exists

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Define directories.
44
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
55
TOOLS_DIR=$SCRIPT_DIR/tools
6-
CAKE_VERSION=0.18.0
6+
CAKE_VERSION=0.20.0
77
CAKE_DLL=$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION/Cake.dll
8-
DOTNET_VERSION=1.0.1
8+
DOTNET_VERSION=1.0.4
99

1010
# Make sure the tools folder exist.
1111
if [ ! -d "$TOOLS_DIR" ]; then

exercises/beer-song/BeerSongTest.cs

Lines changed: 322 additions & 322 deletions
Large diffs are not rendered by default.

exercises/bob/BobTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file was auto-generated based on version 1.0.0 of the canonical data.
2+
13
using Xunit;
24

35
public class BobTest

exercises/food-chain/FoodChainTest.cs

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class FoodChainTest
88
public void Fly()
99
{
1010
var expected =
11-
"I know an old lady who swallowed a fly.\n"+
11+
"I know an old lady who swallowed a fly.\n" +
1212
"I don't know why she swallowed the fly. Perhaps she'll die.";
1313
Assert.Equal(expected, FoodChain.Verse(1));
1414
}
@@ -17,9 +17,9 @@ public void Fly()
1717
public void Spider()
1818
{
1919
var expected =
20-
"I know an old lady who swallowed a spider.\n"+
21-
"It wriggled and jiggled and tickled inside her.\n"+
22-
"She swallowed the spider to catch the fly.\n"+
20+
"I know an old lady who swallowed a spider.\n" +
21+
"It wriggled and jiggled and tickled inside her.\n" +
22+
"She swallowed the spider to catch the fly.\n" +
2323
"I don't know why she swallowed the fly. Perhaps she'll die.";
2424
Assert.Equal(expected, FoodChain.Verse(2));
2525
}
@@ -28,10 +28,10 @@ public void Spider()
2828
public void Bird()
2929
{
3030
var expected =
31-
"I know an old lady who swallowed a bird.\n"+
32-
"How absurd to swallow a bird!\n"+
33-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
34-
"She swallowed the spider to catch the fly.\n"+
31+
"I know an old lady who swallowed a bird.\n" +
32+
"How absurd to swallow a bird!\n" +
33+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
34+
"She swallowed the spider to catch the fly.\n" +
3535
"I don't know why she swallowed the fly. Perhaps she'll die.";
3636
Assert.Equal(expected, FoodChain.Verse(3));
3737
}
@@ -40,11 +40,11 @@ public void Bird()
4040
public void Cat()
4141
{
4242
var expected =
43-
"I know an old lady who swallowed a cat.\n"+
44-
"Imagine that, to swallow a cat!\n"+
45-
"She swallowed the cat to catch the bird.\n"+
46-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
47-
"She swallowed the spider to catch the fly.\n"+
43+
"I know an old lady who swallowed a cat.\n" +
44+
"Imagine that, to swallow a cat!\n" +
45+
"She swallowed the cat to catch the bird.\n" +
46+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
47+
"She swallowed the spider to catch the fly.\n" +
4848
"I don't know why she swallowed the fly. Perhaps she'll die.";
4949
Assert.Equal(expected, FoodChain.Verse(4));
5050
}
@@ -53,12 +53,12 @@ public void Cat()
5353
public void Dog()
5454
{
5555
var expected =
56-
"I know an old lady who swallowed a dog.\n"+
57-
"What a hog, to swallow a dog!\n"+
58-
"She swallowed the dog to catch the cat.\n"+
59-
"She swallowed the cat to catch the bird.\n"+
60-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
61-
"She swallowed the spider to catch the fly.\n"+
56+
"I know an old lady who swallowed a dog.\n" +
57+
"What a hog, to swallow a dog!\n" +
58+
"She swallowed the dog to catch the cat.\n" +
59+
"She swallowed the cat to catch the bird.\n" +
60+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
61+
"She swallowed the spider to catch the fly.\n" +
6262
"I don't know why she swallowed the fly. Perhaps she'll die.";
6363
Assert.Equal(expected, FoodChain.Verse(5));
6464
}
@@ -67,13 +67,13 @@ public void Dog()
6767
public void Goat()
6868
{
6969
var expected =
70-
"I know an old lady who swallowed a goat.\n"+
71-
"Just opened her throat and swallowed a goat!\n"+
72-
"She swallowed the goat to catch the dog.\n"+
73-
"She swallowed the dog to catch the cat.\n"+
74-
"She swallowed the cat to catch the bird.\n"+
75-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
76-
"She swallowed the spider to catch the fly.\n"+
70+
"I know an old lady who swallowed a goat.\n" +
71+
"Just opened her throat and swallowed a goat!\n" +
72+
"She swallowed the goat to catch the dog.\n" +
73+
"She swallowed the dog to catch the cat.\n" +
74+
"She swallowed the cat to catch the bird.\n" +
75+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
76+
"She swallowed the spider to catch the fly.\n" +
7777
"I don't know why she swallowed the fly. Perhaps she'll die.";
7878
Assert.Equal(expected, FoodChain.Verse(6));
7979
}
@@ -82,14 +82,14 @@ public void Goat()
8282
public void Cow()
8383
{
8484
var expected =
85-
"I know an old lady who swallowed a cow.\n"+
86-
"I don't know how she swallowed a cow!\n"+
87-
"She swallowed the cow to catch the goat.\n"+
88-
"She swallowed the goat to catch the dog.\n"+
89-
"She swallowed the dog to catch the cat.\n"+
90-
"She swallowed the cat to catch the bird.\n"+
91-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
92-
"She swallowed the spider to catch the fly.\n"+
85+
"I know an old lady who swallowed a cow.\n" +
86+
"I don't know how she swallowed a cow!\n" +
87+
"She swallowed the cow to catch the goat.\n" +
88+
"She swallowed the goat to catch the dog.\n" +
89+
"She swallowed the dog to catch the cat.\n" +
90+
"She swallowed the cat to catch the bird.\n" +
91+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
92+
"She swallowed the spider to catch the fly.\n" +
9393
"I don't know why she swallowed the fly. Perhaps she'll die.";
9494
Assert.Equal(expected, FoodChain.Verse(7));
9595
}
@@ -98,7 +98,7 @@ public void Cow()
9898
public void Horse()
9999
{
100100
var expected =
101-
"I know an old lady who swallowed a horse.\n"+
101+
"I know an old lady who swallowed a horse.\n" +
102102
"She's dead, of course!";
103103
Assert.Equal(expected, FoodChain.Verse(8));
104104
}
@@ -107,18 +107,18 @@ public void Horse()
107107
public void Multiple_verses()
108108
{
109109
var expected =
110-
"I know an old lady who swallowed a fly.\n"+
111-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
112-
"\n"+
113-
"I know an old lady who swallowed a spider.\n"+
114-
"It wriggled and jiggled and tickled inside her.\n"+
115-
"She swallowed the spider to catch the fly.\n"+
116-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
117-
"\n"+
118-
"I know an old lady who swallowed a bird.\n"+
119-
"How absurd to swallow a bird!\n"+
120-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
121-
"She swallowed the spider to catch the fly.\n"+
110+
"I know an old lady who swallowed a fly.\n" +
111+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
112+
"\n" +
113+
"I know an old lady who swallowed a spider.\n" +
114+
"It wriggled and jiggled and tickled inside her.\n" +
115+
"She swallowed the spider to catch the fly.\n" +
116+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
117+
"\n" +
118+
"I know an old lady who swallowed a bird.\n" +
119+
"How absurd to swallow a bird!\n" +
120+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
121+
"She swallowed the spider to catch the fly.\n" +
122122
"I don't know why she swallowed the fly. Perhaps she'll die.";
123123
Assert.Equal(expected, FoodChain.Verse(1, 3));
124124
}
@@ -127,55 +127,55 @@ public void Multiple_verses()
127127
public void Full_song()
128128
{
129129
var expected =
130-
"I know an old lady who swallowed a fly.\n"+
131-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
132-
"\n"+
133-
"I know an old lady who swallowed a spider.\n"+
134-
"It wriggled and jiggled and tickled inside her.\n"+
135-
"She swallowed the spider to catch the fly.\n"+
136-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
137-
"\n"+
138-
"I know an old lady who swallowed a bird.\n"+
139-
"How absurd to swallow a bird!\n"+
140-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
141-
"She swallowed the spider to catch the fly.\n"+
142-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
143-
"\n"+
144-
"I know an old lady who swallowed a cat.\n"+
145-
"Imagine that, to swallow a cat!\n"+
146-
"She swallowed the cat to catch the bird.\n"+
147-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
148-
"She swallowed the spider to catch the fly.\n"+
149-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
150-
"\n"+
151-
"I know an old lady who swallowed a dog.\n"+
152-
"What a hog, to swallow a dog!\n"+
153-
"She swallowed the dog to catch the cat.\n"+
154-
"She swallowed the cat to catch the bird.\n"+
155-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
156-
"She swallowed the spider to catch the fly.\n"+
157-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
158-
"\n"+
159-
"I know an old lady who swallowed a goat.\n"+
160-
"Just opened her throat and swallowed a goat!\n"+
161-
"She swallowed the goat to catch the dog.\n"+
162-
"She swallowed the dog to catch the cat.\n"+
163-
"She swallowed the cat to catch the bird.\n"+
164-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
165-
"She swallowed the spider to catch the fly.\n"+
166-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
167-
"\n"+
168-
"I know an old lady who swallowed a cow.\n"+
169-
"I don't know how she swallowed a cow!\n"+
170-
"She swallowed the cow to catch the goat.\n"+
171-
"She swallowed the goat to catch the dog.\n"+
172-
"She swallowed the dog to catch the cat.\n"+
173-
"She swallowed the cat to catch the bird.\n"+
174-
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n"+
175-
"She swallowed the spider to catch the fly.\n"+
176-
"I don't know why she swallowed the fly. Perhaps she'll die.\n"+
177-
"\n"+
178-
"I know an old lady who swallowed a horse.\n"+
130+
"I know an old lady who swallowed a fly.\n" +
131+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
132+
"\n" +
133+
"I know an old lady who swallowed a spider.\n" +
134+
"It wriggled and jiggled and tickled inside her.\n" +
135+
"She swallowed the spider to catch the fly.\n" +
136+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
137+
"\n" +
138+
"I know an old lady who swallowed a bird.\n" +
139+
"How absurd to swallow a bird!\n" +
140+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
141+
"She swallowed the spider to catch the fly.\n" +
142+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
143+
"\n" +
144+
"I know an old lady who swallowed a cat.\n" +
145+
"Imagine that, to swallow a cat!\n" +
146+
"She swallowed the cat to catch the bird.\n" +
147+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
148+
"She swallowed the spider to catch the fly.\n" +
149+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
150+
"\n" +
151+
"I know an old lady who swallowed a dog.\n" +
152+
"What a hog, to swallow a dog!\n" +
153+
"She swallowed the dog to catch the cat.\n" +
154+
"She swallowed the cat to catch the bird.\n" +
155+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
156+
"She swallowed the spider to catch the fly.\n" +
157+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
158+
"\n" +
159+
"I know an old lady who swallowed a goat.\n" +
160+
"Just opened her throat and swallowed a goat!\n" +
161+
"She swallowed the goat to catch the dog.\n" +
162+
"She swallowed the dog to catch the cat.\n" +
163+
"She swallowed the cat to catch the bird.\n" +
164+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
165+
"She swallowed the spider to catch the fly.\n" +
166+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
167+
"\n" +
168+
"I know an old lady who swallowed a cow.\n" +
169+
"I don't know how she swallowed a cow!\n" +
170+
"She swallowed the cow to catch the goat.\n" +
171+
"She swallowed the goat to catch the dog.\n" +
172+
"She swallowed the dog to catch the cat.\n" +
173+
"She swallowed the cat to catch the bird.\n" +
174+
"She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
175+
"She swallowed the spider to catch the fly.\n" +
176+
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
177+
"\n" +
178+
"I know an old lady who swallowed a horse.\n" +
179179
"She's dead, of course!";
180180
Assert.Equal(expected, FoodChain.Verse(1, 8));
181181
}

exercises/nth-prime/NthPrimeTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This file was auto-generated based on version 1.0.0 of the canonical data.
22

33
using Xunit;
4-
using System;
54

65
public class NthPrimeTest
76
{
@@ -32,6 +31,6 @@ public void Big_prime()
3231
[Fact(Skip = "Remove to run test")]
3332
public void There_is_no_zeroth_prime()
3433
{
35-
Assert.Throws<ArgumentOutOfRangeException>(() => NthPrime.Prime(0));
34+
Assert.Throws<System.ArgumentOutOfRangeException>(() => NthPrime.Prime(0));
3635
}
3736
}

exercises/perfect-numbers/PerfectNumbersTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This file was auto-generated based on version 1.0.1 of the canonical data.
22

33
using Xunit;
4-
using System;
54

65
public class PerfectNumbersTest
76
{
@@ -74,12 +73,12 @@ public void Edge_case_no_factors_other_than_itself_is_classified_correctly()
7473
[Fact(Skip = "Remove to run test")]
7574
public void Zero_is_rejected_not_a_natural_number_()
7675
{
77-
Assert.Throws<ArgumentOutOfRangeException>(() => PerfectNumbers.Classify(0));
76+
Assert.Throws<System.ArgumentOutOfRangeException>(() => PerfectNumbers.Classify(0));
7877
}
7978

8079
[Fact(Skip = "Remove to run test")]
8180
public void Negative_integer_is_rejected_not_a_natural_number_()
8281
{
83-
Assert.Throws<ArgumentOutOfRangeException>(() => PerfectNumbers.Classify(-1));
82+
Assert.Throws<System.ArgumentOutOfRangeException>(() => PerfectNumbers.Classify(-1));
8483
}
8584
}

exercises/wordy/WordyTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This file was auto-generated based on version 1.0.0 of the canonical data.
22

33
using Xunit;
4-
using System;
54

65
public class WordyTest
76
{
@@ -92,12 +91,12 @@ public void Multiple_division()
9291
[Fact(Skip = "Remove to run test")]
9392
public void Unknown_operation()
9493
{
95-
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is 52 cubed?"));
94+
Assert.Throws<System.ArgumentException>(() => Wordy.Answer("What is 52 cubed?"));
9695
}
9796

9897
[Fact(Skip = "Remove to run test")]
9998
public void Non_math_question()
10099
{
101-
Assert.Throws<ArgumentException>(() => Wordy.Answer("Who is the President of the United States?"));
100+
Assert.Throws<System.ArgumentException>(() => Wordy.Answer("Who is the President of the United States?"));
102101
}
103102
}

generators/Classes/TestClass.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

generators/Classes/TestClassNameTransformer.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)