Skip to content

Commit

Permalink
exercises: update to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Nov 3, 2018
1 parent d91288c commit 0ca68d6
Show file tree
Hide file tree
Showing 21 changed files with 259 additions and 80 deletions.
15 changes: 14 additions & 1 deletion exercises/alphametics/AlphameticsTest.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;
using System.Collections.Generic;
Expand Down Expand Up @@ -31,6 +31,19 @@ public void Leading_zero_solution_is_invalid()
Assert.Throws<ArgumentException>(() => Alphametics.Solve("ACA + DD == BD"));
}

[Fact(Skip = "Remove to run test")]
public void Puzzle_with_two_digits_final_carry()
{
var actual = Alphametics.Solve("A + A + A + A + A + A + A + A + A + A + A + B == BCC");
var expected = new Dictionary<char, int>
{
['A'] = 9,
['B'] = 1,
['C'] = 0
};
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Puzzle_with_four_letters()
{
Expand Down
14 changes: 13 additions & 1 deletion exercises/atbash-cipher/AtbashCipherTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
// This file was auto-generated based on version 1.2.0 of the canonical data.

using Xunit;

Expand Down Expand Up @@ -75,4 +75,16 @@ public void Decode_all_the_letters()
{
Assert.Equal("thequickbrownfoxjumpsoverthelazydog", AtbashCipher.Decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"));
}

[Fact(Skip = "Remove to run test")]
public void Decode_with_too_many_spaces()
{
Assert.Equal("exercism", AtbashCipher.Decode("vc vix r hn"));
}

[Fact(Skip = "Remove to run test")]
public void Decode_with_no_spaces()
{
Assert.Equal("anobstacleisoftenasteppingstone", AtbashCipher.Decode("zmlyhgzxovrhlugvmzhgvkkrmthglmv"));
}
}
9 changes: 8 additions & 1 deletion exercises/bracket-push/BracketPushTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.3.0 of the canonical data.
// This file was auto-generated based on version 1.4.0 of the canonical data.

using Xunit;

Expand Down Expand Up @@ -95,6 +95,13 @@ public void Paired_and_wrong_nested_brackets()
Assert.False(BracketPush.IsPaired(value));
}

[Fact(Skip = "Remove to run test")]
public void Paired_and_incomplete_brackets()
{
var value = "{}[";
Assert.False(BracketPush.IsPaired(value));
}

[Fact(Skip = "Remove to run test")]
public void Math_expression()
{
Expand Down
75 changes: 74 additions & 1 deletion exercises/grep/GrepTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
// This file was auto-generated based on version 1.2.0 of the canonical data.

using System;
using System.IO;
Expand Down Expand Up @@ -139,6 +139,34 @@ public void One_file_no_matches_various_flags()
Assert.Equal(expected, Grep.Match(pattern, flags, files));
}

[Fact(Skip = "Remove to run test")]
public void One_file_one_match_file_flag_takes_precedence_over_line_flag()
{
var pattern = "ten";
var flags = "-n -l";
var files = new[] { "iliad.txt" };
var expected = "iliad.txt";
Assert.Equal(expected, Grep.Match(pattern, flags, files));
}

[Fact(Skip = "Remove to run test")]
public void One_file_several_matches_inverted_and_match_entire_lines_flags()
{
var pattern = "Illustrious into Ades premature,";
var flags = "-x -v";
var files = new[] { "iliad.txt" };
var expected =
"Achilles sing, O Goddess! Peleus' son;\n" +
"His wrath pernicious, who ten thousand woes\n" +
"Caused to Achaia's host, sent many a soul\n" +
"And Heroes gave (so stood the will of Jove)\n" +
"To dogs and to all ravening fowls a prey,\n" +
"When fierce dispute had separated once\n" +
"The noble Chief Achilles from the son\n" +
"Of Atreus, Agamemnon, King of men.";
Assert.Equal(expected, Grep.Match(pattern, flags, files));
}

[Fact(Skip = "Remove to run test")]
public void Multiple_files_one_match_no_flags()
{
Expand Down Expand Up @@ -251,6 +279,51 @@ public void Multiple_files_no_matches_various_flags()
Assert.Equal(expected, Grep.Match(pattern, flags, files));
}

[Fact(Skip = "Remove to run test")]
public void Multiple_files_several_matches_file_flag_takes_precedence_over_line_number_flag()
{
var pattern = "who";
var flags = "-n -l";
var files = new[] { "iliad.txt", "midsummer-night.txt", "paradise-lost.txt" };
var expected =
"iliad.txt\n" +
"paradise-lost.txt";
Assert.Equal(expected, Grep.Match(pattern, flags, files));
}

[Fact(Skip = "Remove to run test")]
public void Multiple_files_several_matches_inverted_and_match_entire_lines_flags()
{
var pattern = "Illustrious into Ades premature,";
var flags = "-x -v";
var files = new[] { "iliad.txt", "midsummer-night.txt", "paradise-lost.txt" };
var expected =
"iliad.txt:Achilles sing, O Goddess! Peleus' son;\n" +
"iliad.txt:His wrath pernicious, who ten thousand woes\n" +
"iliad.txt:Caused to Achaia's host, sent many a soul\n" +
"iliad.txt:And Heroes gave (so stood the will of Jove)\n" +
"iliad.txt:To dogs and to all ravening fowls a prey,\n" +
"iliad.txt:When fierce dispute had separated once\n" +
"iliad.txt:The noble Chief Achilles from the son\n" +
"iliad.txt:Of Atreus, Agamemnon, King of men.\n" +
"midsummer-night.txt:I do entreat your grace to pardon me.\n" +
"midsummer-night.txt:I know not by what power I am made bold,\n" +
"midsummer-night.txt:Nor how it may concern my modesty,\n" +
"midsummer-night.txt:In such a presence here to plead my thoughts;\n" +
"midsummer-night.txt:But I beseech your grace that I may know\n" +
"midsummer-night.txt:The worst that may befall me in this case,\n" +
"midsummer-night.txt:If I refuse to wed Demetrius.\n" +
"paradise-lost.txt:Of Mans First Disobedience, and the Fruit\n" +
"paradise-lost.txt:Of that Forbidden Tree, whose mortal tast\n" +
"paradise-lost.txt:Brought Death into the World, and all our woe,\n" +
"paradise-lost.txt:With loss of Eden, till one greater Man\n" +
"paradise-lost.txt:Restore us, and regain the blissful Seat,\n" +
"paradise-lost.txt:Sing Heav'nly Muse, that on the secret top\n" +
"paradise-lost.txt:Of Oreb, or of Sinai, didst inspire\n" +
"paradise-lost.txt:That Shepherd, who first taught the chosen Seed";
Assert.Equal(expected, Grep.Match(pattern, flags, files));
}

private const string IliadFileName = "iliad.txt";
private const string IliadContents =
"Achilles sing, O Goddess! Peleus' son;\n" +
Expand Down
8 changes: 7 additions & 1 deletion exercises/leap/LeapTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.3.0 of the canonical data.
// This file was auto-generated based on version 1.4.0 of the canonical data.

using Xunit;

Expand Down Expand Up @@ -27,4 +27,10 @@ public void Year_divisible_by_400_is_leap_year()
{
Assert.True(Leap.IsLeapYear(2000));
}

[Fact(Skip = "Remove to run test")]
public void Year_divisible_by_200_not_divisible_by_400_is_common_year()
{
Assert.False(Leap.IsLeapYear(1800));
}
}
2 changes: 1 addition & 1 deletion exercises/pangram/PangramTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.4.0 of the canonical data.
// This file was auto-generated based on version 1.4.1 of the canonical data.

