Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions exercises/practice/rna-transcription/.meta/example.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
UPDATE "rna-transcription"
SET result = REPLACE(
REPLACE(
SET
result = REPLACE(
REPLACE(
REPLACE(
REPLACE(dna, 'A', 'U'),
'T', 'A'
REPLACE(REPLACE(dna, 'A', 'U'), 'T', 'A'),
'C',
'Z'
),
'C', 'Z'
'G',
'C'
),
'G', 'C'
),
'Z', 'G'
);
'Z',
'G'
);
6 changes: 2 additions & 4 deletions exercises/practice/rna-transcription/create_fixture.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
DROP TABLE IF EXISTS "rna-transcription";
CREATE TABLE "rna-transcription" (
"dna" TEXT,
"result" TEXT
);

CREATE TABLE "rna-transcription" ("dna" TEXT, "result" TEXT);

.mode csv
.import ./data.csv rna-transcription
63 changes: 51 additions & 12 deletions exercises/practice/rna-transcription/rna-transcription_test.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
-- Setup test table and read in student solution:
.read ./test_setup.sql

-- Test cases:
INSERT INTO tests (name, uuid, dna, expected)
VALUES
('Empty RNA sequence', 'b4631f82-c98c-4a2f-90b3-c5c2b6c6f661', '', ''),
('RNA complement of cytosine is guanine', 'a9558a3c-318c-4240-9256-5d5ed47005a6', 'C', 'G'),
('RNA complement of guanine is cytosine', '6eedbb5c-12cb-4c8b-9f51-f8320b4dc2e7', 'G', 'C'),
('RNA complement of thymine is adenine', '870bd3ec-8487-471d-8d9a-a25046488d3e', 'T', 'A'),
('RNA complement of adenine is uracil', 'aade8964-02e1-4073-872f-42d3ffd74c5f', 'A', 'U'),
('RNA complement', '79ed2757-f018-4f47-a1d7-34a559392dbf', 'ACGTGGTCTTAA', 'UGCACCAGAAUU');
INSERT INTO
tests (name, uuid, dna, expected)
VALUES
(
'Empty RNA sequence',
'b4631f82-c98c-4a2f-90b3-c5c2b6c6f661',
'',
''
),
(
'RNA complement of cytosine is guanine',
'a9558a3c-318c-4240-9256-5d5ed47005a6',
'C',
'G'
),
(
'RNA complement of guanine is cytosine',
'6eedbb5c-12cb-4c8b-9f51-f8320b4dc2e7',
'G',
'C'
),
(
'RNA complement of thymine is adenine',
'870bd3ec-8487-471d-8d9a-a25046488d3e',
'T',
'A'
),
(
'RNA complement of adenine is uracil',
'aade8964-02e1-4073-872f-42d3ffd74c5f',
'A',
'U'
),
(
'RNA complement',
'79ed2757-f018-4f47-a1d7-34a559392dbf',
'ACGTGGTCTTAA',
'UGCACCAGAAUU'
);

-- Comparison of user input and the tests updates the status for each test:
UPDATE tests
SET status = 'pass'
FROM (SELECT dna, result FROM "rna-transcription") AS actual
WHERE (actual.dna, actual.result) = (tests.dna, tests.expected);
SET
status = 'pass'
FROM
(
SELECT
dna,
result
FROM
"rna-transcription"
) AS actual
WHERE
(actual.dna, actual.result) = (tests.dna, tests.expected);

-- Write results and debug info:
.read ./test_reporter.sql
41 changes: 30 additions & 11 deletions exercises/practice/rna-transcription/test_reporter.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
-- Update message for failed tests to give helpful information:
UPDATE tests
SET message = (
'Result for "' || tests.dna || '"'
|| ' is <' || COALESCE(actual.result, 'NULL')
|| '> but should be <' || tests.expected || '>'
)
FROM (SELECT dna, result FROM 'rna-transcription') AS actual
WHERE actual.dna = tests.dna AND tests.status = 'fail';
SET
message = (
'Result for "' || tests.dna || '"' || ' is <' || COALESCE(actual.result, 'NULL') || '> but should be <' || tests.expected || '>'
)
FROM
(
SELECT
dna,
result
FROM
'rna-transcription'
) AS actual
WHERE
actual.dna = tests.dna
AND tests.status = 'fail';

-- Save results to ./output.json (needed by the online test-runner)
.mode json
.once './output.json'
SELECT name, status, message, output, test_code, task_id
FROM tests;
SELECT
name,
status,
message,
output,
test_code,
task_id
FROM
tests;

-- Display test results in readable form for the student:
.mode table
SELECT name, status, message
FROM tests;
SELECT
name,
status,
message
FROM
tests;
27 changes: 13 additions & 14 deletions exercises/practice/rna-transcription/test_setup.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
-- Create database:
.read ./create_fixture.sql

-- Read user student solution and save any output as markdown in user_output.md:
.mode markdown
.output user_output.md
.read ./rna-transcription.sql
.output

-- Create a clean testing environment:
DROP TABLE IF EXISTS tests;

CREATE TABLE IF NOT EXISTS tests (
-- uuid and name (description) are taken from the test.toml file
uuid TEXT PRIMARY KEY,
name TEXT NOT NULL,
-- The following section is needed by the online test-runner
status TEXT DEFAULT 'fail',
message TEXT,
output TEXT,
test_code TEXT,
task_id INTEGER DEFAULT NULL,
-- Here are columns for the actual tests
dna TEXT NOT NULL,
expected TEXT NOT NULL
-- uuid and name (description) are taken from the test.toml file
uuid TEXT PRIMARY KEY,
name TEXT NOT NULL,
-- The following section is needed by the online test-runner
status TEXT DEFAULT 'fail',
message TEXT,
output TEXT,
test_code TEXT,
task_id INTEGER DEFAULT NULL,
-- Here are columns for the actual tests
dna TEXT NOT NULL,
expected TEXT NOT NULL
);