Skip to content

Commit 0794ec4

Browse files
And-more (#2369)
* crypto-square: add generator * dominoes: add generator * forth: add generator * knapsack: add generator * meetup: add generator * poker: add generator * pascals-triangle: add generator * isbn-verifier: add generator * gigasecond: add generator * Fix * Fix meetup * forth [no important files changed]
1 parent 4ca1eb3 commit 0794ec4

File tree

16 files changed

+463
-294
lines changed

16 files changed

+463
-294
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
public class {{ testClass }}
4+
{
5+
{{- for test in tests }}
6+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
7+
public void {{ test.testMethod }}()
8+
{
9+
Assert.Equal({{ test.expected | string.literal }}, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.plaintext | string.literal }}));
10+
}
11+
{{ end -}}
12+
}

exercises/practice/crypto-square/CryptoSquareTests.cs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,48 @@ public class CryptoSquareTests
55
[Fact]
66
public void Empty_plaintext_results_in_an_empty_ciphertext()
77
{
8-
var plaintext = "";
9-
var expected = "";
10-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
8+
Assert.Equal("", CryptoSquare.Ciphertext(""));
9+
}
10+
11+
[Fact(Skip = "Remove this Skip property to run this test")]
12+
public void Normalization_results_in_empty_plaintext()
13+
{
14+
Assert.Equal("", CryptoSquare.Ciphertext("... --- ..."));
1115
}
1216

1317
[Fact(Skip = "Remove this Skip property to run this test")]
1418
public void Lowercase()
1519
{
16-
var plaintext = "A";
17-
var expected = "a";
18-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
20+
Assert.Equal("a", CryptoSquare.Ciphertext("A"));
1921
}
2022

2123
[Fact(Skip = "Remove this Skip property to run this test")]
2224
public void Remove_spaces()
2325
{
24-
var plaintext = " b ";
25-
var expected = "b";
26-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
26+
Assert.Equal("b", CryptoSquare.Ciphertext(" b "));
2727
}
2828

2929
[Fact(Skip = "Remove this Skip property to run this test")]
3030
public void Remove_punctuation()
3131
{
32-
var plaintext = "@1,%!";
33-
var expected = "1";
34-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
32+
Assert.Equal("1", CryptoSquare.Ciphertext("@1,%!"));
3533
}
3634

3735
[Fact(Skip = "Remove this Skip property to run this test")]
38-
public void Number_9_character_plaintext_results_in_3_chunks_of_3_characters()
36+
public void Nine_character_plaintext_results_in_3_chunks_of_3_characters()
3937
{
40-
var plaintext = "This is fun!";
41-
var expected = "tsf hiu isn";
42-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
38+
Assert.Equal("tsf hiu isn", CryptoSquare.Ciphertext("This is fun!"));
4339
}
4440

4541
[Fact(Skip = "Remove this Skip property to run this test")]
46-
public void Number_8_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space()
42+
public void Eight_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space()
4743
{
48-
var plaintext = "Chill out.";
49-
var expected = "clu hlt io ";
50-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
44+
Assert.Equal("clu hlt io ", CryptoSquare.Ciphertext("Chill out."));
5145
}
5246

5347
[Fact(Skip = "Remove this Skip property to run this test")]
54-
public void Number_54_character_plaintext_results_in_7_chunks_the_last_two_with_trailing_spaces()
48+
public void Fifty_four_character_plaintext_results_in_7_chunks_the_last_two_with_trailing_spaces()
5549
{
56-
var plaintext = "If man was meant to stay on the ground, god would have given us roots.";
57-
var expected = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ";
58-
Assert.Equal(expected, CryptoSquare.Ciphertext(plaintext));
50+
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."));
5951
}
6052
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
public class {{ testClass }}
4+
{
5+
{{- for test in tests }}
6+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
7+
public void {{ test.testMethod }}()
8+
{
9+
Assert.{{ test.expected ? "True" : "False" }}({{ testedClass }}.{{ test.testedMethod }}([{{for pair in test.input.dominoes}}({{ pair[0] }}, {{ pair[1] }}){{ if !for.last}}, {{ end }}{{ end }}]));
10+
}
11+
{{ end -}}
12+
}
Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,82 @@
1-
using System;
21
using Xunit;
32

