-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* triangle: simplify generator * Remove grouped test cases * yacht: add generator * word-count: add generator * variable-length-quantity: add generator * simple-cipher: add generator * series: add generator
- Loading branch information
1 parent
d3bd5a3
commit 2783eaf
Showing
17 changed files
with
250 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using Xunit; | ||
|
||
public class SeriesTests | ||
{ | ||
{{for testCase in testCases}} | ||
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] | ||
public void {{testCase.testMethodName}}() | ||
{ | ||
{{if testCase.expected.error}} | ||
Assert.Throws<ArgumentException>(() => Series.Slices({{testCase.input.series | string.literal}}, {{testCase.input.sliceLength}})); | ||
{{else}} | ||
string[] expected = {{testCase.expected}}; | ||
Assert.Equal(expected, Series.Slices({{testCase.input.series | string.literal}}, {{testCase.input.sliceLength}})); | ||
{{end}} | ||
} | ||
{{end}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,77 @@ | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
public class SeriesTests | ||
{ | ||
[Fact] | ||
public void Slices_of_one_from_one() | ||
{ | ||
var expected = new[] { "1" }; | ||
Assert.Equal(expected, Series.Slices("1", 1).ToArray()); | ||
string[] expected = ["1"]; | ||
Assert.Equal(expected, Series.Slices("1", 1)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slices_of_one_from_two() | ||
{ | ||
var expected = new[] { "1", "2" }; | ||
Assert.Equal(expected, Series.Slices("12", 1).ToArray()); | ||
string[] expected = ["1", "2"]; | ||
Assert.Equal(expected, Series.Slices("12", 1)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slices_of_two() | ||
{ | ||
var expected = new[] { "35" }; | ||
Assert.Equal(expected, Series.Slices("35", 2).ToArray()); | ||
string[] expected = ["35"]; | ||
Assert.Equal(expected, Series.Slices("35", 2)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slices_of_two_overlap() | ||
{ | ||
var expected = new[] { "91", "14", "42" }; | ||
Assert.Equal(expected, Series.Slices("9142", 2).ToArray()); | ||
string[] expected = ["91", "14", "42"]; | ||
Assert.Equal(expected, Series.Slices("9142", 2)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slices_can_include_duplicates() | ||
{ | ||
var expected = new[] { "777", "777", "777", "777" }; | ||
Assert.Equal(expected, Series.Slices("777777", 3).ToArray()); | ||
string[] expected = ["777", "777", "777", "777"]; | ||
Assert.Equal(expected, Series.Slices("777777", 3)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slices_of_a_long_series() | ||
{ | ||
var expected = new[] { "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243" }; | ||
Assert.Equal(expected, Series.Slices("918493904243", 5).ToArray()); | ||
string[] expected = ["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243"]; | ||
Assert.Equal(expected, Series.Slices("918493904243", 5)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slice_length_is_too_large() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 6).ToArray()); | ||
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 6)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slice_length_is_way_too_large() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 42).ToArray()); | ||
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 42)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slice_length_cannot_be_zero() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 0).ToArray()); | ||
Assert.Throws<ArgumentException>(() => Series.Slices("12345", 0)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Slice_length_cannot_be_negative() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Series.Slices("123", -1).ToArray()); | ||
Assert.Throws<ArgumentException>(() => Series.Slices("123", -1)); | ||
} | ||
|
||
[Fact(Skip = "Remove this Skip property to run this test")] | ||
public void Empty_series_is_invalid() | ||
{ | ||
Assert.Throws<ArgumentException>(() => Series.Slices("", 1).ToArray()); | ||
Assert.Throws<ArgumentException>(() => Series.Slices("", 1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Xunit; | ||
|
||
{{func decode_arg}} | ||
{{if $0.input.ciphertext == "cipher.encode"}} | ||
sut.Encode({{$0.input.plaintext | string.literal}}) | ||
{{else if $0.input.ciphertext == "cipher.key.substring(0, expected.length)"}} | ||
sut.Key.Substring(0, 10) | ||
{{else}} | ||
{{$0.input.ciphertext | string.literal}} | ||
{{end}} | ||
{{end}} | ||
|
||
{{func expected_value}} | ||
{{if $0 == "cipher.key.substring(0, plaintext.length)"}} | ||
sut.Key.Substring(0, 10) | ||
{{else}} | ||
{{ $0 | string.literal }} | ||
{{end}} | ||
{{end}} | ||
|
||
public class SimpleCipherTests | ||
{ | ||
{{for testCase in testCases}} | ||
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] | ||
public void {{testCase.testMethodName}}() | ||
{ | ||
var sut = new SimpleCipher({{if testCase.input.key}}{{testCase.input.key | string.literal}}{{end}}); | ||
{{if testCase.property == "encode"}} | ||
Assert.Equal({{testCase.expected | expected_value}}, sut.Encode({{testCase.input.plaintext | string.literal}})); | ||
{{else if testCase.property == "decode"}} | ||
Assert.Equal({{testCase.expected | string.literal}}, sut.Decode({{testCase | decode_arg}})); | ||
{{else if testCase.property == "key"}} | ||
Assert.Matches({{testCase.expected.match | string.literal}}, sut.Key); | ||
{{end}} | ||
} | ||
{{end}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
exercises/practice/variable-length-quantity/.meta/Generator.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using Xunit; | ||
|
||
public class VariableLengthQuantityTests | ||
{ | ||
{{for testCase in testCases}} | ||
[Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] | ||
public void {{testCase.testMethodName}}() | ||
{ | ||
uint[] integers = [ | ||
{{for integer in testCase.input.integers}} | ||
{{integer}}{{if !for.last}},{{end}} | ||
{{end}} | ||
]; | ||
{{if testCase.expected.error}} | ||
Assert.Throws<InvalidOperationException>(() => VariableLengthQuantity.{{testCase.property | string.capitalize}}(integers)); | ||
{{else}} | ||
uint[] expected = [ | ||
{{for expected in testCase.expected}} | ||
{{expected}}{{if !for.last}},{{end}} | ||
{{end}} | ||
]; | ||
Assert.Equal(expected, VariableLengthQuantity.{{testCase.property | string.capitalize}}(integers)); | ||
{{end}} | ||
} | ||
{{end}} | ||
} |
Oops, something went wrong.