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
12 changes: 12 additions & 0 deletions exercises/practice/crypto-square/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -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.plaintext | string.literal }}));
}
{{ end -}}
}
40 changes: 16 additions & 24 deletions exercises/practice/crypto-square/CryptoSquareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,48 @@ public class CryptoSquareTests
[Fact]
public void Empty_plaintext_results_in_an_empty_ciphertext()
{
var plaintext = "";
var expected = "";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("", CryptoSquare.Ciphertext(""));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Normalization_results_in_empty_plaintext()
{
Assert.Equal("", CryptoSquare.Ciphertext("... --- ..."));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Lowercase()
{
var plaintext = "A";
var expected = "a";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("a", CryptoSquare.Ciphertext("A"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Remove_spaces()
{
var plaintext = " b ";
var expected = "b";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("b", CryptoSquare.Ciphertext(" b "));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Remove_punctuation()
{
var plaintext = "@1,%!";
var expected = "1";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("1", CryptoSquare.Ciphertext("@1,%!"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Number_9_character_plaintext_results_in_3_chunks_of_3_characters()
public void Nine_character_plaintext_results_in_3_chunks_of_3_characters()
{
var plaintext = "This is fun!";
var expected = "tsf hiu isn";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("tsf hiu isn", CryptoSquare.Ciphertext("This is fun!"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Number_8_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space()
public void Eight_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space()
{
var plaintext = "Chill out.";
var expected = "clu hlt io ";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("clu hlt io ", CryptoSquare.Ciphertext("Chill out."));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Number_54_character_plaintext_results_in_7_chunks_the_last_two_with_trailing_spaces()
public void Fifty_four_character_plaintext_results_in_7_chunks_the_last_two_with_trailing_spaces()
{
var plaintext = "If man was meant to stay on the ground, god would have given us roots.";
var expected = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ";
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
Assert.Equal("imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ", CryptoSquare.Ciphertext("If man was meant to stay on the ground, god would have given us roots."));
}
}
12 changes: 12 additions & 0 deletions exercises/practice/dominoes/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -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.{{ test.expected ? "True" : "False" }}({{ testedClass }}.{{ test.testedMethod }}([{{for pair in test.input.dominoes}}({{ pair[0] }}, {{ pair[1] }}){{ if !for.last}}, {{ end }}{{ end }}]));
}
{{ end -}}
}
44 changes: 15 additions & 29 deletions exercises/practice/dominoes/DominoesTests.cs
Original file line number Diff line number Diff line change
@@ -1,96 +1,82 @@
using System;
using Xunit;

public class DominoesTests
{
[Fact]
public void Empty_input_empty_output()
{
var dominoes = Array.Empty<(int, int)>();
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Singleton_input_singleton_output()
{
var dominoes = new[] { (1, 1) };
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([(1, 1)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Singleton_that_cant_be_chained()
public void Singleton_that_can_t_be_chained()
{
var dominoes = new[] { (1, 2) };
Assert.False(Dominoes.CanChain(dominoes));
Assert.False(Dominoes.CanChain([(1, 2)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Three_elements()
{
var dominoes = new[] { (1, 2), (3, 1), (2, 3) };
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([(1, 2), (3, 1), (2, 3)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_reverse_dominoes()
{
var dominoes = new[] { (1, 2), (1, 3), (2, 3) };
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([(1, 2), (1, 3), (2, 3)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Cant_be_chained()
public void Can_t_be_chained()
{
var dominoes = new[] { (1, 2), (4, 1), (2, 3) };
Assert.False(Dominoes.CanChain(dominoes));
Assert.False(Dominoes.CanChain([(1, 2), (4, 1), (2, 3)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Disconnected_simple()
{
var dominoes = new[] { (1, 1), (2, 2) };
Assert.False(Dominoes.CanChain(dominoes));
Assert.False(Dominoes.CanChain([(1, 1), (2, 2)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Disconnected_double_loop()
{
var dominoes = new[] { (1, 2), (2, 1), (3, 4), (4, 3) };
Assert.False(Dominoes.CanChain(dominoes));
Assert.False(Dominoes.CanChain([(1, 2), (2, 1), (3, 4), (4, 3)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Disconnected_single_isolated()
{
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (4, 4) };
Assert.False(Dominoes.CanChain(dominoes));
Assert.False(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (4, 4)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Need_backtrack()
{
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (2, 4), (2, 4) };
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (2, 4), (2, 4)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Separate_loops()
{
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (1, 1), (2, 2), (3, 3) };
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (1, 1), (2, 2), (3, 3)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Nine_elements()
{
var dominoes = new[] { (1, 2), (5, 3), (3, 1), (1, 2), (2, 4), (1, 6), (2, 3), (3, 4), (5, 6) };
Assert.True(Dominoes.CanChain(dominoes));
Assert.True(Dominoes.CanChain([(1, 2), (5, 3), (3, 1), (1, 2), (2, 4), (1, 6), (2, 3), (3, 4), (5, 6)]));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Separate_three_domino_loops()
{
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (6, 4) };
Assert.False(Dominoes.CanChain(dominoes));
Assert.False(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (6, 4)]));
}
}
20 changes: 20 additions & 0 deletions exercises/practice/forth/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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.expected.error }}
Assert.Throws<{{ if test.expected.error == "divide by zero" }}DivideByZeroException{{ else }}InvalidOperationException{{ end }}>(() => {{ testedClass }}.{{ test.testedMethod }}({{ test.input.instructions }}));
{{ else if test.property == "evaluateBoth" }}
Assert.Equal("{{test.expected[0] | array.join " "}}", {{ testedClass }}.Evaluate({{ test.input.instructionsFirst }}));
Assert.Equal("{{test.expected[1] | array.join " "}}", {{ testedClass }}.Evaluate({{ test.input.instructionsSecond }}));
{{ else }}
Assert.Equal("{{test.expected | array.join " "}}", {{ testedClass }}.{{ test.testedMethod }}({{ test.input.instructions }}));
{{ end -}}
}
{{ end -}}
}
Loading
Loading