Skip to content

Commit

Permalink
rectangles: add generator (#2373)
Browse files Browse the repository at this point in the history
* 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]
  • Loading branch information
ErikSchierboom authored Feb 5, 2025
1 parent 7432aec commit 85c19dd
Show file tree
Hide file tree
Showing 29 changed files with 566 additions and 591 deletions.
12 changes: 12 additions & 0 deletions exercises/practice/book-store/.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 / 100.0 }}m, {{ testedClass }}.{{ test.testedMethod }}({{ test.input.basket }}));
}
{{ end -}}
}
55 changes: 18 additions & 37 deletions exercises/practice/book-store/BookStoreTests.cs
Original file line number Diff line number Diff line change
@@ -1,131 +1,112 @@
using System;
using Xunit;

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<int>();
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]));
}
}
28 changes: 28 additions & 0 deletions exercises/practice/game-of-life/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
}
Loading

0 comments on commit 85c19dd

Please sign in to comment.