using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion exercises/phone-number/PhoneNumberTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.6.0 of the canonical data.
// This file was auto-generated based on version 1.6.1 of the canonical data.

using System;
using Xunit;
Expand Down
2 changes: 1 addition & 1 deletion exercises/protein-translation/ProteinTranslationTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
// This file was auto-generated based on version 1.1.1 of the canonical data.

using Xunit;

Expand Down
4 changes: 2 additions & 2 deletions exercises/rest-api/RestApiTest.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.1 of the canonical data.
// This file was auto-generated based on version 1.0.2 of the canonical data.

using Xunit;

Expand Down Expand Up @@ -98,4 +98,4 @@ public void Lender_owes_borrower_less_than_new_loan()
var expected = "[{\"name\":\"Adam\",\"owes\":{},\"owed_by\":{\"Bob\":1.0},\"balance\":1.0},{\"name\":\"Bob\",\"owes\":{\"Adam\":1.0},\"owed_by\":{},\"balance\":-1.0}]";
Assert.Equal(expected, actual);
}
}
}
6 changes: 3 additions & 3 deletions exercises/robot-simulator/RobotSimulatorTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 3.0.0 of the canonical data.
// This file was auto-generated based on version 3.1.0 of the canonical data.

using Xunit;

Expand Down Expand Up @@ -143,7 +143,7 @@ public void Moves_the_robot_forward_1_space_in_the_direction_it_is_pointing_decr
}

[Fact(Skip = "Remove to run test")]
public void Where_r_turn_right_l_turn_left_and_a_advance_the_robot_can_follow_a_series_of_instructions_and_end_up_with_the_correct_position_and_direction_instructions_to_move_east_and_north()
public void Where_r_turn_right_l_turn_left_and_a_advance_the_robot_can_follow_a_series_of_instructions_and_end_up_with_the_correct_position_and_direction_instructions_to_move_east_and_north_from_readme()
{
var sut = new RobotSimulator(Direction.North, new Coordinate(7, 3));
sut.Simulate("RAALAL");
Expand Down Expand Up @@ -173,7 +173,7 @@ public void Where_r_turn_right_l_turn_left_and_a_advance_the_robot_can_follow_a_
}

