Skip to content

Commit

Permalink
[not for merging] generate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode committed Feb 24, 2025
1 parent 208585e commit c81b6d8
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 78 deletions.
602 changes: 602 additions & 0 deletions bin/generate.py

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions exercises/practice/atbash-cipher/source/atbash_cipher.d
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
module atbash_cipher;

pure string encode(immutable string phrase)
{
// implement this function
}

pure string decode(immutable string phrase)
{
// implement this function
}

unittest
{
immutable int allTestsEnabled = 0;
Expand Down
14 changes: 3 additions & 11 deletions exercises/practice/book-store/source/book_store.d
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module book_store;

pure int total(immutable int[] basket)
{
// implement this function
}

unittest
{
immutable int allTestsEnabled = 0;
Expand Down Expand Up @@ -101,11 +96,9 @@ unittest
assert(total(basket) == 10240);
}

// Check that groups of four are created properly even when there are
// more groups of three than groups of five
// Check that groups of four are created properly even when there are more groups of three than groups of five
{
immutable int[] basket = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 4, 4, 5, 5];
immutable int[] basket = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5];
assert(total(basket) == 14560);
}

Expand All @@ -115,8 +108,7 @@ unittest
assert(total(basket) == 3360);
}

// One group of one and two plus three groups of four is cheaper than
// one group of each size
// One group of one and two plus three groups of four is cheaper than one group of each size
{
immutable int[] basket = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5];
assert(total(basket) == 10000);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
module collatz_conjecture;

pure int steps(immutable int number)
{
// implement this function
}

unittest
{
import std.exception : assertThrown;

const int allTestsEnabled = 0;
immutable int allTestsEnabled = 0;

// Zero steps for one
assert(steps(1) == 0);
Expand Down
5 changes: 0 additions & 5 deletions exercises/practice/isbn-verifier/source/isbn_verifier.d
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module isbn_verifier;

pure bool isValid(immutable string isbn)
{
// implement this function
}

unittest
{
immutable int allTestsEnabled = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ unittest
assert(plants(diagram, "Bob") == expected);
}

// Partial garden-multiple students for the same garden with three
// students-second student's garden
// Partial garden-multiple students for the same garden with three students-second student's garden
{
immutable string diagram = "VVCCGG\nVVCCGG";
string[4] expected = [
Expand All @@ -60,8 +59,7 @@ unittest
assert(plants(diagram, "Bob") == expected);
}

// Partial garden-multiple students for the same garden with three
// students-third student's garden
// Partial garden-multiple students for the same garden with three students-third student's garden
{
immutable string diagram = "VVCCGG\nVVCCGG";
string[4] expected = [
Expand Down
1 change: 1 addition & 0 deletions exercises/practice/knapsack/source/knapsack.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ uint maximumValue(Item[] items, uint maximumWeight)
{
// implement this function
}

unittest
{
immutable int allTestsEnabled = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module largest_series_product;

pure ulong largestProduct(immutable string digits, int span)
{
// implement this function
}

unittest
{
import std.exception : assertThrown;
Expand Down
5 changes: 0 additions & 5 deletions exercises/practice/micro-blog/source/micro_blog.d
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module micro_blog;

pure string truncate(immutable string phrase)
{
// implement this function
}

unittest
{
immutable int allTestsEnabled = 0;
Expand Down
7 changes: 0 additions & 7 deletions exercises/practice/phone-number/source/phone_number.d
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
module phone_number;

pure string clean(immutable string phrase)
{
// implement this function
}

unittest
{
import std.exception : assertThrown;

immutable int allTestsEnabled = 0;

// Cleans the number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pure State gamestate(immutable string[] board)

unittest
{
import std.algorithm.comparison : equal;
import std.exception : assertThrown;

immutable int allTestsEnabled = 0;
Expand All @@ -24,7 +25,7 @@ unittest
"X ",
"X ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

static if (allTestsEnabled)
Expand All @@ -36,7 +37,7 @@ unittest
" X ",
" X ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via right column victory
Expand All @@ -46,7 +47,7 @@ unittest
" X",
" X",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via left column victory
Expand All @@ -56,7 +57,7 @@ unittest
"OX ",
"O ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via middle column victory
Expand All @@ -66,7 +67,7 @@ unittest
" OX",
" O ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via right column victory
Expand All @@ -76,7 +77,7 @@ unittest
" XO",
" O",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via top row victory
Expand All @@ -86,7 +87,7 @@ unittest
"XOO",
"O ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via middle row victory
Expand All @@ -96,7 +97,7 @@ unittest
"XXX",
" O ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via bottom row victory
Expand All @@ -106,7 +107,7 @@ unittest
"O X",
"XXX",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via top row victory
Expand All @@ -116,7 +117,7 @@ unittest
"XXO",
"XX ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via middle row victory
Expand All @@ -126,7 +127,7 @@ unittest
"OOO",
"X ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via bottom row victory
Expand All @@ -136,7 +137,7 @@ unittest
" XX",
"OOO",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via falling diagonal victory
Expand All @@ -146,7 +147,7 @@ unittest
" X ",
" X",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via rising diagonal victory
Expand All @@ -156,7 +157,7 @@ unittest
"OX ",
"X ",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via falling diagonal victory
Expand All @@ -166,7 +167,7 @@ unittest
"OOX",
"X O",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where O won via rising diagonal victory
Expand All @@ -176,7 +177,7 @@ unittest
" OX",
"OXX",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via a row and a column victory
Expand All @@ -186,7 +187,7 @@ unittest
"XOO",
"XOO",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Won games-Finished game where X won via two diagonal victories
Expand All @@ -196,7 +197,7 @@ unittest
"OXO",
"XOX",
];
assert(gamestate(board) == State.win);
assert(equal(gamestate(board), State.win));
}

// Drawn games-Draw
Expand All @@ -206,7 +207,7 @@ unittest
"XXO",
"OXO",
];
assert(gamestate(board) == State.draw);
assert(equal(gamestate(board), State.draw));
}

// Drawn games-Another draw
Expand All @@ -216,7 +217,7 @@ unittest
"OXX",
"XOO",
];
assert(gamestate(board) == State.draw);
assert(equal(gamestate(board), State.draw));
}

// Ongoing games-Ongoing game: one move in
Expand All @@ -226,7 +227,7 @@ unittest
"X ",
" ",
];
assert(gamestate(board) == State.ongoing);
assert(equal(gamestate(board), State.ongoing));
}

// Ongoing games-Ongoing game: two moves in
Expand All @@ -236,7 +237,7 @@ unittest
" X ",
" ",
];
assert(gamestate(board) == State.ongoing);
assert(equal(gamestate(board), State.ongoing));
}

// Ongoing games-Ongoing game: five moves in
Expand All @@ -246,7 +247,7 @@ unittest
" XO",
"OX ",
];
assert(gamestate(board) == State.ongoing);
assert(equal(gamestate(board), State.ongoing));
}

// Invalid boards-Invalid board: X went twice
Expand Down

0 comments on commit c81b6d8

Please sign in to comment.