|
| 1 | +FUNC_PROTO = """\ |
| 2 | +#include "vendor/unity.h" |
| 3 | +
|
| 4 | +#include <stdint.h> |
| 5 | +
|
| 6 | +extern int64_t expected_minutes_in_oven(void); |
| 7 | +extern int64_t remaining_minutes_in_oven(int64_t actual_minutes_in_oven); |
| 8 | +extern int64_t preparation_time_in_minutes(int64_t number_of_layers); |
| 9 | +extern int64_t elapsed_time_in_minutes(int64_t number_of_layers, int64_t actual_minutes_in_oven); |
| 10 | +""" |
| 11 | + |
| 12 | + |
| 13 | +def extra_cases(): |
| 14 | + return [ |
| 15 | + { |
| 16 | + "task_id": 1, |
| 17 | + "description": "expected", |
| 18 | + "property": "expected_minutes_in_oven", |
| 19 | + "input": None, |
| 20 | + "expected": 40, |
| 21 | + }, |
| 22 | + { |
| 23 | + "task_id": 2, |
| 24 | + "description": "remaining", |
| 25 | + "property": "remaining_minutes_in_oven", |
| 26 | + "input": 25, |
| 27 | + "expected": 15, |
| 28 | + }, |
| 29 | + { |
| 30 | + "task_id": 3, |
| 31 | + "description": "preparation_one", |
| 32 | + "property": "preparation_time_in_minutes", |
| 33 | + "input": 1, |
| 34 | + "expected": 2, |
| 35 | + }, |
| 36 | + { |
| 37 | + "task_id": 3, |
| 38 | + "description": "preparation_many", |
| 39 | + "property": "preparation_time_in_minutes", |
| 40 | + "input": 4, |
| 41 | + "expected": 8, |
| 42 | + }, |
| 43 | + { |
| 44 | + "task_id": 4, |
| 45 | + "description": "elapsed_one", |
| 46 | + "property": "elapsed_time_in_minutes", |
| 47 | + "input": {"number_of_layers": 1, "actual_minutes_in_oven": 30}, |
| 48 | + "expected": 32, |
| 49 | + }, |
| 50 | + { |
| 51 | + "task_id": 4, |
| 52 | + "description": "elapsed_many", |
| 53 | + "property": "elapsed_time_in_minutes", |
| 54 | + "input": {"number_of_layers": 4, "actual_minutes_in_oven": 8}, |
| 55 | + "expected": 16, |
| 56 | + }, |
| 57 | + ] |
| 58 | + |
| 59 | + |
| 60 | +def gen_func_body(prop, inp, expected): |
| 61 | + if prop == "expected_minutes_in_oven": |
| 62 | + return f"TEST_ASSERT_EQUAL_INT64({expected}, {prop}());\n" |
| 63 | + if prop == "remaining_minutes_in_oven" or prop == "preparation_time_in_minutes": |
| 64 | + message = f"The function was called with argument: {inp}." |
| 65 | + return f'TEST_ASSERT_EQUAL_INT64_MESSAGE({expected}, {prop}({inp}), "{message}");\n' |
| 66 | + message = f"The function was called with arguments: {inp['number_of_layers']}, {inp['actual_minutes_in_oven']}." |
| 67 | + return ( |
| 68 | + f"TEST_ASSERT_EQUAL_INT64_MESSAGE({expected}, {prop}" |
| 69 | + f"({inp['number_of_layers']}, {inp['actual_minutes_in_oven']}), " |
| 70 | + f'"{message}");\n' |
| 71 | + ) |
0 commit comments