Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

word-search: add generator #2374

Merged
merged 5 commits into from
Feb 5, 2025
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
24 changes: 24 additions & 0 deletions exercises/practice/nucleotide-count/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
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.error }}
Assert.Throws<ArgumentException>(() => {{ testedClass }}.Count({{ test.input.strand | string.literal }}));
{{ else }}
var expected = new Dictionary<char, int>
{
{{- for key in test.expected | object.keys }}
['{{ key }}'] = {{ test.expected[key] }}{{- if !for.last }},{{ end -}}
{{ end -}}
};
Assert.Equal(expected, {{ testedClass }}.Count({{ test.input.strand | string.literal }}));
{{ end -}}
}
{{ end -}}
}
17 changes: 17 additions & 0 deletions exercises/practice/prime-factors/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 }}.{{ test.testedMethod }}({{ test.input.value }}));
{{- else }}
long[] expected = {{ test.expected }};
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.value }}));
{{ end -}}
}
{{ end -}}
}
35 changes: 23 additions & 12 deletions exercises/practice/prime-factors/PrimeFactorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,83 @@ public class PrimeFactorsTests
[Fact]
public void No_factors()
{
Assert.Empty(PrimeFactors.Factors(1L));
Assert.Empty(PrimeFactors.Factors(1));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Prime_number()
{
Assert.Equal(new[] { 2L }, PrimeFactors.Factors(2L));
long[] expected = [2];
Assert.Equal(expected, PrimeFactors.Factors(2));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Another_prime_number()
{
Assert.Equal(new[] { 3L }, PrimeFactors.Factors(3L));
long[] expected = [3];
Assert.Equal(expected, PrimeFactors.Factors(3));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Square_of_a_prime()
{
Assert.Equal(new[] { 3L, 3L }, PrimeFactors.Factors(9L));
long[] expected = [3, 3];
Assert.Equal(expected, PrimeFactors.Factors(9));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Product_of_first_prime()
{
Assert.Equal(new[] { 2L, 2L }, PrimeFactors.Factors(4L));
long[] expected = [2, 2];
Assert.Equal(expected, PrimeFactors.Factors(4));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Cube_of_a_prime()
{
Assert.Equal(new[] { 2L, 2L, 2L }, PrimeFactors.Factors(8L));
long[] expected = [2, 2, 2];
Assert.Equal(expected, PrimeFactors.Factors(8));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Product_of_second_prime()
{
Assert.Equal(new[] { 3L, 3L, 3L }, PrimeFactors.Factors(27L));
long[] expected = [3, 3, 3];
Assert.Equal(expected, PrimeFactors.Factors(27));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Product_of_third_prime()
{
Assert.Equal(new[] { 5L, 5L, 5L, 5L }, PrimeFactors.Factors(625L));
long[] expected = [5, 5, 5, 5];
Assert.Equal(expected, PrimeFactors.Factors(625));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Product_of_first_and_second_prime()
{
Assert.Equal(new[] { 2L, 3L }, PrimeFactors.Factors(6L));
long[] expected = [2, 3];
Assert.Equal(expected, PrimeFactors.Factors(6));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Product_of_primes_and_non_primes()
{
Assert.Equal(new[] { 2L, 2L, 3L }, PrimeFactors.Factors(12L));
long[] expected = [2, 2, 3];
Assert.Equal(expected, PrimeFactors.Factors(12));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Product_of_primes()
{
Assert.Equal(new[] { 5L, 17L, 23L, 461L }, PrimeFactors.Factors(901255L));
long[] expected = [5, 17, 23, 461];
Assert.Equal(expected, PrimeFactors.Factors(901255));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Factors_include_a_large_prime()
{
Assert.Equal(new[] { 11L, 9539L, 894119L }, PrimeFactors.Factors(93819012551L));
long[] expected = [11, 9539, 894119];
Assert.Equal(expected, PrimeFactors.Factors(93819012551));
}
}
21 changes: 21 additions & 0 deletions exercises/practice/pythagorean-triplet/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 }}.{{ test.testedMethod }}({{ test.input.n }}));
{{- else }}
(int,int,int)[] expected = [
{{- for expected in test.expected }}
({{ expected | array.join ", " }}){{- if !for.last }},{{ end -}}
{{ end }}
];
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.n }}));
{{ end -}}
}
{{ end -}}
}
39 changes: 19 additions & 20 deletions exercises/practice/pythagorean-triplet/PythagoreanTripletTests.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
using System;
using Xunit;

public class PythagoreanTripletTests
{
[Fact]
public void Triplets_whose_sum_is_12()
{
Assert.Equal(new[]
{
(int, int, int)[] expected = [
(3, 4, 5)
}, PythagoreanTriplet.TripletsWithSum(12));
];
Assert.Equal(expected, PythagoreanTriplet.TripletsWithSum(12));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Triplets_whose_sum_is_108()
{
Assert.Equal(new[]
{
(int, int, int)[] expected = [
(27, 36, 45)
}, PythagoreanTriplet.TripletsWithSum(108));
];
Assert.Equal(expected, PythagoreanTriplet.TripletsWithSum(108));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Triplets_whose_sum_is_1000()
{
Assert.Equal(new[]
{
(int, int, int)[] expected = [
(200, 375, 425)
}, PythagoreanTriplet.TripletsWithSum(1000));
];
Assert.Equal(expected, PythagoreanTriplet.TripletsWithSum(1000));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void No_matching_triplets_for_1001()
{
Assert.Equal(Array.Empty<(int, int, int)>(), PythagoreanTriplet.TripletsWithSum(1001));
Assert.Empty(PythagoreanTriplet.TripletsWithSum(1001));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Returns_all_matching_triplets()
{
Assert.Equal(new[]
{
(int, int, int)[] expected = [
(9, 40, 41),
(15, 36, 39)
}, PythagoreanTriplet.TripletsWithSum(90));
];
Assert.Equal(expected, PythagoreanTriplet.TripletsWithSum(90));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Several_matching_triplets()
{
Assert.Equal(new[]
{
(int, int, int)[] expected = [
(40, 399, 401),
(56, 390, 394),
(105, 360, 375),
Expand All @@ -59,19 +57,20 @@ public void Several_matching_triplets()
(168, 315, 357),
(210, 280, 350),
(240, 252, 348)
}, PythagoreanTriplet.TripletsWithSum(840));
];
Assert.Equal(expected, PythagoreanTriplet.TripletsWithSum(840));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Triplets_for_large_number()
{
Assert.Equal(new[]
{
(int, int, int)[] expected = [
(1200, 14375, 14425),
(1875, 14000, 14125),
(5000, 12000, 13000),
(6000, 11250, 12750),
(7500, 10000, 12500)
}, PythagoreanTriplet.TripletsWithSum(30000));
];
Assert.Equal(expected, PythagoreanTriplet.TripletsWithSum(30000));
}
}
23 changes: 23 additions & 0 deletions exercises/practice/queen-attack/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.shortTestMethod }}()
{
{{- if test.property == "create" }}
{{- if test.expected.error }}
Assert.Throws<ArgumentOutOfRangeException>(() => {{ testedClass }}.{{ test.testedMethod }}({{ test.input.queen.position.row }}, {{ test.input.queen.position.column }}));
{{ else }}
var queen = {{ testedClass }}.{{ test.testedMethod }}({{ test.input.queen.position.row }}, {{ test.input.queen.position.column }});
{{ end -}}
{{- else }}
var whiteQueen = {{ testedClass }}.Create({{ test.input.white_queen.position.row }}, {{ test.input.white_queen.position.column }});
var blackQueen = {{ testedClass }}.Create({{ test.input.black_queen.position.row }}, {{ test.input.black_queen.position.column }});
Assert.{{ test.expected ? "True" : "False" }}({{ testedClass }}.{{ test.testedMethod }}(whiteQueen, blackQueen));
{{ end -}}
}
{{ end -}}
}
34 changes: 17 additions & 17 deletions exercises/practice/queen-attack/QueenAttackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class QueenAttackTests
[Fact]
public void Queen_with_a_valid_position()
{
var actual = QueenAttack.Create(2, 2);
var queen = QueenAttack.Create(2, 2);
}

[Fact(Skip = "Remove this Skip property to run this test")]
Expand Down Expand Up @@ -36,64 +36,64 @@ public void Queen_must_have_column_on_board()
[Fact(Skip = "Remove this Skip property to run this test")]
public void Cannot_attack()
{
var whiteQueen = QueenAttack.Create(2,4);
var blackQueen = QueenAttack.Create(6,6);
var whiteQueen = QueenAttack.Create(2, 4);
var blackQueen = QueenAttack.Create(6, 6);
Assert.False(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_attack_on_same_row()
{
var whiteQueen = QueenAttack.Create(2,4);
var blackQueen = QueenAttack.Create(2,6);
var whiteQueen = QueenAttack.Create(2, 4);
var blackQueen = QueenAttack.Create(2, 6);
Assert.True(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_attack_on_same_column()
{
var whiteQueen = QueenAttack.Create(4,5);
var blackQueen = QueenAttack.Create(2,5);
var whiteQueen = QueenAttack.Create(4, 5);
var blackQueen = QueenAttack.Create(2, 5);
Assert.True(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_attack_on_first_diagonal()
{
var whiteQueen = QueenAttack.Create(2,2);
var blackQueen = QueenAttack.Create(0,4);
var whiteQueen = QueenAttack.Create(2, 2);
var blackQueen = QueenAttack.Create(0, 4);
Assert.True(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_attack_on_second_diagonal()
{
var whiteQueen = QueenAttack.Create(2,2);
var blackQueen = QueenAttack.Create(3,1);
var whiteQueen = QueenAttack.Create(2, 2);
var blackQueen = QueenAttack.Create(3, 1);
Assert.True(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_attack_on_third_diagonal()
{
var whiteQueen = QueenAttack.Create(2,2);
var blackQueen = QueenAttack.Create(1,1);
var whiteQueen = QueenAttack.Create(2, 2);
var blackQueen = QueenAttack.Create(1, 1);
Assert.True(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_attack_on_fourth_diagonal()
{
var whiteQueen = QueenAttack.Create(1,7);
var blackQueen = QueenAttack.Create(0,6);
var whiteQueen = QueenAttack.Create(1, 7);
var blackQueen = QueenAttack.Create(0, 6);
Assert.True(QueenAttack.CanAttack(whiteQueen, blackQueen));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Cannot_attack_if_falling_diagonals_are_only_the_same_when_reflected_across_the_longest_falling_diagonal()
{
var whiteQueen = QueenAttack.Create(4,1);
var blackQueen = QueenAttack.Create(2,5);
var whiteQueen = QueenAttack.Create(4, 1);
var blackQueen = QueenAttack.Create(2, 5);
Assert.False(QueenAttack.CanAttack(whiteQueen, blackQueen));
}
}
Loading
Loading