Skip to content

Commit 13fc520

Browse files
authored
Auto-format .sql files using github.com/sql-formatter-org/sql-formatter - pangram (#164)
[no important files changed]
1 parent 5614f43 commit 13fc520

File tree

4 files changed

+152
-77
lines changed

4 files changed

+152
-77
lines changed
Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
UPDATE pangram
2-
SET result = (
3-
INSTR(LOWER(sentence), 'a')
4-
AND INSTR(LOWER(sentence), 'b')
5-
AND INSTR(LOWER(sentence), 'c')
6-
AND INSTR(LOWER(sentence), 'd')
7-
AND INSTR(LOWER(sentence), 'e')
8-
AND INSTR(LOWER(sentence), 'f')
9-
AND INSTR(LOWER(sentence), 'g')
10-
AND INSTR(LOWER(sentence), 'h')
11-
AND INSTR(LOWER(sentence), 'i')
12-
AND INSTR(LOWER(sentence), 'j')
13-
AND INSTR(LOWER(sentence), 'k')
14-
AND INSTR(LOWER(sentence), 'l')
15-
AND INSTR(LOWER(sentence), 'm')
16-
AND INSTR(LOWER(sentence), 'n')
17-
AND INSTR(LOWER(sentence), 'o')
18-
AND INSTR(LOWER(sentence), 'p')
19-
AND INSTR(LOWER(sentence), 'q')
20-
AND INSTR(LOWER(sentence), 'r')
21-
AND INSTR(LOWER(sentence), 's')
22-
AND INSTR(LOWER(sentence), 't')
23-
AND INSTR(LOWER(sentence), 'u')
24-
AND INSTR(LOWER(sentence), 'v')
25-
AND INSTR(LOWER(sentence), 'w')
26-
AND INSTR(LOWER(sentence), 'x')
27-
AND INSTR(LOWER(sentence), 'y')
28-
AND INSTR(LOWER(sentence), 'z')
29-
);
2+
SET
3+
result = (
4+
INSTR(LOWER(sentence), 'a')
5+
AND INSTR(LOWER(sentence), 'b')
6+
AND INSTR(LOWER(sentence), 'c')
7+
AND INSTR(LOWER(sentence), 'd')
8+
AND INSTR(LOWER(sentence), 'e')
9+
AND INSTR(LOWER(sentence), 'f')
10+
AND INSTR(LOWER(sentence), 'g')
11+
AND INSTR(LOWER(sentence), 'h')
12+
AND INSTR(LOWER(sentence), 'i')
13+
AND INSTR(LOWER(sentence), 'j')
14+
AND INSTR(LOWER(sentence), 'k')
15+
AND INSTR(LOWER(sentence), 'l')
16+
AND INSTR(LOWER(sentence), 'm')
17+
AND INSTR(LOWER(sentence), 'n')
18+
AND INSTR(LOWER(sentence), 'o')
19+
AND INSTR(LOWER(sentence), 'p')
20+
AND INSTR(LOWER(sentence), 'q')
21+
AND INSTR(LOWER(sentence), 'r')
22+
AND INSTR(LOWER(sentence), 's')
23+
AND INSTR(LOWER(sentence), 't')
24+
AND INSTR(LOWER(sentence), 'u')
25+
AND INSTR(LOWER(sentence), 'v')
26+
AND INSTR(LOWER(sentence), 'w')
27+
AND INSTR(LOWER(sentence), 'x')
28+
AND INSTR(LOWER(sentence), 'y')
29+
AND INSTR(LOWER(sentence), 'z')
30+
);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
DROP TABLE IF EXISTS pangram;
2-
CREATE TABLE pangram (
3-
sentence TEXT NOT NULL,
4-
result BOOLEAN
5-
);
2+
3+
CREATE TABLE pangram (sentence TEXT NOT NULL, result BOOLEAN);
64

75
.mode csv
86
.import ./data.csv pangram
9-
10-
UPDATE pangram SET result = NULL;
7+
UPDATE pangram
8+
SET
9+
result = NULL;
Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,80 @@
11
DROP TABLE IF EXISTS tests;
2+
23
CREATE TABLE IF NOT EXISTS tests (
3-
-- uuid and description are taken from the test.toml file
4-
uuid TEXT PRIMARY KEY,
5-
description TEXT NOT NULL,
6-
-- The following section is needed by the online test-runner
7-
status TEXT DEFAULT 'fail',
8-
message TEXT,
9-
output TEXT,
10-
test_code TEXT,
11-
task_id INTEGER DEFAULT NULL,
12-
-- Here are columns for the actual tests
13-
sentence TEXT NOT NULL,
14-
expected BOOLEAN NOT NULL
4+
-- uuid and description are taken from the test.toml file
5+
uuid TEXT PRIMARY KEY,
6+
description TEXT NOT NULL,
7+
-- The following section is needed by the online test-runner
8+
status TEXT DEFAULT 'fail',
9+
message TEXT,
10+
output TEXT,
11+
test_code TEXT,
12+
task_id INTEGER DEFAULT NULL,
13+
-- Here are columns for the actual tests
14+
sentence TEXT NOT NULL,
15+
expected BOOLEAN NOT NULL
1516
);
1617

17-
INSERT INTO tests (uuid, description, sentence, expected)
18-
VALUES
19-
('64f61791-508e-4f5c-83ab-05de042b0149', 'empty sentence', '', false),
20-
('74858f80-4a4d-478b-8a5e-c6477e4e4e84', 'perfect lower case', 'abcdefghijklmnopqrstuvwxyz', true),
21-
('61288860-35ca-4abe-ba08-f5df76ecbdcd', 'only lower case', 'the quick brown fox jumps over the lazy dog', true),
22-
('6564267d-8ac5-4d29-baf2-e7d2e304a743', 'missing the letter ''x''', 'a quick movement of the enemy will jeopardize five gunboats', false),
23-
('c79af1be-d715-4cdb-a5f2-b2fa3e7e0de0', 'missing the letter ''h''', 'five boxing wizards jump quickly at it', false),
24-
('d835ec38-bc8f-48e4-9e36-eb232427b1df', 'with underscores', 'the_quick_brown_fox_jumps_over_the_lazy_dog', true),
25-
('8cc1e080-a178-4494-b4b3-06982c9be2a8', 'with numbers', 'the 1 quick brown fox jumps over the 2 lazy dogs', true),
26-
('bed96b1c-ff95-45b8-9731-fdbdcb6ede9a', 'missing letters replaced by numbers', '7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog', false),
27-
('938bd5d8-ade5-40e2-a2d9-55a338a01030', 'mixed case and punctuation', '"Five quacking Zephyrs jolt my wax bed."', true),
28-
('7138e389-83e4-4c6e-8413-1e40a0076951', 'a-m and A-M are 26 different characters but not a pangram', 'abcdefghijklm ABCDEFGHIJKLM', false);
18+
INSERT INTO
19+
tests (uuid, description, sentence, expected)
20+
VALUES
21+
(
22+
'64f61791-508e-4f5c-83ab-05de042b0149',
23+
'empty sentence',
24+
'',
25+
false
26+
),
27+
(
28+
'74858f80-4a4d-478b-8a5e-c6477e4e4e84',
29+
'perfect lower case',
30+
'abcdefghijklmnopqrstuvwxyz',
31+
true
32+
),
33+
(
34+
'61288860-35ca-4abe-ba08-f5df76ecbdcd',
35+
'only lower case',
36+
'the quick brown fox jumps over the lazy dog',
37+
true
38+
),
39+
(
40+
'6564267d-8ac5-4d29-baf2-e7d2e304a743',
41+
'missing the letter ''x''',
42+
'a quick movement of the enemy will jeopardize five gunboats',
43+
false
44+
),
45+
(
46+
'c79af1be-d715-4cdb-a5f2-b2fa3e7e0de0',
47+
'missing the letter ''h''',
48+
'five boxing wizards jump quickly at it',
49+
false
50+
),
51+
(
52+
'd835ec38-bc8f-48e4-9e36-eb232427b1df',
53+
'with underscores',
54+
'the_quick_brown_fox_jumps_over_the_lazy_dog',
55+
true
56+
),
57+
(
58+
'8cc1e080-a178-4494-b4b3-06982c9be2a8',
59+
'with numbers',
60+
'the 1 quick brown fox jumps over the 2 lazy dogs',
61+
true
62+
),
63+
(
64+
'bed96b1c-ff95-45b8-9731-fdbdcb6ede9a',
65+
'missing letters replaced by numbers',
66+
'7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog',
67+
false
68+
),
69+
(
70+
'938bd5d8-ade5-40e2-a2d9-55a338a01030',
71+
'mixed case and punctuation',
72+
'"Five quacking Zephyrs jolt my wax bed."',
73+
true
74+
),
75+
(
76+
'7138e389-83e4-4c6e-8413-1e40a0076951',
77+
'a-m and A-M are 26 different characters but not a pangram',
78+
'abcdefghijklm ABCDEFGHIJKLM',
79+
false
80+
);
Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,63 @@
11
-- Create database:
22
.read ./create_fixture.sql
3-
43
-- Read user student solution and save any output as markdown in user_output.md:
54
.mode markdown
65
.output user_output.md
76
.read ./pangram.sql
87
.output
9-
108
-- Create a clean testing environment:
119
.read ./create_test_table.sql
12-
1310
-- Comparison of user input and the tests updates the status for each test:
1411
UPDATE tests
15-
SET status = 'pass'
16-
FROM (SELECT sentence, result FROM pangram) AS actual
17-
WHERE (actual.sentence, actual.result) = (tests.sentence, tests.expected);
12+
SET
13+
status = 'pass'
14+
FROM
15+
(
16+
SELECT
17+
sentence,
18+
result
19+
FROM
20+
pangram
21+
) AS actual
22+
WHERE
23+
(actual.sentence, actual.result) = (tests.sentence, tests.expected);
1824

1925
-- Update message for failed tests to give helpful information:
2026
UPDATE tests
21-
SET message = (
22-
'Result for "'
23-
|| actual.sentence
24-
|| '"'
25-
|| ' is <' || COALESCE(actual.result, 'NULL')
26-
|| '> but should be <' || tests.expected || '>'
27-
)
28-
FROM (SELECT sentence, result FROM pangram) AS actual
29-
WHERE actual.sentence = tests.sentence AND tests.status = 'fail';
27+
SET
28+
message = (
29+
'Result for "' || actual.sentence || '"' || ' is <' || COALESCE(actual.result, 'NULL') || '> but should be <' || tests.expected || '>'
30+
)
31+
FROM
32+
(
33+
SELECT
34+
sentence,
35+
result
36+
FROM
37+
pangram
38+
) AS actual
39+
WHERE
40+
actual.sentence = tests.sentence
41+
AND tests.status = 'fail';
3042

3143
-- Save results to ./output.json (needed by the online test-runner)
3244
.mode json
3345
.once './output.json'
34-
SELECT description, status, message, output, test_code, task_id
35-
FROM tests;
46+
SELECT
47+
description,
48+
status,
49+
message,
50+
output,
51+
test_code,
52+
task_id
53+
FROM
54+
tests;
3655

3756
-- Display test results in readable form for the student:
3857
.mode table
39-
SELECT description, status, message
40-
FROM tests;
58+
SELECT
59+
description,
60+
status,
61+
message
62+
FROM
63+
tests;

0 commit comments

Comments
 (0)