Skip to content

Commit 9f5cc64

Browse files
Simplify
1 parent 06b2035 commit 9f5cc64

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

exercises/practice/hamming/.meta/Generator.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class HammingTests
66
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
77
public void {{test_method_name}}()
88
{
9-
{{#if error}}
9+
{{#if expected.error}}
1010
Assert.Throws<ArgumentException>(() => Hamming.Distance({{lit input.strand1}}, {{lit input.strand2}}));
1111
{{else}}
1212
Assert.Equal({{expected}}, Hamming.Distance({{lit input.strand1}}, {{lit input.strand2}}));

exercises/practice/perfect-numbers/.meta/Generator.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class PerfectNumbersTests
66
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
77
public void {{test_method_name}}()
88
{
9-
{{#if error}}
9+
{{#if expected.error}}
1010
Assert.Throws<ArgumentOutOfRangeException>(() => PerfectNumbers.Classify({{input.number}}));
1111
{{else}}
1212
Assert.Equal(Classification.{{Capitalize expected}}, PerfectNumbers.Classify({{input.number}}));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Xunit;
2+
3+
public class WordyTests
4+
{
5+
{{#test_cases}}
6+
[Fact{{#unless @first}}(Skip = "Remove this Skip property to run this test"){{/unless}}]
7+
public void {{test_method_name}}()
8+
{
9+
{{#if expected.error}}
10+
Assert.Throws<ArgumentException>(() => Wordy.Answer({{lit input.question}}));
11+
{{else}}
12+
Assert.Equal({{expected}}, Wordy.Answer({{lit input.question}}));
13+
{{/if}}
14+
}
15+
{{/test_cases}}
16+
}

exercises/practice/wordy/WordyTests.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
21
using Xunit;
32

43
public class WordyTests
54
{
65
[Fact]
7-
public void Just_a_number()
6+
public void JustANumber()
87
{
98
Assert.Equal(5, Wordy.Answer("What is 5?"));
109
}
@@ -16,19 +15,19 @@ public void Addition()
1615
}
1716

1817
[Fact(Skip = "Remove this Skip property to run this test")]
19-
public void More_addition()
18+
public void MoreAddition()
2019
{
2120
Assert.Equal(55, Wordy.Answer("What is 53 plus 2?"));
2221
}
2322

2423
[Fact(Skip = "Remove this Skip property to run this test")]
25-
public void Addition_with_negative_numbers()
24+
public void AdditionWithNegativeNumbers()
2625
{
2726
Assert.Equal(-11, Wordy.Answer("What is -1 plus -10?"));
2827
}
2928

3029
[Fact(Skip = "Remove this Skip property to run this test")]
31-
public void Large_addition()
30+
public void LargeAddition()
3231
{
3332
Assert.Equal(45801, Wordy.Answer("What is 123 plus 45678?"));
3433
}
@@ -52,91 +51,91 @@ public void Division()
5251
}
5352

5453
[Fact(Skip = "Remove this Skip property to run this test")]
55-
public void Multiple_additions()
54+
public void MultipleAdditions()
5655
{
5756
Assert.Equal(3, Wordy.Answer("What is 1 plus 1 plus 1?"));
5857
}
5958

6059
[Fact(Skip = "Remove this Skip property to run this test")]
61-
public void Addition_and_subtraction()
60+
public void AdditionAndSubtraction()
6261
{
6362
Assert.Equal(8, Wordy.Answer("What is 1 plus 5 minus -2?"));
6463
}
6564

6665
[Fact(Skip = "Remove this Skip property to run this test")]
67-
public void Multiple_subtraction()
66+
public void MultipleSubtraction()
6867
{
6968
Assert.Equal(3, Wordy.Answer("What is 20 minus 4 minus 13?"));
7069
}
7170

7271
[Fact(Skip = "Remove this Skip property to run this test")]
73-
public void Subtraction_then_addition()
72+
public void SubtractionThenAddition()
7473
{
7574
Assert.Equal(14, Wordy.Answer("What is 17 minus 6 plus 3?"));
7675
}
7776

7877
[Fact(Skip = "Remove this Skip property to run this test")]
79-
public void Multiple_multiplication()
78+
public void MultipleMultiplication()
8079
{
8180
Assert.Equal(-12, Wordy.Answer("What is 2 multiplied by -2 multiplied by 3?"));
8281
}
8382

8483
[Fact(Skip = "Remove this Skip property to run this test")]
85-
public void Addition_and_multiplication()
84+
public void AdditionAndMultiplication()
8685
{
8786
Assert.Equal(-8, Wordy.Answer("What is -3 plus 7 multiplied by -2?"));
8887
}
8988

9089
[Fact(Skip = "Remove this Skip property to run this test")]
91-
public void Multiple_division()
90+
public void MultipleDivision()
9291
{
9392
Assert.Equal(2, Wordy.Answer("What is -12 divided by 2 divided by -3?"));
9493
}
9594

9695
[Fact(Skip = "Remove this Skip property to run this test")]
97-
public void Unknown_operation()
96+
public void UnknownOperation()
9897
{
9998
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is 52 cubed?"));
10099
}
101100

102101
[Fact(Skip = "Remove this Skip property to run this test")]
103-
public void Non_math_question()
102+
public void NonMathQuestion()
104103
{
105104
Assert.Throws<ArgumentException>(() => Wordy.Answer("Who is the President of the United States?"));
106105
}
107106

108107
[Fact(Skip = "Remove this Skip property to run this test")]
109-
public void Reject_problem_missing_an_operand()
108+
public void RejectProblemMissingAnOperand()
110109
{
111110
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is 1 plus?"));
112111
}
113112

114113
[Fact(Skip = "Remove this Skip property to run this test")]
115-
public void Reject_problem_with_no_operands_or_operators()
114+
public void RejectProblemWithNoOperandsOrOperators()
116115
{
117116
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is?"));
118117
}
119118

120119
[Fact(Skip = "Remove this Skip property to run this test")]
121-
public void Reject_two_operations_in_a_row()
120+
public void RejectTwoOperationsInARow()
122121
{
123122
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is 1 plus plus 2?"));
124123
}
125124

126125
[Fact(Skip = "Remove this Skip property to run this test")]
127-
public void Reject_two_numbers_in_a_row()
126+
public void RejectTwoNumbersInARow()
128127
{
129128
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is 1 plus 2 1?"));
130129
}
131130

132131
[Fact(Skip = "Remove this Skip property to run this test")]
133-
public void Reject_postfix_notation()
132+
public void RejectPostfixNotation()
134133
{
135134
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is 1 2 plus?"));
136135
}
137136

138137
[Fact(Skip = "Remove this Skip property to run this test")]
139-
public void Reject_prefix_notation()
138+
public void RejectPrefixNotation()
140139
{
141140
Assert.Throws<ArgumentException>(() => Wordy.Answer("What is plus 1 2?"));
142141
}

generators.new/CanonicalData.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,8 @@ private static IEnumerable<JObject> ParseTestCases(JObject jsonObject, Immutable
3434
private static JObject ToTestCase(JObject testCaseJson, IEnumerable<string> path)
3535
{
3636
testCaseJson["path"] = JArray.FromObject(path);
37-
testCaseJson["error"] = ToError(testCaseJson);
3837
return testCaseJson;
3938
}
40-
41-
private static JToken? ToError(JObject testCaseJson)
42-
{
43-
if (testCaseJson["expected"] is JObject expectedJson &&
44-
expectedJson.TryGetValue("error", out var error))
45-
return error.DeepClone();
46-
47-
return null;
48-
}
4939

5040
private static class ProbSpecs
5141
{

0 commit comments

Comments
 (0)