From 85c19dde33f20c8976daf6265b2ad37570c6d6ff Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 5 Feb 2025 15:13:20 +0100 Subject: [PATCH] rectangles: add generator (#2373) * reverse-string: add generator * spiral-matrix: add generator * scale-generator: add generator * minesweeper: add generator * tournament: add generator * transpose: fix * saddle-points: add generator * ocr-numbers: add generator * book-store: add generator * spiral-matrix: fix * game-of-life: add generator * rectangles: add generator [no important files changed] --- .../practice/book-store/.meta/Generator.tpl | 12 ++ .../practice/book-store/BookStoreTests.cs | 55 +++---- .../practice/game-of-life/.meta/Generator.tpl | 28 ++++ .../practice/game-of-life/GameOfLifeTests.cs | 137 +++++++++--------- .../practice/minesweeper/.meta/Generator.tpl | 27 ++++ .../practice/minesweeper/MinesweeperTests.cs | 114 ++++++--------- .../practice/ocr-numbers/.meta/Generator.tpl | 25 ++++ .../practice/ocr-numbers/OcrNumbersTests.cs | 85 +++++------ .../practice/rectangles/.meta/Generator.tpl | 22 +++ .../practice/rectangles/RectanglesTests.cs | 97 ++++++------- .../reverse-string/.meta/Generator.tpl | 12 ++ .../saddle-points/.meta/Generator.tpl | 27 ++++ .../saddle-points/SaddlePointsTests.cs | 108 +++++++------- .../scale-generator/.meta/Generator.tpl | 13 ++ .../scale-generator/ScaleGeneratorTests.cs | 68 ++++----- .../spiral-matrix/.meta/Generator.tpl | 22 +++ .../spiral-matrix/SpiralMatrixTests.cs | 40 ++--- .../practice/tournament/.meta/Generator.tpl | 44 ++++++ .../practice/tournament/TournamentTests.cs | 38 ++--- .../practice/transpose/.meta/Generator.tpl | 2 +- .../Exercises/Generators/GameOfLife.cs | 23 --- .../Exercises/Generators/Minesweeper.cs | 23 --- .../Exercises/Generators/Rectangles.cs | 23 --- .../Exercises/Generators/ReverseString.cs | 5 - .../Exercises/Generators/ScaleGenerator.cs | 8 - .../Exercises/Generators/SpiralMatrix.cs | 16 -- .../Exercises/Generators/Tournament.cs | 48 ------ .../Exercises/Generators/Transpose.cs | 17 --- .../Exercises/Generators/TwelveDays.cs | 18 --- 29 files changed, 566 insertions(+), 591 deletions(-) create mode 100644 exercises/practice/book-store/.meta/Generator.tpl create mode 100644 exercises/practice/game-of-life/.meta/Generator.tpl create mode 100644 exercises/practice/minesweeper/.meta/Generator.tpl create mode 100644 exercises/practice/ocr-numbers/.meta/Generator.tpl create mode 100644 exercises/practice/rectangles/.meta/Generator.tpl create mode 100644 exercises/practice/reverse-string/.meta/Generator.tpl create mode 100644 exercises/practice/saddle-points/.meta/Generator.tpl create mode 100644 exercises/practice/scale-generator/.meta/Generator.tpl create mode 100644 exercises/practice/spiral-matrix/.meta/Generator.tpl create mode 100644 exercises/practice/tournament/.meta/Generator.tpl delete mode 100644 generators.deprecated/Exercises/Generators/GameOfLife.cs delete mode 100644 generators.deprecated/Exercises/Generators/Minesweeper.cs delete mode 100644 generators.deprecated/Exercises/Generators/Rectangles.cs delete mode 100644 generators.deprecated/Exercises/Generators/ReverseString.cs delete mode 100644 generators.deprecated/Exercises/Generators/ScaleGenerator.cs delete mode 100644 generators.deprecated/Exercises/Generators/SpiralMatrix.cs delete mode 100644 generators.deprecated/Exercises/Generators/Tournament.cs delete mode 100644 generators.deprecated/Exercises/Generators/Transpose.cs delete mode 100644 generators.deprecated/Exercises/Generators/TwelveDays.cs diff --git a/exercises/practice/book-store/.meta/Generator.tpl b/exercises/practice/book-store/.meta/Generator.tpl new file mode 100644 index 0000000000..ce110ec047 --- /dev/null +++ b/exercises/practice/book-store/.meta/Generator.tpl @@ -0,0 +1,12 @@ +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + Assert.Equal({{ test.expected / 100.0 }}m, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.basket }})); + } + {{ end -}} +} diff --git a/exercises/practice/book-store/BookStoreTests.cs b/exercises/practice/book-store/BookStoreTests.cs index 5c839f0232..e956c11d9a 100644 --- a/exercises/practice/book-store/BookStoreTests.cs +++ b/exercises/practice/book-store/BookStoreTests.cs @@ -1,4 +1,3 @@ -using System; using Xunit; public class BookStoreTests @@ -6,126 +5,108 @@ public class BookStoreTests [Fact] public void Only_a_single_book() { - var basket = new[] { 1 }; - Assert.Equal(8m, BookStore.Total(basket)); + Assert.Equal(8m, BookStore.Total([1])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_of_the_same_book() { - var basket = new[] { 2, 2 }; - Assert.Equal(16m, BookStore.Total(basket)); + Assert.Equal(16m, BookStore.Total([2, 2])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Empty_basket() { - var basket = Array.Empty(); - Assert.Equal(0m, BookStore.Total(basket)); + Assert.Equal(0m, BookStore.Total([])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_different_books() { - var basket = new[] { 1, 2 }; - Assert.Equal(15.2m, BookStore.Total(basket)); + Assert.Equal(15.2m, BookStore.Total([1, 2])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Three_different_books() { - var basket = new[] { 1, 2, 3 }; - Assert.Equal(21.6m, BookStore.Total(basket)); + Assert.Equal(21.6m, BookStore.Total([1, 2, 3])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Four_different_books() { - var basket = new[] { 1, 2, 3, 4 }; - Assert.Equal(25.6m, BookStore.Total(basket)); + Assert.Equal(25.6m, BookStore.Total([1, 2, 3, 4])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Five_different_books() { - var basket = new[] { 1, 2, 3, 4, 5 }; - Assert.Equal(30m, BookStore.Total(basket)); + Assert.Equal(30m, BookStore.Total([1, 2, 3, 4, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_groups_of_four_is_cheaper_than_group_of_five_plus_group_of_three() { - var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5 }; - Assert.Equal(51.2m, BookStore.Total(basket)); + Assert.Equal(51.2m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_groups_of_four_is_cheaper_than_groups_of_five_and_three() { - var basket = new[] { 1, 1, 2, 3, 4, 4, 5, 5 }; - Assert.Equal(51.2m, BookStore.Total(basket)); + Assert.Equal(51.2m, BookStore.Total([1, 1, 2, 3, 4, 4, 5, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Group_of_four_plus_group_of_two_is_cheaper_than_two_groups_of_three() { - var basket = new[] { 1, 1, 2, 2, 3, 4 }; - Assert.Equal(40.8m, BookStore.Total(basket)); + Assert.Equal(40.8m, BookStore.Total([1, 1, 2, 2, 3, 4])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_each_of_first_four_books_and_one_copy_each_of_rest() { - var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5 }; - Assert.Equal(55.6m, BookStore.Total(basket)); + Assert.Equal(55.6m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_copies_of_each_book() { - var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 }; - Assert.Equal(60m, BookStore.Total(basket)); + Assert.Equal(60m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Three_copies_of_first_book_and_two_each_of_remaining() { - var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1 }; - Assert.Equal(68m, BookStore.Total(basket)); + Assert.Equal(68m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Three_each_of_first_two_books_and_two_each_of_remaining_books() { - var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2 }; - Assert.Equal(75.2m, BookStore.Total(basket)); + Assert.Equal(75.2m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three() { - var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5 }; - Assert.Equal(102.4m, BookStore.Total(basket)); + Assert.Equal(102.4m, BookStore.Total([1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void Check_that_groups_of_four_are_created_properly_even_when_there_are_more_groups_of_three_than_groups_of_five() { - var basket = new[] { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5 }; - Assert.Equal(145.6m, BookStore.Total(basket)); + Assert.Equal(145.6m, BookStore.Total([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5])); } [Fact(Skip = "Remove this Skip property to run this test")] public void One_group_of_one_and_four_is_cheaper_than_one_group_of_two_and_three() { - var basket = new[] { 1, 1, 2, 3, 4 }; - Assert.Equal(33.6m, BookStore.Total(basket)); + Assert.Equal(33.6m, BookStore.Total([1, 1, 2, 3, 4])); } [Fact(Skip = "Remove this Skip property to run this test")] public void One_group_of_one_and_two_plus_three_groups_of_four_is_cheaper_than_one_group_of_each_size() { - var basket = new[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5 }; - Assert.Equal(100m, BookStore.Total(basket)); + Assert.Equal(100m, BookStore.Total([1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5])); } } diff --git a/exercises/practice/game-of-life/.meta/Generator.tpl b/exercises/practice/game-of-life/.meta/Generator.tpl new file mode 100644 index 0000000000..7109e701c1 --- /dev/null +++ b/exercises/practice/game-of-life/.meta/Generator.tpl @@ -0,0 +1,28 @@ +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + int[,] matrix = + { + {{- for row in test.input.matrix }} + { {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}} + {{ end }} + }; + {{- if test.expected.empty? }} + Assert.Empty({{ testedClass }}.{{ test.testedMethod }}(matrix)); + {{ else }} + int[,] expected = + { + {{- for row in test.expected }} + { {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}} + {{ end }} + }; + Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}(matrix)); + {{ end -}} + } + {{ end -}} +} diff --git a/exercises/practice/game-of-life/GameOfLifeTests.cs b/exercises/practice/game-of-life/GameOfLifeTests.cs index 7028585bb4..307e5537d6 100644 --- a/exercises/practice/game-of-life/GameOfLifeTests.cs +++ b/exercises/practice/game-of-life/GameOfLifeTests.cs @@ -1,4 +1,3 @@ -using System; using Xunit; public class GameOfLifeTests @@ -6,24 +5,26 @@ public class GameOfLifeTests [Fact] public void Empty_matrix() { - var matrix = new int[,] { }; + int[,] matrix = + { + }; Assert.Empty(GameOfLife.Tick(matrix)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Live_cells_with_zero_live_neighbors_die() { - var matrix = new[,] + int[,] matrix = { - { 0, 0, 0 }, - { 0, 1, 0 }, - { 0, 0, 0 } + { 0, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 0 } }; - var expected = new[,] + int[,] expected = { - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 } + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } @@ -31,17 +32,17 @@ public void Live_cells_with_zero_live_neighbors_die() [Fact(Skip = "Remove this Skip property to run this test")] public void Live_cells_with_only_one_live_neighbor_die() { - var matrix = new[,] + int[,] matrix = { - { 0, 0, 0 }, - { 0, 1, 0 }, - { 0, 1, 0 } + { 0, 0, 0 }, + { 0, 1, 0 }, + { 0, 1, 0 } }; - var expected = new[,] + int[,] expected = { - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 } + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } @@ -49,17 +50,17 @@ public void Live_cells_with_only_one_live_neighbor_die() [Fact(Skip = "Remove this Skip property to run this test")] public void Live_cells_with_two_live_neighbors_stay_alive() { - var matrix = new[,] + int[,] matrix = { - { 1, 0, 1 }, - { 1, 0, 1 }, - { 1, 0, 1 } + { 1, 0, 1 }, + { 1, 0, 1 }, + { 1, 0, 1 } }; - var expected = new[,] + int[,] expected = { - { 0, 0, 0 }, - { 1, 0, 1 }, - { 0, 0, 0 } + { 0, 0, 0 }, + { 1, 0, 1 }, + { 0, 0, 0 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } @@ -67,17 +68,17 @@ public void Live_cells_with_two_live_neighbors_stay_alive() [Fact(Skip = "Remove this Skip property to run this test")] public void Live_cells_with_three_live_neighbors_stay_alive() { - var matrix = new[,] + int[,] matrix = { - { 0, 1, 0 }, - { 1, 0, 0 }, - { 1, 1, 0 } + { 0, 1, 0 }, + { 1, 0, 0 }, + { 1, 1, 0 } }; - var expected = new[,] + int[,] expected = { - { 0, 0, 0 }, - { 1, 0, 0 }, - { 1, 1, 0 } + { 0, 0, 0 }, + { 1, 0, 0 }, + { 1, 1, 0 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } @@ -85,17 +86,17 @@ public void Live_cells_with_three_live_neighbors_stay_alive() [Fact(Skip = "Remove this Skip property to run this test")] public void Dead_cells_with_three_live_neighbors_become_alive() { - var matrix = new[,] + int[,] matrix = { - { 1, 1, 0 }, - { 0, 0, 0 }, - { 1, 0, 0 } + { 1, 1, 0 }, + { 0, 0, 0 }, + { 1, 0, 0 } }; - var expected = new[,] + int[,] expected = { - { 0, 0, 0 }, - { 1, 1, 0 }, - { 0, 0, 0 } + { 0, 0, 0 }, + { 1, 1, 0 }, + { 0, 0, 0 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } @@ -103,17 +104,17 @@ public void Dead_cells_with_three_live_neighbors_become_alive() [Fact(Skip = "Remove this Skip property to run this test")] public void Live_cells_with_four_or_more_neighbors_die() { - var matrix = new[,] + int[,] matrix = { - { 1, 1, 1 }, - { 1, 1, 1 }, - { 1, 1, 1 } + { 1, 1, 1 }, + { 1, 1, 1 }, + { 1, 1, 1 } }; - var expected = new[,] + int[,] expected = { - { 1, 0, 1 }, - { 0, 0, 0 }, - { 1, 0, 1 } + { 1, 0, 1 }, + { 0, 0, 0 }, + { 1, 0, 1 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } @@ -121,27 +122,27 @@ public void Live_cells_with_four_or_more_neighbors_die() [Fact(Skip = "Remove this Skip property to run this test")] public void Bigger_matrix() { - var matrix = new[,] + int[,] matrix = { - { 1, 1, 0, 1, 1, 0, 0, 0 }, - { 1, 0, 1, 1, 0, 0, 0, 0 }, - { 1, 1, 1, 0, 0, 1, 1, 1 }, - { 0, 0, 0, 0, 0, 1, 1, 0 }, - { 1, 0, 0, 0, 1, 1, 0, 0 }, - { 1, 1, 0, 0, 0, 1, 1, 1 }, - { 0, 0, 1, 0, 1, 0, 0, 1 }, - { 1, 0, 0, 0, 0, 0, 1, 1 } + { 1, 1, 0, 1, 1, 0, 0, 0 }, + { 1, 0, 1, 1, 0, 0, 0, 0 }, + { 1, 1, 1, 0, 0, 1, 1, 1 }, + { 0, 0, 0, 0, 0, 1, 1, 0 }, + { 1, 0, 0, 0, 1, 1, 0, 0 }, + { 1, 1, 0, 0, 0, 1, 1, 1 }, + { 0, 0, 1, 0, 1, 0, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 1, 1 } }; - var expected = new[,] + int[,] expected = { - { 1, 1, 0, 1, 1, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 1, 1, 0 }, - { 1, 0, 1, 1, 1, 1, 0, 1 }, - { 1, 0, 0, 0, 0, 0, 0, 1 }, - { 1, 1, 0, 0, 1, 0, 0, 1 }, - { 1, 1, 0, 1, 0, 0, 0, 1 }, - { 1, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 1, 1 } + { 1, 1, 0, 1, 1, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 1, 1, 0 }, + { 1, 0, 1, 1, 1, 1, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1, 0, 0, 1 }, + { 1, 1, 0, 1, 0, 0, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 1, 1 } }; Assert.Equal(expected, GameOfLife.Tick(matrix)); } diff --git a/exercises/practice/minesweeper/.meta/Generator.tpl b/exercises/practice/minesweeper/.meta/Generator.tpl new file mode 100644 index 0000000000..30ec3d1ed4 --- /dev/null +++ b/exercises/practice/minesweeper/.meta/Generator.tpl @@ -0,0 +1,27 @@ +using System; +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + {{- if test.input.minefield.empty? }} + Assert.Empty({{ testedClass }}.{{ test.testedMethod }}(Array.Empty())); + {{ else }} + string[] minefield = [ + {{- for line in test.input.minefield }} + {{ line | string.literal }}{{- if !for.last }},{{ end -}} + {{ end }} + ]; + string[] expected = [ + {{- for line in test.expected }} + {{ line | string.literal }}{{- if !for.last }},{{ end -}} + {{ end }} + ]; + Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}(minefield)); + {{ end -}} + } + {{ end -}} +} diff --git a/exercises/practice/minesweeper/MinesweeperTests.cs b/exercises/practice/minesweeper/MinesweeperTests.cs index ae54b45c9f..8b4288b6e6 100644 --- a/exercises/practice/minesweeper/MinesweeperTests.cs +++ b/exercises/practice/minesweeper/MinesweeperTests.cs @@ -6,212 +6,188 @@ public class MinesweeperTests [Fact] public void No_rows() { - var minefield = Array.Empty(); - var expected = Array.Empty(); - Assert.Equal(expected, Minesweeper.Annotate(minefield)); + Assert.Empty(Minesweeper.Annotate(Array.Empty())); } [Fact(Skip = "Remove this Skip property to run this test")] public void No_columns() { - var minefield = new[] - { + string[] minefield = [ "" - }; - var expected = new[] - { + ]; + string[] expected = [ "" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void No_mines() { - var minefield = new[] - { + string[] minefield = [ " ", " ", " " - }; - var expected = new[] - { + ]; + string[] expected = [ " ", " ", " " - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Minefield_with_only_mines() { - var minefield = new[] - { + string[] minefield = [ "***", "***", "***" - }; - var expected = new[] - { + ]; + string[] expected = [ "***", "***", "***" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Mine_surrounded_by_spaces() { - var minefield = new[] - { + string[] minefield = [ " ", " * ", " " - }; - var expected = new[] - { + ]; + string[] expected = [ "111", "1*1", "111" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Space_surrounded_by_mines() { - var minefield = new[] - { + string[] minefield = [ "***", "* *", "***" - }; - var expected = new[] - { + ]; + string[] expected = [ "***", "*8*", "***" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Horizontal_line() { - var minefield = new[] - { + string[] minefield = [ " * * " - }; - var expected = new[] - { + ]; + string[] expected = [ "1*2*1" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Horizontal_line_mines_at_edges() { - var minefield = new[] - { + string[] minefield = [ "* *" - }; - var expected = new[] - { + ]; + string[] expected = [ "*1 1*" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Vertical_line() { - var minefield = new[] - { + string[] minefield = [ " ", "*", " ", "*", " " - }; - var expected = new[] - { + ]; + string[] expected = [ "1", "*", "2", "*", "1" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Vertical_line_mines_at_edges() { - var minefield = new[] - { + string[] minefield = [ "*", " ", " ", " ", "*" - }; - var expected = new[] - { + ]; + string[] expected = [ "*", "1", " ", "1", "*" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Cross() { - var minefield = new[] - { + string[] minefield = [ " * ", " * ", "*****", " * ", " * " - }; - var expected = new[] - { + ]; + string[] expected = [ " 2*2 ", "25*52", "*****", "25*52", " 2*2 " - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Large_minefield() { - var minefield = new[] - { + string[] minefield = [ " * * ", " * ", " * ", " * *", " * * ", " " - }; - var expected = new[] - { + ]; + string[] expected = [ "1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111" - }; + ]; Assert.Equal(expected, Minesweeper.Annotate(minefield)); } } diff --git a/exercises/practice/ocr-numbers/.meta/Generator.tpl b/exercises/practice/ocr-numbers/.meta/Generator.tpl new file mode 100644 index 0000000000..db6a9da135 --- /dev/null +++ b/exercises/practice/ocr-numbers/.meta/Generator.tpl @@ -0,0 +1,25 @@ +using System; +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + var rows = + {{- for line in test.input.rows }} + {{ if for.last -}} + {{ line | string.literal -}}; + {{- else -}} + {{ line | string.append "\n" | string.literal }} + + {{- end -}} + {{- end }} + {{- if test.expected.error }} + Assert.Throws(() => {{ testedClass }}.{{ test.testedMethod }}(rows)); + {{ else }} + Assert.Equal({{ test.expected | string.literal }}, {{ testedClass }}.{{ test.testedMethod }}(rows)); + {{ end -}} + } + {{ end -}} +} diff --git a/exercises/practice/ocr-numbers/OcrNumbersTests.cs b/exercises/practice/ocr-numbers/OcrNumbersTests.cs index 75b792718a..36465f0cc7 100644 --- a/exercises/practice/ocr-numbers/OcrNumbersTests.cs +++ b/exercises/practice/ocr-numbers/OcrNumbersTests.cs @@ -6,43 +6,40 @@ public class OcrNumbersTests [Fact] public void Recognizes_0() { - var rows = + var rows = " _ \n" + "| |\n" + "|_|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("0", actual); + Assert.Equal("0", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_1() { - var rows = + var rows = " \n" + " |\n" + " |\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("1", actual); + Assert.Equal("1", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Unreadable_but_correctly_sized_inputs_return_() + public void Unreadable_but_correctly_sized_inputs_return() { - var rows = + var rows = " \n" + " _\n" + " |\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("?", actual); + Assert.Equal("?", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Input_with_a_number_of_lines_that_is_not_a_multiple_of_four_raises_an_error() { - var rows = + var rows = " _ \n" + "| |\n" + " "; @@ -52,7 +49,7 @@ public void Input_with_a_number_of_lines_that_is_not_a_multiple_of_four_raises_a [Fact(Skip = "Remove this Skip property to run this test")] public void Input_with_a_number_of_columns_that_is_not_a_multiple_of_three_raises_an_error() { - var rows = + var rows = " \n" + " |\n" + " |\n" + @@ -63,139 +60,128 @@ public void Input_with_a_number_of_columns_that_is_not_a_multiple_of_three_raise [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_110101100() { - var rows = + var rows = " _ _ _ _ \n" + " | || | || | | || || |\n" + " | ||_| ||_| | ||_||_|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("110101100", actual); + Assert.Equal("110101100", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Garbled_numbers_in_a_string_are_replaced_with_() + public void Garbled_numbers_in_a_string_are_replaced_with() { - var rows = + var rows = " _ _ _ \n" + " | || | || | || || |\n" + " | | _| ||_| | ||_||_|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("11?10?1?0", actual); + Assert.Equal("11?10?1?0", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_2() { - var rows = + var rows = " _ \n" + " _|\n" + "|_ \n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("2", actual); + Assert.Equal("2", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_3() { - var rows = + var rows = " _ \n" + " _|\n" + " _|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("3", actual); + Assert.Equal("3", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_4() { - var rows = + var rows = " \n" + "|_|\n" + " |\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("4", actual); + Assert.Equal("4", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_5() { - var rows = + var rows = " _ \n" + "|_ \n" + " _|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("5", actual); + Assert.Equal("5", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_6() { - var rows = + var rows = " _ \n" + "|_ \n" + "|_|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("6", actual); + Assert.Equal("6", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_7() { - var rows = + var rows = " _ \n" + " |\n" + " |\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("7", actual); + Assert.Equal("7", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_8() { - var rows = + var rows = " _ \n" + "|_|\n" + "|_|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("8", actual); + Assert.Equal("8", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_9() { - var rows = + var rows = " _ \n" + "|_|\n" + " _|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("9", actual); + Assert.Equal("9", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Recognizes_string_of_decimal_numbers() { - var rows = + var rows = " _ _ _ _ _ _ _ _ \n" + " | _| _||_||_ |_ ||_||_|| |\n" + " ||_ _| | _||_| ||_| _||_|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("1234567890", actual); + Assert.Equal("1234567890", OcrNumbers.Convert(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Numbers_separated_by_empty_lines_are_recognized_lines_are_joined_by_commas_() + public void Numbers_separated_by_empty_lines_are_recognized_lines_are_joined_by_commas() { - var rows = + var rows = " _ _ \n" + " | _| _|\n" + " ||_ _|\n" + @@ -208,7 +194,6 @@ public void Numbers_separated_by_empty_lines_are_recognized_lines_are_joined_by_ " ||_||_|\n" + " ||_| _|\n" + " "; - var actual = OcrNumbers.Convert(rows); - Assert.Equal("123,456,789", actual); + Assert.Equal("123,456,789", OcrNumbers.Convert(rows)); } } diff --git a/exercises/practice/rectangles/.meta/Generator.tpl b/exercises/practice/rectangles/.meta/Generator.tpl new file mode 100644 index 0000000000..aca77f4380 --- /dev/null +++ b/exercises/practice/rectangles/.meta/Generator.tpl @@ -0,0 +1,22 @@ +using System; +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod | string.replace "1x1" "One_by_one" }}() + { + {{- if test.input.strings.empty? }} + string[] rows = Array.Empty(); + {{ else }} + string[] rows = [ + {{- for row in test.input.strings }} + {{ row | string.literal }}{{- if !for.last }},{{ end -}} + {{ end }} + ]; + {{ end -}} + Assert.Equal({{ test.expected }}, {{ testedClass }}.Count(rows)); + } + {{ end -}} +} diff --git a/exercises/practice/rectangles/RectanglesTests.cs b/exercises/practice/rectangles/RectanglesTests.cs index 6c8a22ee05..c2b1e6e7c5 100644 --- a/exercises/practice/rectangles/RectanglesTests.cs +++ b/exercises/practice/rectangles/RectanglesTests.cs @@ -6,151 +6,139 @@ public class RectanglesTests [Fact] public void No_rows() { - var strings = Array.Empty(); - Assert.Equal(0, Rectangles.Count(strings)); + string[] rows = Array.Empty(); + Assert.Equal(0, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void No_columns() { - var strings = new[] - { + string[] rows = [ "" - }; - Assert.Equal(0, Rectangles.Count(strings)); + ]; + Assert.Equal(0, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void No_rectangles() { - var strings = new[] - { + string[] rows = [ " " - }; - Assert.Equal(0, Rectangles.Count(strings)); + ]; + Assert.Equal(0, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void One_rectangle() { - var strings = new[] - { + string[] rows = [ "+-+", "| |", "+-+" - }; - Assert.Equal(1, Rectangles.Count(strings)); + ]; + Assert.Equal(1, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Two_rectangles_without_shared_parts() { - var strings = new[] - { + string[] rows = [ " +-+", " | |", "+-+-+", "| | ", "+-+ " - }; - Assert.Equal(2, Rectangles.Count(strings)); + ]; + Assert.Equal(2, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Five_rectangles_with_shared_parts() { - var strings = new[] - { + string[] rows = [ " +-+", " | |", "+-+-+", "| | |", "+-+-+" - }; - Assert.Equal(5, Rectangles.Count(strings)); + ]; + Assert.Equal(5, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Rectangle_of_height_1_is_counted() { - var strings = new[] - { + string[] rows = [ "+--+", "+--+" - }; - Assert.Equal(1, Rectangles.Count(strings)); + ]; + Assert.Equal(1, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Rectangle_of_width_1_is_counted() { - var strings = new[] - { + string[] rows = [ "++", "||", "++" - }; - Assert.Equal(1, Rectangles.Count(strings)); + ]; + Assert.Equal(1, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Number_1x1_square_is_counted() + public void One_by_one_square_is_counted() { - var strings = new[] - { + string[] rows = [ "++", "++" - }; - Assert.Equal(1, Rectangles.Count(strings)); + ]; + Assert.Equal(1, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Only_complete_rectangles_are_counted() { - var strings = new[] - { + string[] rows = [ " +-+", " |", "+-+-+", "| | -", "+-+-+" - }; - Assert.Equal(1, Rectangles.Count(strings)); + ]; + Assert.Equal(1, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Rectangles_can_be_of_different_sizes() { - var strings = new[] - { + string[] rows = [ "+------+----+", "| | |", "+---+--+ |", "| | |", "+---+-------+" - }; - Assert.Equal(3, Rectangles.Count(strings)); + ]; + Assert.Equal(3, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Corner_is_required_for_a_rectangle_to_be_complete() { - var strings = new[] - { + string[] rows = [ "+------+----+", "| | |", "+------+ |", "| | |", "+---+-------+" - }; - Assert.Equal(2, Rectangles.Count(strings)); + ]; + Assert.Equal(2, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Large_input_with_many_rectangles() { - var strings = new[] - { + string[] rows = [ "+---+--+----+", "| +--+----+", "+---+--+ |", @@ -159,15 +147,14 @@ public void Large_input_with_many_rectangles() "+---+--+--+-+", "+------+ | |", " +-+" - }; - Assert.Equal(60, Rectangles.Count(strings)); + ]; + Assert.Equal(60, Rectangles.Count(rows)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Rectangles_must_have_four_sides() { - var strings = new[] - { + string[] rows = [ "+-+ +-+", "| | | |", "+-+-+-+", @@ -175,7 +162,7 @@ public void Rectangles_must_have_four_sides() "+-+-+-+", "| | | |", "+-+ +-+" - }; - Assert.Equal(5, Rectangles.Count(strings)); + ]; + Assert.Equal(5, Rectangles.Count(rows)); } } diff --git a/exercises/practice/reverse-string/.meta/Generator.tpl b/exercises/practice/reverse-string/.meta/Generator.tpl new file mode 100644 index 0000000000..824c143244 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/Generator.tpl @@ -0,0 +1,12 @@ +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + Assert.Equal({{ test.expected | string.literal }}, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.value | string.literal }})); + } + {{ end -}} +} diff --git a/exercises/practice/saddle-points/.meta/Generator.tpl b/exercises/practice/saddle-points/.meta/Generator.tpl new file mode 100644 index 0000000000..f5949a6471 --- /dev/null +++ b/exercises/practice/saddle-points/.meta/Generator.tpl @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Linq; +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + int[,] matrix = + { + {{- for row in test.input.matrix }} + {{- if !row.empty? }} + { {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}} + {{ end -}} + {{ end }} + }; + {{- if test.expected.empty? }} + Assert.Empty({{ testedClass }}.Calculate(matrix)); + {{ else }} + HashSet<(int, int)> expected = [{{ for pair in test.expected }}({{ pair.row }}, {{ pair.column }}){{ if !for.last}}, {{ end }}{{ end }}]; + Assert.Equal(expected, {{ testedClass }}.Calculate(matrix).ToHashSet()); + {{ end -}} + } + {{ end -}} +} diff --git a/exercises/practice/saddle-points/SaddlePointsTests.cs b/exercises/practice/saddle-points/SaddlePointsTests.cs index 19d31df154..97c540c7df 100644 --- a/exercises/practice/saddle-points/SaddlePointsTests.cs +++ b/exercises/practice/saddle-points/SaddlePointsTests.cs @@ -1,4 +1,5 @@ -using System; +using System.Collections.Generic; +using System.Linq; using Xunit; public class SaddlePointsTests @@ -6,117 +7,110 @@ public class SaddlePointsTests [Fact] public void Can_identify_single_saddle_point() { - var matrix = new[,] + int[,] matrix = { - { 9, 8, 7 }, - { 5, 3, 2 }, - { 6, 6, 7 } + { 9, 8, 7 }, + { 5, 3, 2 }, + { 6, 6, 7 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (2, 1) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(2, 1)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_that_empty_matrix_has_no_saddle_points() { - var matrix = new int[,] { }; - var actual = SaddlePoints.Calculate(matrix); - Assert.Empty(actual); + int[,] matrix = + { + }; + Assert.Empty(SaddlePoints.Calculate(matrix)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_lack_of_saddle_points_when_there_are_none() { - var matrix = new[,] + int[,] matrix = { - { 1, 2, 3 }, - { 3, 1, 2 }, - { 2, 3, 1 } + { 1, 2, 3 }, + { 3, 1, 2 }, + { 2, 3, 1 } }; - var actual = SaddlePoints.Calculate(matrix); - Assert.Empty(actual); + Assert.Empty(SaddlePoints.Calculate(matrix)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_multiple_saddle_points_in_a_column() { - var matrix = new[,] + int[,] matrix = { - { 4, 5, 4 }, - { 3, 5, 5 }, - { 1, 5, 4 } + { 4, 5, 4 }, + { 3, 5, 5 }, + { 1, 5, 4 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (1, 2), (2, 2), (3, 2) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(1, 2), (2, 2), (3, 2)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_multiple_saddle_points_in_a_row() { - var matrix = new[,] + int[,] matrix = { - { 6, 7, 8 }, - { 5, 5, 5 }, - { 7, 5, 6 } + { 6, 7, 8 }, + { 5, 5, 5 }, + { 7, 5, 6 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (2, 1), (2, 2), (2, 3) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(2, 1), (2, 2), (2, 3)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_saddle_point_in_bottom_right_corner() { - var matrix = new[,] + int[,] matrix = { - { 8, 7, 9 }, - { 6, 7, 6 }, - { 3, 2, 5 } + { 8, 7, 9 }, + { 6, 7, 6 }, + { 3, 2, 5 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (3, 3) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(3, 3)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_saddle_points_in_a_non_square_matrix() { - var matrix = new[,] + int[,] matrix = { - { 3, 1, 3 }, - { 3, 2, 4 } + { 3, 1, 3 }, + { 3, 2, 4 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (1, 1), (1, 3) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(1, 3), (1, 1)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_that_saddle_points_in_a_single_column_matrix_are_those_with_the_minimum_value() { - var matrix = new[,] + int[,] matrix = { - { 2 }, - { 1 }, - { 4 }, - { 1 } + { 2 }, + { 1 }, + { 4 }, + { 1 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (2, 1), (4, 1) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(2, 1), (4, 1)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } [Fact(Skip = "Remove this Skip property to run this test")] public void Can_identify_that_saddle_points_in_a_single_row_matrix_are_those_with_the_maximum_value() { - var matrix = new[,] + int[,] matrix = { - { 2, 5, 3, 5 } + { 2, 5, 3, 5 } }; - var actual = SaddlePoints.Calculate(matrix); - var expected = new[] { (1, 2), (1, 4) }; - Assert.Equal(expected, actual); + HashSet<(int, int)> expected = [(1, 2), (1, 4)]; + Assert.Equal(expected, SaddlePoints.Calculate(matrix).ToHashSet()); } } diff --git a/exercises/practice/scale-generator/.meta/Generator.tpl b/exercises/practice/scale-generator/.meta/Generator.tpl new file mode 100644 index 0000000000..bce5013f48 --- /dev/null +++ b/exercises/practice/scale-generator/.meta/Generator.tpl @@ -0,0 +1,13 @@ +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + string[] expected = {{ test.expected }}; + Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.tonic | string.literal }}{{ if test.input.intervals }}, {{ test.input.intervals | string.literal}} {{ end }})); + } + {{ end -}} +} diff --git a/exercises/practice/scale-generator/ScaleGeneratorTests.cs b/exercises/practice/scale-generator/ScaleGeneratorTests.cs index fb396ece77..7e9001a88c 100644 --- a/exercises/practice/scale-generator/ScaleGeneratorTests.cs +++ b/exercises/practice/scale-generator/ScaleGeneratorTests.cs @@ -3,121 +3,121 @@ public class ScaleGeneratorTests { [Fact] - public void Chromatic_scale_with_sharps() + public void Chromatic_scales_chromatic_scale_with_sharps() { - var expected = new[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; + string[] expected = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]; Assert.Equal(expected, ScaleGenerator.Chromatic("C")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Chromatic_scale_with_flats() + public void Chromatic_scales_chromatic_scale_with_flats() { - var expected = new[] { "F", "Gb", "G", "Ab", "A", "Bb", "B", "C", "Db", "D", "Eb", "E" }; + string[] expected = ["F", "Gb", "G", "Ab", "A", "Bb", "B", "C", "Db", "D", "Eb", "E"]; Assert.Equal(expected, ScaleGenerator.Chromatic("F")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Simple_major_scale() + public void Scales_with_specified_intervals_simple_major_scale() { - var expected = new[] { "C", "D", "E", "F", "G", "A", "B", "C" }; + string[] expected = ["C", "D", "E", "F", "G", "A", "B", "C"]; Assert.Equal(expected, ScaleGenerator.Interval("C", "MMmMMMm")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Major_scale_with_sharps() + public void Scales_with_specified_intervals_major_scale_with_sharps() { - var expected = new[] { "G", "A", "B", "C", "D", "E", "F#", "G" }; + string[] expected = ["G", "A", "B", "C", "D", "E", "F#", "G"]; Assert.Equal(expected, ScaleGenerator.Interval("G", "MMmMMMm")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Major_scale_with_flats() + public void Scales_with_specified_intervals_major_scale_with_flats() { - var expected = new[] { "F", "G", "A", "Bb", "C", "D", "E", "F" }; + string[] expected = ["F", "G", "A", "Bb", "C", "D", "E", "F"]; Assert.Equal(expected, ScaleGenerator.Interval("F", "MMmMMMm")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Minor_scale_with_sharps() + public void Scales_with_specified_intervals_minor_scale_with_sharps() { - var expected = new[] { "F#", "G#", "A", "B", "C#", "D", "E", "F#" }; + string[] expected = ["F#", "G#", "A", "B", "C#", "D", "E", "F#"]; Assert.Equal(expected, ScaleGenerator.Interval("f#", "MmMMmMM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Minor_scale_with_flats() + public void Scales_with_specified_intervals_minor_scale_with_flats() { - var expected = new[] { "Bb", "C", "Db", "Eb", "F", "Gb", "Ab", "Bb" }; + string[] expected = ["Bb", "C", "Db", "Eb", "F", "Gb", "Ab", "Bb"]; Assert.Equal(expected, ScaleGenerator.Interval("bb", "MmMMmMM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Dorian_mode() + public void Scales_with_specified_intervals_dorian_mode() { - var expected = new[] { "D", "E", "F", "G", "A", "B", "C", "D" }; + string[] expected = ["D", "E", "F", "G", "A", "B", "C", "D"]; Assert.Equal(expected, ScaleGenerator.Interval("d", "MmMMMmM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Mixolydian_mode() + public void Scales_with_specified_intervals_mixolydian_mode() { - var expected = new[] { "Eb", "F", "G", "Ab", "Bb", "C", "Db", "Eb" }; + string[] expected = ["Eb", "F", "G", "Ab", "Bb", "C", "Db", "Eb"]; Assert.Equal(expected, ScaleGenerator.Interval("Eb", "MMmMMmM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Lydian_mode() + public void Scales_with_specified_intervals_lydian_mode() { - var expected = new[] { "A", "B", "C#", "D#", "E", "F#", "G#", "A" }; + string[] expected = ["A", "B", "C#", "D#", "E", "F#", "G#", "A"]; Assert.Equal(expected, ScaleGenerator.Interval("a", "MMMmMMm")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Phrygian_mode() + public void Scales_with_specified_intervals_phrygian_mode() { - var expected = new[] { "E", "F", "G", "A", "B", "C", "D", "E" }; + string[] expected = ["E", "F", "G", "A", "B", "C", "D", "E"]; Assert.Equal(expected, ScaleGenerator.Interval("e", "mMMMmMM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Locrian_mode() + public void Scales_with_specified_intervals_locrian_mode() { - var expected = new[] { "G", "Ab", "Bb", "C", "Db", "Eb", "F", "G" }; + string[] expected = ["G", "Ab", "Bb", "C", "Db", "Eb", "F", "G"]; Assert.Equal(expected, ScaleGenerator.Interval("g", "mMMmMMM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Harmonic_minor() + public void Scales_with_specified_intervals_harmonic_minor() { - var expected = new[] { "D", "E", "F", "G", "A", "Bb", "Db", "D" }; + string[] expected = ["D", "E", "F", "G", "A", "Bb", "Db", "D"]; Assert.Equal(expected, ScaleGenerator.Interval("d", "MmMMmAm")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Octatonic() + public void Scales_with_specified_intervals_octatonic() { - var expected = new[] { "C", "D", "D#", "F", "F#", "G#", "A", "B", "C" }; + string[] expected = ["C", "D", "D#", "F", "F#", "G#", "A", "B", "C"]; Assert.Equal(expected, ScaleGenerator.Interval("C", "MmMmMmMm")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Hexatonic() + public void Scales_with_specified_intervals_hexatonic() { - var expected = new[] { "Db", "Eb", "F", "G", "A", "B", "Db" }; + string[] expected = ["Db", "Eb", "F", "G", "A", "B", "Db"]; Assert.Equal(expected, ScaleGenerator.Interval("Db", "MMMMMM")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Pentatonic() + public void Scales_with_specified_intervals_pentatonic() { - var expected = new[] { "A", "B", "C#", "E", "F#", "A" }; + string[] expected = ["A", "B", "C#", "E", "F#", "A"]; Assert.Equal(expected, ScaleGenerator.Interval("A", "MMAMA")); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Enigmatic() + public void Scales_with_specified_intervals_enigmatic() { - var expected = new[] { "G", "G#", "B", "C#", "D#", "F", "F#", "G" }; + string[] expected = ["G", "G#", "B", "C#", "D#", "F", "F#", "G"]; Assert.Equal(expected, ScaleGenerator.Interval("G", "mAMMMmm")); } } diff --git a/exercises/practice/spiral-matrix/.meta/Generator.tpl b/exercises/practice/spiral-matrix/.meta/Generator.tpl new file mode 100644 index 0000000000..0ef880ffd5 --- /dev/null +++ b/exercises/practice/spiral-matrix/.meta/Generator.tpl @@ -0,0 +1,22 @@ +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + {{- if test.expected.empty? }} + Assert.Empty({{ testedClass }}.GetMatrix({{ test.input.size }})); + {{ else }} + int[,] expected = + { + {{- for row in test.expected }} + { {{ row | array.join ", " }} }{{- if !for.last }},{{ end -}} + {{ end }} + }; + Assert.Equal(expected, {{ testedClass }}.GetMatrix({{ test.input.size }})); + {{ end -}} + } + {{ end -}} +} diff --git a/exercises/practice/spiral-matrix/SpiralMatrixTests.cs b/exercises/practice/spiral-matrix/SpiralMatrixTests.cs index aa726dd31f..2b01cd89e7 100644 --- a/exercises/practice/spiral-matrix/SpiralMatrixTests.cs +++ b/exercises/practice/spiral-matrix/SpiralMatrixTests.cs @@ -11,9 +11,9 @@ public void Empty_spiral() [Fact(Skip = "Remove this Skip property to run this test")] public void Trivial_spiral() { - var expected = new[,] + int[,] expected = { - { 1 } + { 1 } }; Assert.Equal(expected, SpiralMatrix.GetMatrix(1)); } @@ -21,10 +21,10 @@ public void Trivial_spiral() [Fact(Skip = "Remove this Skip property to run this test")] public void Spiral_of_size_2() { - var expected = new[,] + int[,] expected = { - { 1, 2 }, - { 4, 3 } + { 1, 2 }, + { 4, 3 } }; Assert.Equal(expected, SpiralMatrix.GetMatrix(2)); } @@ -32,11 +32,11 @@ public void Spiral_of_size_2() [Fact(Skip = "Remove this Skip property to run this test")] public void Spiral_of_size_3() { - var expected = new[,] + int[,] expected = { - { 1, 2, 3 }, - { 8, 9, 4 }, - { 7, 6, 5 } + { 1, 2, 3 }, + { 8, 9, 4 }, + { 7, 6, 5 } }; Assert.Equal(expected, SpiralMatrix.GetMatrix(3)); } @@ -44,12 +44,12 @@ public void Spiral_of_size_3() [Fact(Skip = "Remove this Skip property to run this test")] public void Spiral_of_size_4() { - var expected = new[,] + int[,] expected = { - { 1, 2, 3, 4 }, - { 12, 13, 14, 5 }, - { 11, 16, 15, 6 }, - { 10, 9, 8, 7 } + { 1, 2, 3, 4 }, + { 12, 13, 14, 5 }, + { 11, 16, 15, 6 }, + { 10, 9, 8, 7 } }; Assert.Equal(expected, SpiralMatrix.GetMatrix(4)); } @@ -57,13 +57,13 @@ public void Spiral_of_size_4() [Fact(Skip = "Remove this Skip property to run this test")] public void Spiral_of_size_5() { - var expected = new[,] + int[,] expected = { - { 1, 2, 3, 4, 5 }, - { 16, 17, 18, 19, 6 }, - { 15, 24, 25, 20, 7 }, - { 14, 23, 22, 21, 8 }, - { 13, 12, 11, 10, 9 } + { 1, 2, 3, 4, 5 }, + { 16, 17, 18, 19, 6 }, + { 15, 24, 25, 20, 7 }, + { 14, 23, 22, 21, 8 }, + { 13, 12, 11, 10, 9 } }; Assert.Equal(expected, SpiralMatrix.GetMatrix(5)); } diff --git a/exercises/practice/tournament/.meta/Generator.tpl b/exercises/practice/tournament/.meta/Generator.tpl new file mode 100644 index 0000000000..33d49ac5f8 --- /dev/null +++ b/exercises/practice/tournament/.meta/Generator.tpl @@ -0,0 +1,44 @@ +{{ func lines(lines, variable) }} + {{- if lines.empty? }} + var {{variable}} = ""; + {{- else if (array.size lines) == 1 }} + var {{variable}} = {{ lines[0] | string.literal }}; + {{- else }} + var {{variable}} = + {{- for line in lines }} + {{ if for.last -}} + {{ line | string.literal -}}; + {{- else -}} + {{ line | string.append "\n" | string.literal }} + + {{- end -}} + {{- end }} + {{- end -}} +{{ end }} + +using System; +using System.IO; +using System.Text; +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + {{- test.input.rows | lines "rows" }} + {{- test.expected | lines "expected" }} + Assert.Equal(expected, RunTally(rows)); + } + {{ end }} + private string RunTally(string input) + { + var encoding = new UTF8Encoding(); + using (var inStream = new MemoryStream(encoding.GetBytes(input))) + using (var outStream = new MemoryStream()) + { + Tournament.Tally(inStream, outStream); + return encoding.GetString(outStream.ToArray()); + } + } +} diff --git a/exercises/practice/tournament/TournamentTests.cs b/exercises/practice/tournament/TournamentTests.cs index fcedd1b3bf..7fa3ff0797 100644 --- a/exercises/practice/tournament/TournamentTests.cs +++ b/exercises/practice/tournament/TournamentTests.cs @@ -17,7 +17,7 @@ public void Just_the_header_if_no_input() public void A_win_is_three_points_a_loss_is_zero_points() { var rows = "Allegoric Alaskans;Blithering Badgers;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" + "Blithering Badgers | 1 | 0 | 0 | 1 | 0"; @@ -28,7 +28,7 @@ public void A_win_is_three_points_a_loss_is_zero_points() public void A_win_can_also_be_expressed_as_a_loss() { var rows = "Blithering Badgers;Allegoric Alaskans;loss"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" + "Blithering Badgers | 1 | 0 | 0 | 1 | 0"; @@ -39,7 +39,7 @@ public void A_win_can_also_be_expressed_as_a_loss() public void A_different_team_can_win() { var rows = "Blithering Badgers;Allegoric Alaskans;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Blithering Badgers | 1 | 1 | 0 | 0 | 3\n" + "Allegoric Alaskans | 1 | 0 | 0 | 1 | 0"; @@ -50,7 +50,7 @@ public void A_different_team_can_win() public void A_draw_is_one_point_each() { var rows = "Allegoric Alaskans;Blithering Badgers;draw"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 1 | 0 | 1 | 0 | 1\n" + "Blithering Badgers | 1 | 0 | 1 | 0 | 1"; @@ -60,10 +60,10 @@ public void A_draw_is_one_point_each() [Fact(Skip = "Remove this Skip property to run this test")] public void There_can_be_more_than_one_match() { - var rows = + var rows = "Allegoric Alaskans;Blithering Badgers;win\n" + "Allegoric Alaskans;Blithering Badgers;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" + "Blithering Badgers | 2 | 0 | 0 | 2 | 0"; @@ -73,10 +73,10 @@ public void There_can_be_more_than_one_match() [Fact(Skip = "Remove this Skip property to run this test")] public void There_can_be_more_than_one_winner() { - var rows = + var rows = "Allegoric Alaskans;Blithering Badgers;loss\n" + "Allegoric Alaskans;Blithering Badgers;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 2 | 1 | 0 | 1 | 3\n" + "Blithering Badgers | 2 | 1 | 0 | 1 | 3"; @@ -86,11 +86,11 @@ public void There_can_be_more_than_one_winner() [Fact(Skip = "Remove this Skip property to run this test")] public void There_can_be_more_than_two_teams() { - var rows = + var rows = "Allegoric Alaskans;Blithering Badgers;win\n" + "Blithering Badgers;Courageous Californians;win\n" + "Courageous Californians;Allegoric Alaskans;loss"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" + "Blithering Badgers | 2 | 1 | 0 | 1 | 3\n" + @@ -101,14 +101,14 @@ public void There_can_be_more_than_two_teams() [Fact(Skip = "Remove this Skip property to run this test")] public void Typical_input() { - var rows = + var rows = "Allegoric Alaskans;Blithering Badgers;win\n" + "Devastating Donkeys;Courageous Californians;draw\n" + "Devastating Donkeys;Allegoric Alaskans;win\n" + "Courageous Californians;Blithering Badgers;loss\n" + "Blithering Badgers;Devastating Donkeys;loss\n" + "Allegoric Alaskans;Courageous Californians;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n" + "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" + @@ -118,14 +118,14 @@ public void Typical_input() } [Fact(Skip = "Remove this Skip property to run this test")] - public void Incomplete_competition_not_all_pairs_have_played_() + public void Incomplete_competition_not_all_pairs_have_played() { - var rows = + var rows = "Allegoric Alaskans;Blithering Badgers;loss\n" + "Devastating Donkeys;Allegoric Alaskans;loss\n" + "Courageous Californians;Blithering Badgers;draw\n" + "Allegoric Alaskans;Courageous Californians;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" + "Blithering Badgers | 2 | 1 | 1 | 0 | 4\n" + @@ -137,14 +137,14 @@ public void Incomplete_competition_not_all_pairs_have_played_() [Fact(Skip = "Remove this Skip property to run this test")] public void Ties_broken_alphabetically() { - var rows = + var rows = "Courageous Californians;Devastating Donkeys;win\n" + "Allegoric Alaskans;Blithering Badgers;win\n" + "Devastating Donkeys;Allegoric Alaskans;loss\n" + "Courageous Californians;Blithering Badgers;win\n" + "Blithering Badgers;Devastating Donkeys;draw\n" + "Allegoric Alaskans;Courageous Californians;draw"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Allegoric Alaskans | 3 | 2 | 1 | 0 | 7\n" + "Courageous Californians | 3 | 2 | 1 | 0 | 7\n" + @@ -156,13 +156,13 @@ public void Ties_broken_alphabetically() [Fact(Skip = "Remove this Skip property to run this test")] public void Ensure_points_sorted_numerically() { - var rows = + var rows = "Devastating Donkeys;Blithering Badgers;win\n" + "Devastating Donkeys;Blithering Badgers;win\n" + "Devastating Donkeys;Blithering Badgers;win\n" + "Devastating Donkeys;Blithering Badgers;win\n" + "Blithering Badgers;Devastating Donkeys;win"; - var expected = + var expected = "Team | MP | W | D | L | P\n" + "Devastating Donkeys | 5 | 4 | 0 | 1 | 12\n" + "Blithering Badgers | 5 | 1 | 0 | 4 | 3"; diff --git a/exercises/practice/transpose/.meta/Generator.tpl b/exercises/practice/transpose/.meta/Generator.tpl index ef2159b193..08b2955cf2 100644 --- a/exercises/practice/transpose/.meta/Generator.tpl +++ b/exercises/practice/transpose/.meta/Generator.tpl @@ -1,5 +1,5 @@ {{ func lines(lines, variable) }} - {{- if test.input.lines.empty? }} + {{- if lines.empty? }} var {{variable}} = ""; {{- else }} var {{variable}} = diff --git a/generators.deprecated/Exercises/Generators/GameOfLife.cs b/generators.deprecated/Exercises/Generators/GameOfLife.cs deleted file mode 100644 index 5a23e96307..0000000000 --- a/generators.deprecated/Exercises/Generators/GameOfLife.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Exercism.CSharp.Output; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class GameOfLife : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - - testMethod.Input["matrix"] = ToMultiDimensionalArray(testMethod.Input["matrix"]); - testMethod.Expected = ToMultiDimensionalArray(testMethod.Expected); - } - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Array).Namespace!); - - private static dynamic ToMultiDimensionalArray(JToken jArray) => jArray.ToObject()!; -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Minesweeper.cs b/generators.deprecated/Exercises/Generators/Minesweeper.cs deleted file mode 100644 index d09f06b794..0000000000 --- a/generators.deprecated/Exercises/Generators/Minesweeper.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Minesweeper : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - - testMethod.Input["minefield"] = RenderAsMultilineArray(testMethod.Input["minefield"]); - testMethod.Expected = RenderAsMultilineArray(testMethod.Expected); - } - - private UnescapedValue RenderAsMultilineArray(dynamic value) - => new(Render.ArrayMultiLine(value as string[] ?? Array.Empty())); - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Array).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Rectangles.cs b/generators.deprecated/Exercises/Generators/Rectangles.cs deleted file mode 100644 index dc7ec8d56e..0000000000 --- a/generators.deprecated/Exercises/Generators/Rectangles.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Rectangles : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.TestedMethod = "Count"; - - if (testMethod.Input["strings"] is JArray) - testMethod.Input["strings"] = Array.Empty(); - - testMethod.Input["strings"] = new UnescapedValue(Render.ArrayMultiLine(testMethod.Input["strings"])); - } - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Array).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/ReverseString.cs b/generators.deprecated/Exercises/Generators/ReverseString.cs deleted file mode 100644 index e20530ec4e..0000000000 --- a/generators.deprecated/Exercises/Generators/ReverseString.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Exercism.CSharp.Exercises.Generators; - -internal class ReverseString : ExerciseGenerator -{ -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/ScaleGenerator.cs b/generators.deprecated/Exercises/Generators/ScaleGenerator.cs deleted file mode 100644 index ec2c2367c2..0000000000 --- a/generators.deprecated/Exercises/Generators/ScaleGenerator.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class ScaleGenerator : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) => testMethod.UseVariableForExpected = true; -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/SpiralMatrix.cs b/generators.deprecated/Exercises/Generators/SpiralMatrix.cs deleted file mode 100644 index 2734d916bd..0000000000 --- a/generators.deprecated/Exercises/Generators/SpiralMatrix.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Exercism.CSharp.Output; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class SpiralMatrix : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestedMethod = "GetMatrix"; - testMethod.UseVariableForExpected = true; - testMethod.Expected = ConvertExpected(testMethod.Expected); - } - - private static int[,] ConvertExpected(JToken jArray) => jArray.ToObject()!; -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Tournament.cs b/generators.deprecated/Exercises/Generators/Tournament.cs deleted file mode 100644 index 649391c95c..0000000000 --- a/generators.deprecated/Exercises/Generators/Tournament.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Tournament : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestedMethod = "RunTally"; - testMethod.TestedMethodType = TestedMethodType.StaticMethod; - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - testMethod.Input["rows"] = new MultiLineString(testMethod.Input["rows"]); - testMethod.Expected = new MultiLineString(testMethod.Expected); - - testMethod.Assert = RenderAssert(); - } - - private string RenderAssert() => Render.AssertEqual("expected", "RunTally(rows)"); - - protected override void UpdateTestClass(TestClass testClass) => AddRunTallyMethod(testClass); - - private static void AddRunTallyMethod(TestClass testClass) => - testClass.AdditionalMethods.Add(@" -private string RunTally(string input) -{ - var encoding = new UTF8Encoding(); - - using (var inStream = new MemoryStream(encoding.GetBytes(input))) - using (var outStream = new MemoryStream()) - { - Tournament.Tally(inStream, outStream); - return encoding.GetString(outStream.ToArray()); - } -}"); - - protected override void UpdateNamespaces(ISet namespaces) - { - namespaces.Add(typeof(Array).Namespace!); - namespaces.Add(typeof(Stream).Namespace!); - namespaces.Add(typeof(UTF8Encoding).Namespace!); - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Transpose.cs b/generators.deprecated/Exercises/Generators/Transpose.cs deleted file mode 100644 index dc35fe590e..0000000000 --- a/generators.deprecated/Exercises/Generators/Transpose.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Transpose : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestedMethod = "String"; - testMethod.Input["lines"] = new MultiLineString(testMethod.Input["lines"]); - testMethod.Expected = new MultiLineString(testMethod.Expected); - - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/TwelveDays.cs b/generators.deprecated/Exercises/Generators/TwelveDays.cs deleted file mode 100644 index 40d8a57469..0000000000 --- a/generators.deprecated/Exercises/Generators/TwelveDays.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class TwelveDays : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariableForExpected = true; - testMethod.Expected = new MultiLineString(testMethod.Expected); - - if (testMethod.Input["startVerse"] == testMethod.Input["endVerse"]) - { - testMethod.InputParameters = new[] { "startVerse" }; - } - } -} \ No newline at end of file