Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
"unlocked_by": null,
"difficulty": 1,
"topics": [
"lists",
"strings"
"lists"
]
},
{
Expand Down Expand Up @@ -1390,4 +1389,4 @@
]
}
]
}
}
26 changes: 19 additions & 7 deletions exercises/darts/DartsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.0.0 of the canonical data.
// This file was auto-generated based on version 1.1.0 of the canonical data.

using Xunit;

Expand All @@ -7,30 +7,42 @@ public class DartsTest
[Fact]
public void A_dart_lands_outside_the_target()
{
Assert.Equal(0, Darts.Score(15.3, 13.2));
Assert.Equal(0, Darts.Score(-9, 9));
}

[Fact(Skip = "Remove to run test")]
public void A_dart_lands_just_in_the_border_of_the_target()
{
Assert.Equal(1, Darts.Score(10, 0));
Assert.Equal(1, Darts.Score(0, 10));
}

[Fact(Skip = "Remove to run test")]
public void A_dart_lands_in_the_outer_circle()
{
Assert.Equal(1, Darts.Score(4, 4));
}

[Fact(Skip = "Remove to run test")]
public void A_dart_lands_right_in_the_border_between_outer_and_middle_circles()
{
Assert.Equal(5, Darts.Score(5, 0));
}

[Fact(Skip = "Remove to run test")]
public void A_dart_lands_in_the_middle_circle()
{
Assert.Equal(5, Darts.Score(3, 3.7));
Assert.Equal(5, Darts.Score(0.8, -0.8));
}

[Fact(Skip = "Remove to run test")]
public void A_dart_lands_right_in_the_border_between_outside_and_middle_circles()
public void A_dart_lands_right_in_the_border_between_middle_and_inner_circles()
{
Assert.Equal(5, Darts.Score(0, 5));
Assert.Equal(10, Darts.Score(0, -1));
}

[Fact(Skip = "Remove to run test")]
public void A_dart_lands_in_the_inner_circle()
{
Assert.Equal(10, Darts.Score(0, 0));
Assert.Equal(10, Darts.Score(-0.1, -0.1));
}
}
14 changes: 13 additions & 1 deletion exercises/hamming/HammingTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 2.2.0 of the canonical data.
// This file was auto-generated based on version 2.3.0 of the canonical data.

using System;
using Xunit;
Expand Down Expand Up @@ -46,4 +46,16 @@ public void Disallow_second_strand_longer()
{
Assert.Throws<ArgumentException>(() => Hamming.Distance("ATA", "AGTG"));
}

[Fact(Skip = "Remove to run test")]
public void Disallow_left_empty_strand()
{
Assert.Throws<ArgumentException>(() => Hamming.Distance("", "G"));
}

[Fact(Skip = "Remove to run test")]
public void Disallow_right_empty_strand()
{
Assert.Throws<ArgumentException>(() => Hamming.Distance("G", ""));
}
}
15 changes: 1 addition & 14 deletions exercises/high-scores/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,5 @@ public class HighScores

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

public List<int> PersonalTop() => _list.OrderByDescending(score => score).Take(3).ToList();

public string Report()
{
var latestScoreReport = $"Your latest score was {Latest()}.";

var differenceOfLatestToPersonalBest = PersonalBest() - Latest();
var latestScoreComparedToPersonalBestReport =
differenceOfLatestToPersonalBest == 0
? "That's your personal best!"
: $"That's {differenceOfLatestToPersonalBest} short of your personal best!";

return $"{latestScoreReport} {latestScoreComparedToPersonalBestReport}";
}
public List<int> PersonalTopThree() => _list.OrderByDescending(score => score).Take(3).ToList();
}
7 changes: 1 addition & 6 deletions exercises/high-scores/HighScores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ public int PersonalBest()
throw new NotImplementedException();
}

public List<int> PersonalTop()
{
throw new NotImplementedException();
}

public string Report()
public List<int> PersonalTopThree()
{
throw new NotImplementedException();
}
Expand Down
44 changes: 8 additions & 36 deletions exercises/high-scores/HighScoresTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 2.0.0 of the canonical data.
// This file was auto-generated based on version 4.0.0 of the canonical data.

using System.Collections.Generic;
using Xunit;
Expand Down Expand Up @@ -27,65 +27,37 @@ public void Personal_best()
}

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

