|
1 | 1 | -- Setup test table and read in student solution:
|
2 | 2 | .read ./test_setup.sql
|
3 |
| - |
4 | 3 | -- Test cases:
|
5 | 4 | -- Note: the strings below _may_ contain literal tab, newline, or carriage returns.
|
6 |
| -INSERT INTO tests (name, uuid, |
7 |
| - value, expected) |
8 |
| - VALUES |
9 |
| - ('single digit strings can not be valid', '792a7082-feb7-48c7-b88b-bbfec160865e', |
10 |
| - '1', false), |
11 |
| - |
12 |
| - ('a single zero is invalid', '698a7924-64d4-4d89-8daa-32e1aadc271e', |
13 |
| - '0', false), |
14 |
| - |
15 |
| - ('a simple valid SIN that remains valid if reversed', '73c2f62b-9b10-4c9f-9a04-83cee7367965', |
16 |
| - '059', true), |
17 |
| - |
18 |
| - ('a simple valid SIN that becomes invalid if reversed', '9369092e-b095-439f-948d-498bd076be11', |
19 |
| - '59', true), |
20 |
| - |
21 |
| - ('a valid Canadian SIN', '8f9f2350-1faf-4008-ba84-85cbb93ffeca', |
22 |
| - '055 444 285', true), |
23 |
| - |
24 |
| - ('invalid Canadian SIN', '1cdcf269-6560-44fc-91f6-5819a7548737', |
25 |
| - '055 444 286', false), |
26 |
| - |
27 |
| - ('invalid credit card', '656c48c1-34e8-4e60-9a5a-aad8a367810a', |
28 |
| - '8273 1232 7352 0569', false), |
29 |
| - |
30 |
| - ('invalid long number with an even remainder', '20e67fad-2121-43ed-99a8-14b5b856adb9', |
31 |
| - '1 2345 6789 1234 5678 9012', false), |
32 |
| - |
33 |
| - ('invalid long number with a remainder divisible by 5', '7e7c9fc1-d994-457c-811e-d390d52fba5e', |
34 |
| - '1 2345 6789 1234 5678 9013', false), |
35 |
| - |
36 |
| - ('valid number with an even number of digits', 'ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa', |
37 |
| - '095 245 88', true), |
38 |
| - |
39 |
| - ('valid number with an odd number of spaces', 'ef081c06-a41f-4761-8492-385e13c8202d', |
40 |
| - '234 567 891 234', true), |
41 |
| - |
42 |
| - ('valid strings with a non-digit added at the end become invalid', 'bef66f64-6100-4cbb-8f94-4c9713c5e5b2', |
43 |
| - '059a', false), |
44 |
| - |
45 |
| - ('valid strings with punctuation included become invalid', '2177e225-9ce7-40f6-b55d-fa420e62938e', |
46 |
| - '055-444-285', false), |
47 |
| - |
48 |
| - ('valid strings with symbols included become invalid', 'ebf04f27-9698-45e1-9afe-7e0851d0fe8d', |
49 |
| - '055# 444$ 285', false), |
50 |
| - |
51 |
| - ('single zero with space is invalid', '08195c5e-ce7f-422c-a5eb-3e45fece68ba', |
52 |
| - ' 0', false), |
53 |
| - |
54 |
| - ('more than a single zero is valid', '12e63a3c-f866-4a79-8c14-b359fc386091', |
55 |
| - '0000 0', true), |
56 |
| - |
57 |
| - ('input digit 9 is correctly converted to output digit 9', 'ab56fa80-5de8-4735-8a4a-14dae588663e', |
58 |
| - '091', true), |
59 |
| - |
60 |
| - ('very long input is valid', 'b9887ee8-8337-46c5-bc45-3bcab51bc36f', |
61 |
| - '9999999999 9999999999 9999999999 9999999999', true), |
62 |
| - |
63 |
| - ('valid luhn with an odd number of digits and non zero first digit', '8a7c0e24-85ea-4154-9cf1-c2db90eabc08', |
64 |
| - '109', true), |
65 |
| - |
66 |
| - ('using ascii value for non-doubled non-digit isn''t allowed', '39a06a5a-5bad-4e0f-b215-b042d46209b1', |
67 |
| - '055b 444 285', false), |
68 |
| - |
69 |
| - ('using ascii value for doubled non-digit isn''t allowed', 'f94cf191-a62f-4868-bc72-7253114aa157', |
70 |
| - ':9', false), |
71 |
| - |
72 |
| - ('non-numeric, non-space char in the middle with a sum that''s divisible by 10 isn''t allowed', '8b72ad26-c8be-49a2-b99c-bcc3bf631b33', |
73 |
| - '59%59', false); |
| 5 | +INSERT INTO |
| 6 | + tests (name, uuid, value, expected) |
| 7 | +VALUES |
| 8 | + ( |
| 9 | + 'single digit strings can not be valid', |
| 10 | + '792a7082-feb7-48c7-b88b-bbfec160865e', |
| 11 | + '1', |
| 12 | + false |
| 13 | + ), |
| 14 | + ( |
| 15 | + 'a single zero is invalid', |
| 16 | + '698a7924-64d4-4d89-8daa-32e1aadc271e', |
| 17 | + '0', |
| 18 | + false |
| 19 | + ), |
| 20 | + ( |
| 21 | + 'a simple valid SIN that remains valid if reversed', |
| 22 | + '73c2f62b-9b10-4c9f-9a04-83cee7367965', |
| 23 | + '059', |
| 24 | + true |
| 25 | + ), |
| 26 | + ( |
| 27 | + 'a simple valid SIN that becomes invalid if reversed', |
| 28 | + '9369092e-b095-439f-948d-498bd076be11', |
| 29 | + '59', |
| 30 | + true |
| 31 | + ), |
| 32 | + ( |
| 33 | + 'a valid Canadian SIN', |
| 34 | + '8f9f2350-1faf-4008-ba84-85cbb93ffeca', |
| 35 | + '055 444 285', |
| 36 | + true |
| 37 | + ), |
| 38 | + ( |
| 39 | + 'invalid Canadian SIN', |
| 40 | + '1cdcf269-6560-44fc-91f6-5819a7548737', |
| 41 | + '055 444 286', |
| 42 | + false |
| 43 | + ), |
| 44 | + ( |
| 45 | + 'invalid credit card', |
| 46 | + '656c48c1-34e8-4e60-9a5a-aad8a367810a', |
| 47 | + '8273 1232 7352 0569', |
| 48 | + false |
| 49 | + ), |
| 50 | + ( |
| 51 | + 'invalid long number with an even remainder', |
| 52 | + '20e67fad-2121-43ed-99a8-14b5b856adb9', |
| 53 | + '1 2345 6789 1234 5678 9012', |
| 54 | + false |
| 55 | + ), |
| 56 | + ( |
| 57 | + 'invalid long number with a remainder divisible by 5', |
| 58 | + '7e7c9fc1-d994-457c-811e-d390d52fba5e', |
| 59 | + '1 2345 6789 1234 5678 9013', |
| 60 | + false |
| 61 | + ), |
| 62 | + ( |
| 63 | + 'valid number with an even number of digits', |
| 64 | + 'ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa', |
| 65 | + '095 245 88', |
| 66 | + true |
| 67 | + ), |
| 68 | + ( |
| 69 | + 'valid number with an odd number of spaces', |
| 70 | + 'ef081c06-a41f-4761-8492-385e13c8202d', |
| 71 | + '234 567 891 234', |
| 72 | + true |
| 73 | + ), |
| 74 | + ( |
| 75 | + 'valid strings with a non-digit added at the end become invalid', |
| 76 | + 'bef66f64-6100-4cbb-8f94-4c9713c5e5b2', |
| 77 | + '059a', |
| 78 | + false |
| 79 | + ), |
| 80 | + ( |
| 81 | + 'valid strings with punctuation included become invalid', |
| 82 | + '2177e225-9ce7-40f6-b55d-fa420e62938e', |
| 83 | + '055-444-285', |
| 84 | + false |
| 85 | + ), |
| 86 | + ( |
| 87 | + 'valid strings with symbols included become invalid', |
| 88 | + 'ebf04f27-9698-45e1-9afe-7e0851d0fe8d', |
| 89 | + '055# 444$ 285', |
| 90 | + false |
| 91 | + ), |
| 92 | + ( |
| 93 | + 'single zero with space is invalid', |
| 94 | + '08195c5e-ce7f-422c-a5eb-3e45fece68ba', |
| 95 | + ' 0', |
| 96 | + false |
| 97 | + ), |
| 98 | + ( |
| 99 | + 'more than a single zero is valid', |
| 100 | + '12e63a3c-f866-4a79-8c14-b359fc386091', |
| 101 | + '0000 0', |
| 102 | + true |
| 103 | + ), |
| 104 | + ( |
| 105 | + 'input digit 9 is correctly converted to output digit 9', |
| 106 | + 'ab56fa80-5de8-4735-8a4a-14dae588663e', |
| 107 | + '091', |
| 108 | + true |
| 109 | + ), |
| 110 | + ( |
| 111 | + 'very long input is valid', |
| 112 | + 'b9887ee8-8337-46c5-bc45-3bcab51bc36f', |
| 113 | + '9999999999 9999999999 9999999999 9999999999', |
| 114 | + true |
| 115 | + ), |
| 116 | + ( |
| 117 | + 'valid luhn with an odd number of digits and non zero first digit', |
| 118 | + '8a7c0e24-85ea-4154-9cf1-c2db90eabc08', |
| 119 | + '109', |
| 120 | + true |
| 121 | + ), |
| 122 | + ( |
| 123 | + 'using ascii value for non-doubled non-digit isn''t allowed', |
| 124 | + '39a06a5a-5bad-4e0f-b215-b042d46209b1', |
| 125 | + '055b 444 285', |
| 126 | + false |
| 127 | + ), |
| 128 | + ( |
| 129 | + 'using ascii value for doubled non-digit isn''t allowed', |
| 130 | + 'f94cf191-a62f-4868-bc72-7253114aa157', |
| 131 | + ':9', |
| 132 | + false |
| 133 | + ), |
| 134 | + ( |
| 135 | + 'non-numeric, non-space char in the middle with a sum that''s divisible by 10 isn''t allowed', |
| 136 | + '8b72ad26-c8be-49a2-b99c-bcc3bf631b33', |
| 137 | + '59%59', |
| 138 | + false |
| 139 | + ); |
74 | 140 |
|
75 | 141 | -- Comparison of user input and the tests updates the status for each test:
|
76 | 142 | UPDATE tests
|
77 |
| -SET status = 'pass' |
78 |
| -FROM (SELECT value, result FROM luhn) AS actual |
79 |
| -WHERE (actual.value, actual.result) = (tests.value, tests.expected); |
| 143 | +SET |
| 144 | + status = 'pass' |
| 145 | +FROM |
| 146 | + ( |
| 147 | + SELECT |
| 148 | + value, |
| 149 | + result |
| 150 | + FROM |
| 151 | + luhn |
| 152 | + ) AS actual |
| 153 | +WHERE |
| 154 | + (actual.value, actual.result) = (tests.value, tests.expected); |
80 | 155 |
|
81 | 156 | -- Write results and debug info:
|
82 | 157 | .read ./test_reporter.sql
|
0 commit comments