Skip to content

Commit 0bd0462

Browse files
ErikSchierboomrobkeim
authored andcommitted
Update test suites (#763)
* hamming: update test suite * list-ops: update test suite * simple-cipher: update test suite * word-count: update test suite * high-scores: update test suite * darts: update test suite * rational-numbers: update test suite
1 parent a5ab60b commit 0bd0462

File tree

11 files changed

+79
-79
lines changed

11 files changed

+79
-79
lines changed

config.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@
8080
"unlocked_by": null,
8181
"difficulty": 1,
8282
"topics": [
83-
"lists",
84-
"strings"
83+
"lists"
8584
]
8685
},
8786
{
@@ -1390,4 +1389,4 @@
13901389
]
13911390
}
13921391
]
1393-
}
1392+
}

exercises/darts/DartsTest.cs

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

33
using Xunit;
44

@@ -7,30 +7,42 @@ public class DartsTest
77
[Fact]
88
public void A_dart_lands_outside_the_target()
99
{
10-
Assert.Equal(0, Darts.Score(15.3, 13.2));
10+
Assert.Equal(0, Darts.Score(-9, 9));
1111
}
1212

1313
[Fact(Skip = "Remove to run test")]
1414
public void A_dart_lands_just_in_the_border_of_the_target()
1515
{
16-
Assert.Equal(1, Darts.Score(10, 0));
16+
Assert.Equal(1, Darts.Score(0, 10));
17+
}
18+
19+
[Fact(Skip = "Remove to run test")]
20+
public void A_dart_lands_in_the_outer_circle()
21+
{
22+
Assert.Equal(1, Darts.Score(4, 4));
23+
}
24+
25+
[Fact(Skip = "Remove to run test")]
26+
public void A_dart_lands_right_in_the_border_between_outer_and_middle_circles()
27+
{
28+
Assert.Equal(5, Darts.Score(5, 0));
1729
}
1830

1931
[Fact(Skip = "Remove to run test")]
2032
public void A_dart_lands_in_the_middle_circle()
2133
{
22-
Assert.Equal(5, Darts.Score(3, 3.7));
34+
Assert.Equal(5, Darts.Score(0.8, -0.8));
2335
}
2436

2537
[Fact(Skip = "Remove to run test")]
26-
public void A_dart_lands_right_in_the_border_between_outside_and_middle_circles()
38+
public void A_dart_lands_right_in_the_border_between_middle_and_inner_circles()
2739
{
28-
Assert.Equal(5, Darts.Score(0, 5));
40+
Assert.Equal(10, Darts.Score(0, -1));
2941
}
3042

3143
[Fact(Skip = "Remove to run test")]
3244
public void A_dart_lands_in_the_inner_circle()
3345
{
34-
Assert.Equal(10, Darts.Score(0, 0));
46+
Assert.Equal(10, Darts.Score(-0.1, -0.1));
3547
}
3648
}

exercises/hamming/HammingTest.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was auto-generated based on version 2.2.0 of the canonical data.
1+
// This file was auto-generated based on version 2.3.0 of the canonical data.
22

33
using System;
44
using Xunit;
@@ -46,4 +46,16 @@ public void Disallow_second_strand_longer()
4646
{
4747
Assert.Throws<ArgumentException>(() => Hamming.Distance("ATA", "AGTG"));
4848
}
49+
50+
[Fact(Skip = "Remove to run test")]
51+
public void Disallow_left_empty_strand()
52+
{
53+
Assert.Throws<ArgumentException>(() => Hamming.Distance("", "G"));
54+
}
55+
56+
[Fact(Skip = "Remove to run test")]
57+
public void Disallow_right_empty_strand()
58+
{
59+
Assert.Throws<ArgumentException>(() => Hamming.Distance("G", ""));
60+
}
4961
}

exercises/high-scores/Example.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,5 @@ public class HighScores
1414

1515
public int PersonalBest() => _list.Max();
1616

17-
public List<int> PersonalTop() => _list.OrderByDescending(score => score).Take(3).ToList();
18-
19-
public string Report()
20-
{
21-
var latestScoreReport = $"Your latest score was {Latest()}.";
22-
23-
var differenceOfLatestToPersonalBest = PersonalBest() - Latest();
24-
var latestScoreComparedToPersonalBestReport =
25-
differenceOfLatestToPersonalBest == 0
26-
? "That's your personal best!"
27-
: $"That's {differenceOfLatestToPersonalBest} short of your personal best!";
28-
29-
return $"{latestScoreReport} {latestScoreComparedToPersonalBestReport}";
30-
}
17+
public List<int> PersonalTopThree() => _list.OrderByDescending(score => score).Take(3).ToList();
3118
}