[Fact(Skip = "Remove to run test")]
public void Personal_top_highest_to_lowest()
{
var sut = new HighScores(new List<int> { 20, 10, 30 });
Assert.Equal(new List<int> { 30, 20, 10 }, sut.PersonalTop());
Assert.Equal(new List<int> { 30, 20, 10 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_when_there_is_a_tie()
{
var sut = new HighScores(new List<int> { 40, 20, 40, 30 });
Assert.Equal(new List<int> { 40, 40, 30 }, sut.PersonalTop());
Assert.Equal(new List<int> { 40, 40, 30 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_when_there_are_less_than_3()
{
var sut = new HighScores(new List<int> { 30, 70 });
Assert.Equal(new List<int> { 70, 30 }, sut.PersonalTop());
Assert.Equal(new List<int> { 70, 30 }, sut.PersonalTopThree());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_when_there_is_only_one()
{
var sut = new HighScores(new List<int> { 40 });
Assert.Equal(new List<int> { 40 }, sut.PersonalTop());
}

[Fact(Skip = "Remove to run test")]
public void Personal_top_from_a_long_list()
{
var sut = new HighScores(new List<int> { 10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70 });
Assert.Equal(new List<int> { 100, 90, 70 }, sut.PersonalTop());
}

[Fact(Skip = "Remove to run test")]
public void Message_for_new_personal_best()
{
var sut = new HighScores(new List<int> { 20, 40, 0, 30, 70 });
Assert.Equal("Your latest score was 70. That's your personal best!", sut.Report());
}

[Fact(Skip = "Remove to run test")]
public void Message_when_latest_score_is_not_the_highest_score()
{
var sut = new HighScores(new List<int> { 20, 100, 0, 30, 70 });
Assert.Equal("Your latest score was 70. That's 30 short of your personal best!", sut.Report());
}

[Fact(Skip = "Remove to run test")]
public void Message_for_repeated_personal_best()
{
var sut = new HighScores(new List<int> { 20, 70, 50, 70, 30 });
Assert.Equal("Your latest score was 30. That's 40 short of your personal best!", sut.Report());
Assert.Equal(new List<int> { 40 }, sut.PersonalTopThree());
}
}
10 changes: 9 additions & 1 deletion exercises/list-ops/ListOpsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 2.3.0 of the canonical data.
// This file was auto-generated based on version 2.4.0 of the canonical data.

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -171,4 +171,12 @@ public void Reverse_the_elements_of_the_list_non_empty_list()
var expected = new List<int> { 7, 5, 3, 1 };
Assert.Equal(expected, ListOps.Reverse(list));
}

[Fact(Skip = "Remove to run test")]
public void Reverse_the_elements_of_the_list_list_of_lists_is_not_flattened()
{
var list = new List<List<int>> { new List<int> { 1, 2 }, new List<int> { 3 }, new List<int>(), new List<int> { 4, 5, 6 } };
var expected = new List<List<int>> { new List<int> { 4, 5, 6 }, new List<int>(), new List<int> { 3 }, new List<int> { 1, 2 } };
Assert.Equal(expected, ListOps.Reverse(list));
}
}
4 changes: 2 additions & 2 deletions exercises/rational-numbers/RationalNumbersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void Raise_a_negative_rational_number_to_the_power_of_zero()
[Fact(Skip = "Remove to run test")]
public void Raise_a_real_number_to_a_positive_rational_number()
{
Assert.Equal(16, 8.Expreal(new RationalNumber(4, 3)), precision: 0);
Assert.Equal(16, 8.Expreal(new RationalNumber(4, 3)), precision: 7);
}

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

[Fact(Skip = "Remove to run test")]
Expand Down
11 changes: 9 additions & 2 deletions exercises/simple-cipher/SimpleCipherTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.2.0 of the canonical data.
// This file was auto-generated based on version 2.0.0 of the canonical data.

using System;
using Xunit;
Expand Down Expand Up @@ -76,9 +76,16 @@ public void Substitution_cipher_can_wrap_on_decode()
}

[Fact(Skip = "Remove to run test")]
public void Substitution_cipher_can_handle_messages_longer_than_the_key()
public void Substitution_cipher_can_encode_messages_longer_than_the_key()
{
var sut = new SimpleCipher("abc");
Assert.Equal("iboaqcnecbfcr", sut.Encode("iamapandabear"));
}

[Fact(Skip = "Remove to run test")]
public void Substitution_cipher_can_decode_messages_longer_than_the_key()
{
var sut = new SimpleCipher("abc");
Assert.Equal("iamapandabear", sut.Decode("iboaqcnecbfcr"));
}
}
15 changes: 14 additions & 1 deletion exercises/word-count/WordCountTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.2.0 of the canonical data.
// This file was auto-generated based on version 1.3.0 of the canonical data.

using System.Collections.Generic;
using Xunit;
Expand Down Expand Up @@ -152,4 +152,17 @@ public void Multiple_spaces_not_detected_as_a_word()
};
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Alternating_word_separators_not_detected_as_a_word()
{
var actual = WordCount.CountWords(",\n,one,\n ,two \n 'three'");
var expected = new Dictionary<string, int>
{
["one"] = 1,
["two"] = 1,
["three"] = 1
};
Assert.Equal(expected, actual);
}
}
7 changes: 1 addition & 6 deletions generators/Exercises/Generators/RationalNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ private string RenderAssert(TestMethod testMethod)
case "exprational":
return Render.AssertEqual(RenderRationalNumber(testMethod.Expected), $"{RenderRationalNumber(testMethod.Input["r"])}.{testMethod.TestedMethod}({testMethod.Input["n"]})");
case "expreal":
return Render.AssertEqualWithin(Render.Object(testMethod.Expected), $"{testMethod.Input["x"]}.{testMethod.TestedMethod}({RenderRationalNumber(testMethod.Input["r"])})", Precision(testMethod.Expected));
return Render.AssertEqualWithin(Render.Object(testMethod.Expected), $"{testMethod.Input["x"]}.{testMethod.TestedMethod}({RenderRationalNumber(testMethod.Input["r"])})", 7);
default:
throw new ArgumentOutOfRangeException();
}
}

private static string RenderRationalNumber(dynamic input) => $"new RationalNumber({input[0]}, {input[1]})";

private static int Precision(object rawValue)
=> rawValue.ToString().Split(new[] { '.' }).Length <= 1
? 0
: rawValue.ToString().Split(new[] { '.' })[1].Length;
}
}