43
public class DominoesTests
54
{
65
[Fact]
76
public void Empty_input_empty_output()
87
{
9-
var dominoes = Array.Empty<(int, int)>();
10-
Assert.True(Dominoes.CanChain(dominoes));
8+
Assert.True(Dominoes.CanChain([]));
119
}
1210

1311
[Fact(Skip = "Remove this Skip property to run this test")]
1412
public void Singleton_input_singleton_output()
1513
{
16-
var dominoes = new[] { (1, 1) };
17-
Assert.True(Dominoes.CanChain(dominoes));
14+
Assert.True(Dominoes.CanChain([(1, 1)]));
1815
}
1916

2017
[Fact(Skip = "Remove this Skip property to run this test")]
21-
public void Singleton_that_cant_be_chained()
18+
public void Singleton_that_can_t_be_chained()
2219
{
23-
var dominoes = new[] { (1, 2) };
24-
Assert.False(Dominoes.CanChain(dominoes));
20+
Assert.False(Dominoes.CanChain([(1, 2)]));
2521
}
2622

2723
[Fact(Skip = "Remove this Skip property to run this test")]
2824
public void Three_elements()
2925
{
30-
var dominoes = new[] { (1, 2), (3, 1), (2, 3) };
31-
Assert.True(Dominoes.CanChain(dominoes));
26+
Assert.True(Dominoes.CanChain([(1, 2), (3, 1), (2, 3)]));
3227
}
3328

3429
[Fact(Skip = "Remove this Skip property to run this test")]
3530
public void Can_reverse_dominoes()
3631
{
37-
var dominoes = new[] { (1, 2), (1, 3), (2, 3) };
38-
Assert.True(Dominoes.CanChain(dominoes));
32+
Assert.True(Dominoes.CanChain([(1, 2), (1, 3), (2, 3)]));
3933
}
4034

4135
[Fact(Skip = "Remove this Skip property to run this test")]
42-
public void Cant_be_chained()
36+
public void Can_t_be_chained()
4337
{
44-
var dominoes = new[] { (1, 2), (4, 1), (2, 3) };
45-
Assert.False(Dominoes.CanChain(dominoes));
38+
Assert.False(Dominoes.CanChain([(1, 2), (4, 1), (2, 3)]));
4639
}
4740

4841
[Fact(Skip = "Remove this Skip property to run this test")]
4942
public void Disconnected_simple()
5043
{
51-
var dominoes = new[] { (1, 1), (2, 2) };
52-
Assert.False(Dominoes.CanChain(dominoes));
44+
Assert.False(Dominoes.CanChain([(1, 1), (2, 2)]));
5345
}
5446

5547
[Fact(Skip = "Remove this Skip property to run this test")]
5648
public void Disconnected_double_loop()
5749
{
58-
var dominoes = new[] { (1, 2), (2, 1), (3, 4), (4, 3) };
59-
Assert.False(Dominoes.CanChain(dominoes));
50+
Assert.False(Dominoes.CanChain([(1, 2), (2, 1), (3, 4), (4, 3)]));
6051
}
6152

6253
[Fact(Skip = "Remove this Skip property to run this test")]
6354
public void Disconnected_single_isolated()
6455
{
65-
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (4, 4) };
66-
Assert.False(Dominoes.CanChain(dominoes));
56+
Assert.False(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (4, 4)]));
6757
}
6858

6959
[Fact(Skip = "Remove this Skip property to run this test")]
7060
public void Need_backtrack()
7161
{
72-
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (2, 4), (2, 4) };
73-
Assert.True(Dominoes.CanChain(dominoes));
62+
Assert.True(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (2, 4), (2, 4)]));
7463
}
7564

7665
[Fact(Skip = "Remove this Skip property to run this test")]
7766
public void Separate_loops()
7867
{
79-
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (1, 1), (2, 2), (3, 3) };
80-
Assert.True(Dominoes.CanChain(dominoes));
68+
Assert.True(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (1, 1), (2, 2), (3, 3)]));
8169
}
8270

8371
[Fact(Skip = "Remove this Skip property to run this test")]
8472
public void Nine_elements()
8573
{
86-
var dominoes = new[] { (1, 2), (5, 3), (3, 1), (1, 2), (2, 4), (1, 6), (2, 3), (3, 4), (5, 6) };
87-
Assert.True(Dominoes.CanChain(dominoes));
74+
Assert.True(Dominoes.CanChain([(1, 2), (5, 3), (3, 1), (1, 2), (2, 4), (1, 6), (2, 3), (3, 4), (5, 6)]));
8875
}
8976

9077
[Fact(Skip = "Remove this Skip property to run this test")]
9178
public void Separate_three_domino_loops()
9279
{
93-
var dominoes = new[] { (1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (6, 4) };
94-
Assert.False(Dominoes.CanChain(dominoes));
80+
Assert.False(Dominoes.CanChain([(1, 2), (2, 3), (3, 1), (4, 5), (5, 6), (6, 4)]));
9581
}
9682
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Xunit;
3+
4+
public class {{ testClass }}
5+
{
6+
{{- for test in tests }}
7+
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
8+
public void {{ test.testMethod }}()
9+
{
10+
{{- if test.expected.error }}
11+
Assert.Throws<{{ if test.expected.error == "divide by zero" }}DivideByZeroException{{ else }}InvalidOperationException{{ end }}>(() => {{ testedClass }}.{{ test.testedMethod }}({{ test.input.instructions }}));
12+
{{ else if test.property == "evaluateBoth" }}
13+
Assert.Equal("{{test.expected[0] | array.join " "}}", {{ testedClass }}.Evaluate({{ test.input.instructionsFirst }}));
14+
Assert.Equal("{{test.expected[1] | array.join " "}}", {{ testedClass }}.Evaluate({{ test.input.instructionsSecond }}));
15+
{{ else }}
16+
Assert.Equal("{{test.expected | array.join " "}}", {{ testedClass }}.{{ test.testedMethod }}({{ test.input.instructions }}));
17+
{{ end -}}
18+
}
19+
{{ end -}}
20+
}

0 commit comments

Comments
 (0)