exercises/high-scores/HighScores.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ public int PersonalBest()
2424
throw new NotImplementedException();
2525
}
2626

27-
public List<int> PersonalTop()
28-
{
29-
throw new NotImplementedException();
30-
}
31-
32-
public string Report()
27+
public List<int> PersonalTopThree()
3328
{
3429
throw new NotImplementedException();
3530
}
Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was auto-generated based on version 2.0.0 of the canonical data.
1+
// This file was auto-generated based on version 4.0.0 of the canonical data.
22

33
using System.Collections.Generic;
44
using Xunit;
@@ -27,65 +27,37 @@ public void Personal_best()
2727
}
2828

2929
[Fact(Skip = "Remove to run test")]
30-
public void Personal_top()
30+
public void Personal_top_three_from_a_list_of_scores()
3131
{
32-
var sut = new HighScores(new List<int> { 50, 30, 10 });
33-
Assert.Equal(new List<int> { 50, 30, 10 }, sut.PersonalTop());
32+
var sut = new HighScores(new List<int> { 10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70 });
33+
Assert.Equal(new List<int> { 100, 90, 70 }, sut.PersonalTopThree());
3434
}
3535

3636
[Fact(Skip = "Remove to run test")]
3737
public void Personal_top_highest_to_lowest()
3838
{
3939
var sut = new HighScores(new List<int> { 20, 10, 30 });
40-
Assert.Equal(new List<int> { 30, 20, 10 }, sut.PersonalTop());
40+
Assert.Equal(new List<int> { 30, 20, 10 }, sut.PersonalTopThree());
4141
}
4242

4343
[Fact(Skip = "Remove to run test")]
4444
public void Personal_top_when_there_is_a_tie()
4545
{
4646
var sut = new HighScores(new List<int> { 40, 20, 40, 30 });
47-
Assert.Equal(new List<int> { 40, 40, 30 }, sut.PersonalTop());
47+
Assert.Equal(new List<int> { 40, 40, 30 }, sut.PersonalTopThree());
4848
}
4949

5050
[Fact(Skip = "Remove to run test")]
5151
public void Personal_top_when_there_are_less_than_3()
5252
{
5353
var sut = new HighScores(new List<int> { 30, 70 });
54-
Assert.Equal(new List<int> { 70, 30 }, sut.PersonalTop());
54+
Assert.Equal(new List<int> { 70, 30 }, sut.PersonalTopThree());
5555
}
5656

5757
[Fact(Skip = "Remove to run test")]
5858
public void Personal_top_when_there_is_only_one()
5959
{
6060
var sut = new HighScores(new List<int> { 40 });
61-
Assert.Equal(new List<int> { 40 }, sut.PersonalTop());
62-
}
63-
64-
[Fact(Skip = "Remove to run test")]
65-
public void Personal_top_from_a_long_list()
66-
{
67-
var sut = new HighScores(new List<int> { 10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70 });
68-
Assert.Equal(new List<int> { 100, 90, 70 }, sut.PersonalTop());
69-
}
70-
71-
[Fact(Skip = "Remove to run test")]
72-
public void Message_for_new_personal_best()
73-
{
74-
var sut = new HighScores(new List<int> { 20, 40, 0, 30, 70 });
75-
Assert.Equal("Your latest score was 70. That's your personal best!", sut.Report());
76-
}
77-
78-
[Fact(Skip = "Remove to run test")]
79-
public void Message_when_latest_score_is_not_the_highest_score()
80-
{
81-
var sut = new HighScores(new List<int> { 20, 100, 0, 30, 70 });
82-
Assert.Equal("Your latest score was 70. That's 30 short of your personal best!", sut.Report());
83-
}
84-
85-
[Fact(Skip = "Remove to run test")]
86-
public void Message_for_repeated_personal_best()
87-
{
88-
var sut = new HighScores(new List<int> { 20, 70, 50, 70, 30 });
89-
Assert.Equal("Your latest score was 30. That's 40 short of your personal best!", sut.Report());
61+
Assert.Equal(new List<int> { 40 }, sut.PersonalTopThree());
9062
}
9163
}

exercises/list-ops/ListOpsTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was auto-generated based on version 2.3.0 of the canonical data.
1+
// This file was auto-generated based on version 2.4.0 of the canonical data.
22

33
using System;
44
using System.Collections.Generic;
@@ -171,4 +171,12 @@ public void Reverse_the_elements_of_the_list_non_empty_list()
171171
var expected = new List<int> { 7, 5, 3, 1 };
172172
Assert.Equal(expected, ListOps.Reverse(list));
173173
}
174+
175+
[Fact(Skip = "Remove to run test")]
176+
public void Reverse_the_elements_of_the_list_list_of_lists_is_not_flattened()
177+
{
178+
var list = new List<List<int>> { new List<int> { 1, 2 }, new List<int> { 3 }, new List<int>(), new List<int> { 4, 5, 6 } };
179+
var expected = new List<List<int>> { new List<int> { 4, 5, 6 }, new List<int>(), new List<int> { 3 }, new List<int> { 1, 2 } };
180+
Assert.Equal(expected, ListOps.Reverse(list));
181+
}
174182
}

