Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions exercises/concept/intro-select/create_fixture.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DROP TABLE IF EXISTS weather_readings;
CREATE TABLE weather_readings (
date TEXT NOT NULL,
location TEXT NOT NULL,
temperature REAL NOT NULL,
humidity INTEGER NOT NULL
);

.mode csv
.import ./data.csv weather_readings
6 changes: 6 additions & 0 deletions exercises/concept/intro-select/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"2025-10-22","Portland",53.1,72
"2025-10-22","Seattle",56.2,66
"2025-10-22","Boise",60.4,55
"2025-10-23","Portland",54.6,70
"2025-10-23","Seattle",57.8,68
"2025-10-23","Boise",62.0,58
1 change: 1 addition & 0 deletions exercises/concept/intro-select/intro-select-task1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM weather_readings;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM weather_readings;
1 change: 1 addition & 0 deletions exercises/concept/intro-select/intro-select-task2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT location, temperature FROM weather_readings;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT location, temperature FROM weather_readings;
2 changes: 2 additions & 0 deletions exercises/concept/intro-select/intro-select-task3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Expected to fail
SELECT 'Hello, world.' AS say_hi;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 'Hello, world.';
1 change: 1 addition & 0 deletions exercises/concept/intro-select/intro-select-task4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM weather_readings WHERE location = 'Seattle';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM weather_readings WHERE location = 'Seattle';
1 change: 1 addition & 0 deletions exercises/concept/intro-select/intro-select-task5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM weather_readings WHERE humidity BETWEEN 60 AND 70;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM weather_readings WHERE humidity BETWEEN 60 AND 70;
1 change: 1 addition & 0 deletions exercises/concept/intro-select/intro-select-task6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT location FROM weather_readings;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT location FROM weather_readings;
87 changes: 87 additions & 0 deletions exercises/concept/intro-select/intro-select_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
-- Create database:
.read ./create_fixture.sql

.mode columns

-- Generate expected output
.output expected_output.txt

.print
.print "All data"
.print "========"
.print
.read intro-select-task1_exemplar.sql

.print
.print "Location and temperature only"
.print "============================="
.print
.read intro-select-task2_exemplar.sql

.print
.print "Greeting"
.print "========"
.print
.read intro-select-task3_exemplar.sql

.print
.print "Data for Seattle"
.print "================"
.print
.read intro-select-task4_exemplar.sql

.print
.print "Data with humidity constraints"
.print "=============================="
.print
.read intro-select-task5_exemplar.sql

.print
.print "Locations"
.print "========="
.print
.read intro-select-task6_exemplar.sql


-- Run user solutions
.output user_output.txt
.print
.print "All data"
.print "========"
.print
.read intro-select-task1.sql

.print
.print "Location and temperature only"
.print "============================="
.print
.read intro-select-task2.sql

.print
.print "Greeting"
.print "========"
.print
.read intro-select-task3.sql

.print
.print "Data for Seattle"
.print "================"
.print
.read intro-select-task4.sql

.print
.print "Data with humidity constraints"
.print "=============================="
.print
.read intro-select-task5.sql

.print
.print "Locations"
.print "========="
.print
.read intro-select-task6.sql


-- Compare expected vs actual
.shell diff expected_output.txt user_output.txt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff output is certainly not user-friendly. Instead of diff, we could run a custom Python script here that would generate a friendlier diff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, note that this would work with the existing test runner.