|
1 | 1 | -- Setup test table and read in student solution:
|
2 | 2 | .read ./test_setup.sql
|
3 |
| - |
4 | 3 | -- Test cases:
|
5 |
| -INSERT INTO tests (name, uuid, input, expected) |
6 |
| - VALUES |
7 |
| - ('paired square brackets', '81ec11da-38dd-442a-bcf9-3de7754609a5', '[]', 1), |
8 |
| - ('empty string', '287f0167-ac60-4b64-8452-a0aa8f4e5238', '', 1), |
9 |
| - ('unpaired brackets', '6c3615a3-df01-4130-a731-8ef5f5d78dac', '[[', 0), |
10 |
| - ('wrong ordered brackets', '9d414171-9b98-4cac-a4e5-941039a97a77', '}{', 0), |
11 |
| - ('wrong closing bracket', 'f0f97c94-a149-4736-bc61-f2c5148ffb85', '{]', 0), |
12 |
| - ('paired with whitespace', '754468e0-4696-4582-a30e-534d47d69756', '{ }', 1), |
13 |
| - ('partially paired brackets', 'ba84f6ee-8164-434a-9c3e-b02c7f8e8545', '{[])', 0), |
14 |
| - ('simple nested brackets', '3c86c897-5ff3-4a2b-ad9b-47ac3a30651d', '{[]}', 1), |
15 |
| - ('several paired brackets', '2d137f2c-a19e-4993-9830-83967a2d4726', '{}[]', 1), |
16 |
| - ('paired and nested brackets', '2e1f7b56-c137-4c92-9781-958638885a44', '([{}({}[])])', 1), |
17 |
| - ('unopened closing brackets', '84f6233b-e0f7-4077-8966-8085d295c19b', '{[)][]}', 0), |
18 |
| - ('unpaired and nested brackets', '9b18c67d-7595-4982-b2c5-4cb949745d49', '([{])', 0), |
19 |
| - ('paired and wrong nested brackets', 'a0205e34-c2ac-49e6-a88a-899508d7d68e', '[({]})', 0), |
20 |
| - ('paired and wrong nested brackets but innermost are correct', '1d5c093f-fc84-41fb-8c2a-e052f9581602', '[({}])', 0), |
21 |
| - ('paired and incomplete brackets', 'ef47c21b-bcfd-4998-844c-7ad5daad90a8', '{}[', 0), |
22 |
| - ('too many closing brackets', 'a4675a40-a8be-4fc2-bc47-2a282ce6edbe', '[]]', 0), |
23 |
| - ('early unexpected brackets', 'a345a753-d889-4b7e-99ae-34ac85910d1a', ')()', 0), |
24 |
| - ('early mismatched brackets', '21f81d61-1608-465a-b850-baa44c5def83', '{)()', 0), |
25 |
| - ('math expression', '99255f93-261b-4435-a352-02bdecc9bdf2', '(((185 + 223.85) * 15) - 543)/2', 1), |
26 |
| - ('complex latex expression', '8e357d79-f302-469a-8515-2561877256a1', '\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &... x^2 \end{array}\right)', 1); |
| 4 | +INSERT INTO |
| 5 | + tests (name, uuid, input, expected) |
| 6 | +VALUES |
| 7 | + ( |
| 8 | + 'paired square brackets', |
| 9 | + '81ec11da-38dd-442a-bcf9-3de7754609a5', |
| 10 | + '[]', |
| 11 | + 1 |
| 12 | + ), |
| 13 | + ( |
| 14 | + 'empty string', |
| 15 | + '287f0167-ac60-4b64-8452-a0aa8f4e5238', |
| 16 | + '', |
| 17 | + 1 |
| 18 | + ), |
| 19 | + ( |
| 20 | + 'unpaired brackets', |
| 21 | + '6c3615a3-df01-4130-a731-8ef5f5d78dac', |
| 22 | + '[[', |
| 23 | + 0 |
| 24 | + ), |
| 25 | + ( |
| 26 | + 'wrong ordered brackets', |
| 27 | + '9d414171-9b98-4cac-a4e5-941039a97a77', |
| 28 | + '}{', |
| 29 | + 0 |
| 30 | + ), |
| 31 | + ( |
| 32 | + 'wrong closing bracket', |
| 33 | + 'f0f97c94-a149-4736-bc61-f2c5148ffb85', |
| 34 | + '{]', |
| 35 | + 0 |
| 36 | + ), |
| 37 | + ( |
| 38 | + 'paired with whitespace', |
| 39 | + '754468e0-4696-4582-a30e-534d47d69756', |
| 40 | + '{ }', |
| 41 | + 1 |
| 42 | + ), |
| 43 | + ( |
| 44 | + 'partially paired brackets', |
| 45 | + 'ba84f6ee-8164-434a-9c3e-b02c7f8e8545', |
| 46 | + '{[])', |
| 47 | + 0 |
| 48 | + ), |
| 49 | + ( |
| 50 | + 'simple nested brackets', |
| 51 | + '3c86c897-5ff3-4a2b-ad9b-47ac3a30651d', |
| 52 | + '{[]}', |
| 53 | + 1 |
| 54 | + ), |
| 55 | + ( |
| 56 | + 'several paired brackets', |
| 57 | + '2d137f2c-a19e-4993-9830-83967a2d4726', |
| 58 | + '{}[]', |
| 59 | + 1 |
| 60 | + ), |
| 61 | + ( |
| 62 | + 'paired and nested brackets', |
| 63 | + '2e1f7b56-c137-4c92-9781-958638885a44', |
| 64 | + '([{}({}[])])', |
| 65 | + 1 |
| 66 | + ), |
| 67 | + ( |
| 68 | + 'unopened closing brackets', |
| 69 | + '84f6233b-e0f7-4077-8966-8085d295c19b', |
| 70 | + '{[)][]}', |
| 71 | + 0 |
| 72 | + ), |
| 73 | + ( |
| 74 | + 'unpaired and nested brackets', |
| 75 | + '9b18c67d-7595-4982-b2c5-4cb949745d49', |
| 76 | + '([{])', |
| 77 | + 0 |
| 78 | + ), |
| 79 | + ( |
| 80 | + 'paired and wrong nested brackets', |
| 81 | + 'a0205e34-c2ac-49e6-a88a-899508d7d68e', |
| 82 | + '[({]})', |
| 83 | + 0 |
| 84 | + ), |
| 85 | + ( |
| 86 | + 'paired and wrong nested brackets but innermost are correct', |
| 87 | + '1d5c093f-fc84-41fb-8c2a-e052f9581602', |
| 88 | + '[({}])', |
| 89 | + 0 |
| 90 | + ), |
| 91 | + ( |
| 92 | + 'paired and incomplete brackets', |
| 93 | + 'ef47c21b-bcfd-4998-844c-7ad5daad90a8', |
| 94 | + '{}[', |
| 95 | + 0 |
| 96 | + ), |
| 97 | + ( |
| 98 | + 'too many closing brackets', |
| 99 | + 'a4675a40-a8be-4fc2-bc47-2a282ce6edbe', |
| 100 | + '[]]', |
| 101 | + 0 |
| 102 | + ), |
| 103 | + ( |
| 104 | + 'early unexpected brackets', |
| 105 | + 'a345a753-d889-4b7e-99ae-34ac85910d1a', |
| 106 | + ')()', |
| 107 | + 0 |
| 108 | + ), |
| 109 | + ( |
| 110 | + 'early mismatched brackets', |
| 111 | + '21f81d61-1608-465a-b850-baa44c5def83', |
| 112 | + '{)()', |
| 113 | + 0 |
| 114 | + ), |
| 115 | + ( |
| 116 | + 'math expression', |
| 117 | + '99255f93-261b-4435-a352-02bdecc9bdf2', |
| 118 | + '(((185 + 223.85) * 15) - 543)/2', |
| 119 | + 1 |
| 120 | + ), |
| 121 | + ( |
| 122 | + 'complex latex expression', |
| 123 | + '8e357d79-f302-469a-8515-2561877256a1', |
| 124 | + '\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &... x^2 \end{array}\right)', |
| 125 | + 1 |
| 126 | + ); |
27 | 127 |
|
28 | 128 | -- Comparison of user input and the tests updates the status for each test:
|
29 | 129 | UPDATE tests
|
30 |
| -SET status = 'pass' |
31 |
| -FROM (SELECT input, result FROM "matching-brackets") AS actual |
32 |
| -WHERE (actual.input, actual.result) = (tests.input, tests.expected); |
| 130 | +SET |
| 131 | + status = 'pass' |
| 132 | +FROM |
| 133 | + ( |
| 134 | + SELECT |
| 135 | + input, |
| 136 | + result |
| 137 | + FROM |
| 138 | + "matching-brackets" |
| 139 | + ) AS actual |
| 140 | +WHERE |
| 141 | + (actual.input, actual.result) = (tests.input, tests.expected); |
33 | 142 |
|
34 | 143 | -- Write results and debug info:
|
35 | 144 | .read ./test_reporter.sql
|
0 commit comments