[Fact(Skip = "Remove to run test")]
public void Where_r_turn_right_l_turn_left_and_a_advance_the_robot_can_follow_a_series_of_instructions_and_end_up_with_the_correct_position_and_direction_instructions_to_move_east_and_north1()
public void Where_r_turn_right_l_turn_left_and_a_advance_the_robot_can_follow_a_series_of_instructions_and_end_up_with_the_correct_position_and_direction_instructions_to_move_east_and_north()
{
var sut = new RobotSimulator(Direction.South, new Coordinate(8, 4));
sut.Simulate("LAAARRRALLLL");
Expand Down
2 changes: 1 addition & 1 deletion exercises/saddle-points/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SaddlePoints(int[,] values)

public IEnumerable<(int, int)> Calculate()
{
return Coordinates().Where(IsSaddlePoint);
return Coordinates().Where(IsSaddlePoint).ToArray();
}

private bool IsSaddlePoint((int, int) coordinate)
Expand Down
62 changes: 60 additions & 2 deletions exercises/saddle-points/SaddlePointsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
// This file was auto-generated based on version 1.3.0 of the canonical data.

using System;
using Xunit;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void Can_identify_lack_of_saddle_points_when_there_are_none()
}

[Fact(Skip = "Remove to run test")]
public void Can_identify_multiple_saddle_points()
public void Can_identify_multiple_saddle_points_in_a_column()
{
var matrix = new[,]
{
Expand All @@ -58,6 +58,21 @@ public void Can_identify_multiple_saddle_points()
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Can_identify_multiple_saddle_points_in_a_row()
{
var matrix = new[,]
{
{ 6, 7, 8 },
{ 5, 5, 5 },
{ 7, 5, 6 }
};
var sut = new SaddlePoints(matrix);
var actual = sut.Calculate();
var expected = new[] { (1, 0), (1, 1), (1, 2) };
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Can_identify_saddle_point_in_bottom_right_corner()
{
Expand All @@ -72,4 +87,47 @@ public void Can_identify_saddle_point_in_bottom_right_corner()
var expected = new[] { (2, 2) };
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Can_identify_saddle_points_in_a_non_square_matrix()
{
var matrix = new[,]
{
{ 3, 1, 3 },
{ 3, 2, 4 }
};
var sut = new SaddlePoints(matrix);
var actual = sut.Calculate();
var expected = new[] { (0, 0), (0, 2) };
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Can_identify_that_saddle_points_in_a_single_column_matrix_are_those_with_the_minimum_value()
{
var matrix = new[,]
{
{ 2 },
{ 1 },
{ 4 },
{ 1 }
};
var sut = new SaddlePoints(matrix);
var actual = sut.Calculate();
var expected = new[] { (1, 0), (3, 0) };
Assert.Equal(expected, actual);
}

[Fact(Skip = "Remove to run test")]
public void Can_identify_that_saddle_points_in_a_single_row_matrix_are_those_with_the_maximum_value()
{
var matrix = new[,]
{
{ 2, 5, 3, 5 }
};
var sut = new SaddlePoints(matrix);
var actual = sut.Calculate();
var expected = new[] { (0, 1), (0, 3) };
Assert.Equal(expected, actual);
}
}
6 changes: 3 additions & 3 deletions exercises/scale-generator/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public static class ScaleGenerator
private static string[] SkipInterval(char interval, string[] scale) => scale.Skip(Intervals[interval]).ToArray();
private static string[] Shift(int index, string[] scale) => scale.Skip(index).Concat(scale.Take(index)).ToArray();

public static string[] Pitches(string tonic)
public static string[] Chromatic(string tonic)
{
return Pitches(tonic, "mmmmmmmmmmmm");
return Interval(tonic, "mmmmmmmmmmmm");
}

public static string[] Pitches(string tonic, string pattern)
public static string[] Interval(string tonic, string pattern)
{
var scale = Scale(tonic);
var index = Array.FindIndex(scale, pitch => string.Equals(pitch, tonic, StringComparison.OrdinalIgnoreCase));
Expand Down
4 changes: 2 additions & 2 deletions exercises/scale-generator/ScaleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public static class ScaleGenerator
{
public static string[] Pitches(string tonic)
public static string[] Chromatic(string tonic)
{
throw new NotImplementedException("You need to implement this function.");
}

public static string[] Pitches(string tonic, string pattern)
public static string[] Interval(string tonic, string pattern)
{
throw new NotImplementedException("You need to implement this function.");
}
Expand Down
Loading

0 comments on commit 0ca68d6

Please sign in to comment.