Skip to content

Commit e7cfe89

Browse files
authored
add generator for eliuds-eggs, queen-attack and square-root (#466)
1 parent 4508593 commit e7cfe89

6 files changed

Lines changed: 78 additions & 6 deletions

File tree

exercises/practice/eliuds-eggs/eliuds_eggs_test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Version: 1.0.0
2-
31
#include "vendor/unity.h"
42

53
extern int egg_count(int number);
@@ -29,11 +27,17 @@ void test_13_eggs(void) {
2927
TEST_ASSERT_EQUAL_INT(13, egg_count(2000000000));
3028
}
3129

30+
void test_negative_number(void) {
31+
TEST_IGNORE();
32+
TEST_ASSERT_EQUAL_INT(32, egg_count(-1));
33+
}
34+
3235
int main(void) {
3336
UNITY_BEGIN();
3437
RUN_TEST(test_0_eggs);
3538
RUN_TEST(test_1_egg);
3639
RUN_TEST(test_4_eggs);
3740
RUN_TEST(test_13_eggs);
41+
RUN_TEST(test_negative_number);
3842
return UNITY_END();
3943
}

exercises/practice/queen-attack/queen_attack_test.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Version: 1.0.0
2-
31
#include "vendor/unity.h"
42

53
// Returns 1 if queen can be created, otherwise 0.

exercises/practice/square-root/square_root_test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Version: 1.0.0
2-
31
#include "vendor/unity.h"
42

53
extern int square_root(int radicand);
@@ -39,6 +37,11 @@ void test_root_of_65025(void) {
3937
TEST_ASSERT_EQUAL_INT(255, square_root(65025));
4038
}
4139

40+
void test_max_perfect_square_in_range(void) {
41+
TEST_IGNORE();
42+
TEST_ASSERT_EQUAL_INT(46340, square_root(2147395600));
43+
}
44+
4245
int main(void) {
4346
UNITY_BEGIN();
4447
RUN_TEST(test_root_of_1);
@@ -47,5 +50,6 @@ int main(void) {
4750
RUN_TEST(test_root_of_81);
4851
RUN_TEST(test_root_of_196);
4952
RUN_TEST(test_root_of_65025);
53+
RUN_TEST(test_max_perfect_square_in_range);
5054
return UNITY_END();
5155
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FUNC_PROTO = """\
2+
#include "vendor/unity.h"
3+
4+
extern int egg_count(int number);
5+
"""
6+
7+
8+
def extra_cases():
9+
return [
10+
{
11+
"description": "negative number",
12+
"property": "eggCount",
13+
"input": {
14+
"number": -1,
15+
},
16+
"expected": 32,
17+
},
18+
]
19+
20+
21+
def gen_func_body(prop, inp, expected):
22+
return f"TEST_ASSERT_EQUAL_INT({expected}, {prop}({inp['number']}));"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FUNC_PROTO = """\
2+
#include "vendor/unity.h"
3+
4+
// Returns 1 if queen can be created, otherwise 0.
5+
extern int can_create(int row, int column);
6+
7+
// Returns 1 if queens attack, otherwise 0.
8+
extern int can_attack(int white_row, int white_column, int black_row, int black_column);
9+
"""
10+
11+
12+
def gen_func_body(prop, inp, expected):
13+
if prop == "create":
14+
pos = inp["queen"]["position"]
15+
assertion = (
16+
"TEST_ASSERT_FALSE" if isinstance(expected, dict) else "TEST_ASSERT_TRUE"
17+
)
18+
return f"{assertion}(can_create({pos['row']}, {pos['column']}));"
19+
white = inp["white_queen"]["position"]
20+
black = inp["black_queen"]["position"]
21+
assertion = "TEST_ASSERT_TRUE" if expected else "TEST_ASSERT_FALSE"
22+
return f"{assertion}(can_attack({white['row']}, {white['column']}, {black['row']}, {black['column']}));"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FUNC_PROTO = """\
2+
#include "vendor/unity.h"
3+
4+
extern int square_root(int radicand);
5+
"""
6+
7+
8+
def extra_cases():
9+
return [
10+
{
11+
"description": "max perfect square in range",
12+
"property": "squareRoot",
13+
"input": {
14+
"radicand": 2147395600,
15+
},
16+
"expected": 46340,
17+
},
18+
]
19+
20+
21+
def gen_func_body(prop, inp, expected):
22+
return f"TEST_ASSERT_EQUAL_INT({expected}, {prop}({inp['radicand']}));"

0 commit comments

Comments
 (0)