exercises/rational-numbers/RationalNumbersTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void Raise_a_negative_rational_number_to_the_power_of_zero()
169169
[Fact(Skip = "Remove to run test")]
170170
public void Raise_a_real_number_to_a_positive_rational_number()
171171
{
172-
Assert.Equal(16, 8.Expreal(new RationalNumber(4, 3)), precision: 0);
172+
Assert.Equal(16, 8.Expreal(new RationalNumber(4, 3)), precision: 7);
173173
}
174174

175175
[Fact(Skip = "Remove to run test")]
@@ -181,7 +181,7 @@ public void Raise_a_real_number_to_a_negative_rational_number()
181181
[Fact(Skip = "Remove to run test")]
182182
public void Raise_a_real_number_to_a_zero_rational_number()
183183
{
184-
Assert.Equal(1, 2.Expreal(new RationalNumber(0, 1)), precision: 0);
184+
Assert.Equal(1, 2.Expreal(new RationalNumber(0, 1)), precision: 7);
185185
}
186186

187187
[Fact(Skip = "Remove to run test")]

exercises/simple-cipher/SimpleCipherTest.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was auto-generated based on version 1.2.0 of the canonical data.
1+
// This file was auto-generated based on version 2.0.0 of the canonical data.
22

33
using System;
44
using Xunit;
@@ -76,9 +76,16 @@ public void Substitution_cipher_can_wrap_on_decode()
7676
}
7777

7878
[Fact(Skip = "Remove to run test")]
79-
public void Substitution_cipher_can_handle_messages_longer_than_the_key()
79+
public void Substitution_cipher_can_encode_messages_longer_than_the_key()
8080
{
8181
var sut = new SimpleCipher("abc");
8282
Assert.Equal("iboaqcnecbfcr", sut.Encode("iamapandabear"));
8383
}
84+
85+
[Fact(Skip = "Remove to run test")]
86+
public void Substitution_cipher_can_decode_messages_longer_than_the_key()
87+
{
88+
var sut = new SimpleCipher("abc");
89+
Assert.Equal("iamapandabear", sut.Decode("iboaqcnecbfcr"));
90+
}
8491
}

exercises/word-count/WordCountTest.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This file was auto-generated based on version 1.2.0 of the canonical data.
1+
// This file was auto-generated based on version 1.3.0 of the canonical data.
22

33
using System.Collections.Generic;
44
using Xunit;
@@ -152,4 +152,17 @@ public void Multiple_spaces_not_detected_as_a_word()
152152
};
153153
Assert.Equal(expected, actual);
154154
}
155+
156+
[Fact(Skip = "Remove to run test")]
157+
public void Alternating_word_separators_not_detected_as_a_word()
158+
{
159+
var actual = WordCount.CountWords(",\n,one,\n ,two \n 'three'");
160+
var expected = new Dictionary<string, int>
161+
{
162+
["one"] = 1,
163+
["two"] = 1,
164+
["three"] = 1
165+
};
166+
Assert.Equal(expected, actual);
167+
}
155168
}

generators/Exercises/Generators/RationalNumbers.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@ private string RenderAssert(TestMethod testMethod)
2828
case "exprational":
2929
return Render.AssertEqual(RenderRationalNumber(testMethod.Expected), $"{RenderRationalNumber(testMethod.Input["r"])}.{testMethod.TestedMethod}({testMethod.Input["n"]})");
3030
case "expreal":
31-
return Render.AssertEqualWithin(Render.Object(testMethod.Expected), $"{testMethod.Input["x"]}.{testMethod.TestedMethod}({RenderRationalNumber(testMethod.Input["r"])})", Precision(testMethod.Expected));
31+
return Render.AssertEqualWithin(Render.Object(testMethod.Expected), $"{testMethod.Input["x"]}.{testMethod.TestedMethod}({RenderRationalNumber(testMethod.Input["r"])})", 7);
3232
default:
3333
throw new ArgumentOutOfRangeException();
3434
}
3535
}
3636

3737
private static string RenderRationalNumber(dynamic input) => $"new RationalNumber({input[0]}, {input[1]})";
38-
39-
private static int Precision(object rawValue)
40-
=> rawValue.ToString().Split(new[] { '.' }).Length <= 1
41-
? 0
42-
: rawValue.ToString().Split(new[] { '.' })[1].Length;
4338
}
4439
}

0 commit comments

Comments
 (0)