|
| 1 | +FUNC_PROTO = """\ |
| 2 | +#include "vendor/unity.h" |
| 3 | +
|
| 4 | +#include <stdint.h> |
| 5 | +
|
| 6 | +extern uint32_t get_box_weight(uint16_t count_first, uint16_t weight_first, uint16_t count_second, uint16_t weight_second); |
| 7 | +extern uint8_t max_number_of_boxes(uint8_t box_height); |
| 8 | +extern int32_t items_to_be_moved(uint32_t remaining_items, uint32_t items_in_box); |
| 9 | +extern int64_t calculate_payment(uint64_t upfront_payment, uint32_t boxes_moved, uint32_t num_trips, uint32_t lost_items, |
| 10 | + uint64_t value_of_each_lost_item, uint8_t num_of_workers); |
| 11 | +""" |
| 12 | + |
| 13 | + |
| 14 | +def extra_cases(): |
| 15 | + return [ |
| 16 | + { |
| 17 | + "task_id": 1, |
| 18 | + "description": "weight_of_small_box", |
| 19 | + "property": "get_box_weight", |
| 20 | + "input": { |
| 21 | + "count_first": 30, |
| 22 | + "weight_first": 40, |
| 23 | + "count_second": 50, |
| 24 | + "weight_second": 20, |
| 25 | + }, |
| 26 | + "expected": 2700, |
| 27 | + }, |
| 28 | + { |
| 29 | + "task_id": 1, |
| 30 | + "description": "weight_of_medium_box", |
| 31 | + "property": "get_box_weight", |
| 32 | + "input": { |
| 33 | + "count_first": 15, |
| 34 | + "weight_first": 242, |
| 35 | + "count_second": 1100, |
| 36 | + "weight_second": 2, |
| 37 | + }, |
| 38 | + "expected": 6330, |
| 39 | + }, |
| 40 | + { |
| 41 | + "task_id": 1, |
| 42 | + "description": "weight_of_large_box", |
| 43 | + "property": "get_box_weight", |
| 44 | + "input": { |
| 45 | + "count_first": 12, |
| 46 | + "weight_first": 5600, |
| 47 | + "count_second": 133, |
| 48 | + "weight_second": 521, |
| 49 | + }, |
| 50 | + "expected": 136993, |
| 51 | + }, |
| 52 | + { |
| 53 | + "task_id": 2, |
| 54 | + "description": "max_stack_for_small_box", |
| 55 | + "property": "max_number_of_boxes", |
| 56 | + "input": 30, |
| 57 | + "expected": 10, |
| 58 | + }, |
| 59 | + { |
| 60 | + "task_id": 2, |
| 61 | + "description": "max_stack_for_medium_box", |
| 62 | + "property": "max_number_of_boxes", |
| 63 | + "input": 85, |
| 64 | + "expected": 3, |
| 65 | + }, |
| 66 | + { |
| 67 | + "task_id": 2, |
| 68 | + "description": "max_stack_for_large_box", |
| 69 | + "property": "max_number_of_boxes", |
| 70 | + "input": 182, |
| 71 | + "expected": 1, |
| 72 | + }, |
| 73 | + { |
| 74 | + "task_id": 3, |
| 75 | + "description": "items_remaining_for_first_product", |
| 76 | + "property": "items_to_be_moved", |
| 77 | + "input": {"remaining_items": 76532, "items_in_box": 120}, |
| 78 | + "expected": 76412, |
| 79 | + }, |
| 80 | + { |
| 81 | + "task_id": 3, |
| 82 | + "description": "items_remaining_for_second_product", |
| 83 | + "property": "items_to_be_moved", |
| 84 | + "input": {"remaining_items": 1234876, "items_in_box": 666986}, |
| 85 | + "expected": 567890, |
| 86 | + }, |
| 87 | + { |
| 88 | + "task_id": 3, |
| 89 | + "description": "items_remaining_for_third_product", |
| 90 | + "property": "items_to_be_moved", |
| 91 | + "input": {"remaining_items": 217, "items_in_box": 217}, |
| 92 | + "expected": 0, |
| 93 | + }, |
| 94 | + { |
| 95 | + "task_id": 3, |
| 96 | + "description": "items_remaining_accounting_error", |
| 97 | + "property": "items_to_be_moved", |
| 98 | + "input": {"remaining_items": 156, "items_in_box": 723}, |
| 99 | + "expected": -567, |
| 100 | + }, |
| 101 | + { |
| 102 | + "task_id": 4, |
| 103 | + "description": "payment_few_lost_items", |
| 104 | + "property": "calculate_payment", |
| 105 | + "input": { |
| 106 | + "upfront_payment": 2000, |
| 107 | + "boxes_moved": 1000, |
| 108 | + "num_trips": 5, |
| 109 | + "lost_items": 21, |
| 110 | + "value_of_each_lost_item": 2, |
| 111 | + "num_of_workers": 1, |
| 112 | + }, |
| 113 | + "expected": 2029, |
| 114 | + }, |
| 115 | + { |
| 116 | + "task_id": 4, |
| 117 | + "description": "no_payment_too_many_lost_items", |
| 118 | + "property": "calculate_payment", |
| 119 | + "input": { |
| 120 | + "upfront_payment": 2000, |
| 121 | + "boxes_moved": 598, |
| 122 | + "num_trips": 2, |
| 123 | + "lost_items": 120, |
| 124 | + "value_of_each_lost_item": 45, |
| 125 | + "num_of_workers": 4, |
| 126 | + }, |
| 127 | + "expected": -794, |
| 128 | + }, |
| 129 | + { |
| 130 | + "task_id": 4, |
| 131 | + "description": "payment_many_boxes", |
| 132 | + "property": "calculate_payment", |
| 133 | + "input": { |
| 134 | + "upfront_payment": 57412, |
| 135 | + "boxes_moved": 163214, |
| 136 | + "num_trips": 183, |
| 137 | + "lost_items": 1931, |
| 138 | + "value_of_each_lost_item": 185, |
| 139 | + "num_of_workers": 216, |
| 140 | + }, |
| 141 | + "expected": 2123, |
| 142 | + }, |
| 143 | + { |
| 144 | + "task_id": 4, |
| 145 | + "description": "no_payment_everything_upfront", |
| 146 | + "property": "calculate_payment", |
| 147 | + "input": { |
| 148 | + "upfront_payment": 22975, |
| 149 | + "boxes_moved": 4523, |
| 150 | + "num_trips": 6, |
| 151 | + "lost_items": 120, |
| 152 | + "value_of_each_lost_item": 8, |
| 153 | + "num_of_workers": 5, |
| 154 | + }, |
| 155 | + "expected": 0, |
| 156 | + }, |
| 157 | + ] |
| 158 | + |
| 159 | + |
| 160 | +def unroll_args(args): |
| 161 | + if isinstance(args, (int, float)): |
| 162 | + return str(args) |
| 163 | + return str([*args.values()]).replace("[", "").replace("]", "") |
| 164 | + |
| 165 | + |
| 166 | +def gen_func_body(prop, inp, expected): |
| 167 | + plural = "s" if isinstance(inp, dict) and len(inp) > 1 else "" |
| 168 | + message = f"The function was called with argument{plural}: {unroll_args(inp)}." |
| 169 | + if prop == "get_box_weight": |
| 170 | + return ( |
| 171 | + f"TEST_ASSERT_EQUAL_UINT32_MESSAGE({expected}, {prop}" |
| 172 | + f"({inp['count_first']}, {inp['weight_first']}, {inp['count_second']}, {inp['weight_second']}), " |
| 173 | + f'"{message}");\n' |
| 174 | + ) |
| 175 | + if prop == "max_number_of_boxes": |
| 176 | + return f'TEST_ASSERT_EQUAL_UINT8_MESSAGE({expected}, {prop}({inp}), "{message}");\n' |
| 177 | + if prop == "items_to_be_moved": |
| 178 | + return ( |
| 179 | + f"TEST_ASSERT_EQUAL_INT64_MESSAGE({expected}, {prop}" |
| 180 | + f"({inp['remaining_items']}, {inp['items_in_box']}), " |
| 181 | + f'"{message}");\n' |
| 182 | + ) |
| 183 | + return ( |
| 184 | + f"TEST_ASSERT_EQUAL_INT64_MESSAGE({expected}, {prop}" |
| 185 | + f"({inp['upfront_payment']}, {inp['boxes_moved']}, {inp['num_trips']}, " |
| 186 | + f"{inp['lost_items']}, {inp['value_of_each_lost_item']}, {inp['num_of_workers']}), " |
| 187 | + f'"{message}");\n' |
| 188 | + ) |
0 commit comments