#!/bin/sh
# run.sh — Quakes grader. Do not filter, skip, or reinterpret.
#
# Runs ./quakes over the frozen USGS snapshot and compares every report's exit code and standard
# output with the known answer below. Standard error is never compared. No network is used.
#
# sh sources/run.sh from the application root (how `drydock uat` runs it)
# sh uat/Quakes/bin/run.sh APP from anywhere, grading the application root APP
#
# Exit 0 only when every check passes.
set -u
HERE=$(cd "$(dirname "$0")" && pwd)
APP=$(cd "${1:-.}" && pwd)
if [ -f "$HERE/quakes_2025-01-01_07.geojson" ]; then DATA=$HERE; else DATA=$(cd "$HERE/../sources" && pwd); fi
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT INT TERM
BIN="$APP/quakes"
QUAKES="$DATA/quakes_2025-01-01_07.geojson"
printf 'this is not json\n' > "$WORK/garbage.json"
printf '{"type":"Feature","properties":{},"geometry":null}\n' > "$WORK/feature.json"
if [ ! -x "$BIN" ]; then
echo "error: no executable ./quakes at the application root $APP." >&2
echo "The deliverable is an executable named quakes at the application root." >&2
exit 1
fi
PASSED=0
FAILED=0
# check <id> <expected exit> <quakes args...> — expected standard output on stdin.
check() {
id=$1
want_rc=$2
shift 2
cat > "$WORK/want"
(cd "$APP" && "$BIN" "$@") > "$WORK/got" 2> "$WORK/err"
rc=$?
if [ "$rc" -eq "$want_rc" ] && cmp -s "$WORK/want" "$WORK/got"; then
PASSED=$((PASSED + 1))
echo "PASS $id: quakes $*"
else
FAILED=$((FAILED + 1))
echo "FAIL $id: quakes $*"
echo " exit: expected $want_rc, got $rc"
diff "$WORK/want" "$WORK/got" | sed 's/^/ /'
sed 's/^/ stderr: /' "$WORK/err"
fi
}
# ── A. Every report over the snapshot ──────────────────────────────────────────────────
check A1 0 summary "$QUAKES" <<'EOF'
events,first,last,min_mag,max_mag,mean_mag,tsunami
44,2025-01-01T04:39:18Z,2025-01-07T17:52:21Z,5.0,7.1,5.30,0
EOF
check A2 0 top "$QUAKES" <<'EOF'
time,mag,depth_km,place,id
2025-01-07T01:05:16Z,7.1,10.0,2025 Southern Tibetan Plateau Earthquake,us6000pi9w
2025-01-05T17:18:45Z,6.2,46.0,"56 km SSE of La Libertad, El Salvador",us6000pi09
2025-01-01T13:48:24Z,6.1,70.0,South Sandwich Islands region,us6000pgv4
2025-01-02T20:43:35Z,6.1,99.0,"84 km NNW of Calama, Chile",us6000phap
2025-01-04T00:52:21Z,5.7,8.0,"52 km N of Āwash, Ethiopia",us6000phrk
2025-01-07T08:31:30Z,5.6,358.0,"Izu Islands, Japan region",us6000pida
2025-01-01T04:39:18Z,5.5,22.0,"153 km S of Isangel, Vanuatu",us6000pgsd
2025-01-02T02:54:17Z,5.5,10.0,Balleny Islands region,us6000pgzq
2025-01-03T02:33:17Z,5.5,86.0,South Sandwich Islands region,us6000phce
2025-01-03T17:01:46Z,5.5,10.0,"45 km NNE of Āwash, Ethiopia",us6000phnz
EOF
check A3 0 daily "$QUAKES" <<'EOF'
date,events,max_mag
2025-01-01,7,6.1
2025-01-02,8,6.1
2025-01-03,6,5.5
2025-01-04,3,5.7
2025-01-05,3,6.2
2025-01-06,5,5.2
2025-01-07,12,7.1
TOTAL,44,7.1
EOF
check A4 0 regions "$QUAKES" <<'EOF'
region,events,max_mag
Ethiopia,7,5.7
Papua New Guinea,6,5.4
Nepal,3,5.4
Southern Tibetan Plateau,3,5.2
Vanuatu,3,5.5
Indonesia,2,5.1
Japan region,2,5.6
South Sandwich Islands region,2,6.1
2025 Southern Tibetan Plateau Earthquake,1,7.1
Balleny Islands region,1,5.5
Chile,1,6.1
El Salvador,1,6.2
Fiji region,1,5.0
India,1,5.0
Iran,1,5.2
Japan,1,5.1
Mid-Indian Ridge,1,5.2
Philippines,1,5.1
Solomon Islands,1,5.2
Southwest Indian Ridge,1,5.0
Tibetan Plateau,1,5.2
Tonga,1,5.1
southeast of Easter Island,1,5.3
southern Mid-Atlantic Ridge,1,5.2
EOF
# ── B. Options ───────────────────────────────────────────────────────────────────────────
check B1 0 top --n 3 "$QUAKES" <<'EOF'
time,mag,depth_km,place,id
2025-01-07T01:05:16Z,7.1,10.0,2025 Southern Tibetan Plateau Earthquake,us6000pi9w
2025-01-05T17:18:45Z,6.2,46.0,"56 km SSE of La Libertad, El Salvador",us6000pi09
2025-01-01T13:48:24Z,6.1,70.0,South Sandwich Islands region,us6000pgv4
EOF
check B2 0 summary --min-mag 5.5 "$QUAKES" <<'EOF'
events,first,last,min_mag,max_mag,mean_mag,tsunami
10,2025-01-01T04:39:18Z,2025-01-07T08:31:30Z,5.5,7.1,5.88,0
EOF
check B3 0 regions --min-mag 5.4 "$QUAKES" <<'EOF'
region,events,max_mag
Ethiopia,3,5.7
South Sandwich Islands region,2,6.1
2025 Southern Tibetan Plateau Earthquake,1,7.1
Balleny Islands region,1,5.5
Chile,1,6.1
El Salvador,1,6.2
Japan region,1,5.6
Nepal,1,5.4
Papua New Guinea,1,5.4
Vanuatu,1,5.5
EOF
check B4 0 daily --min-mag 6 "$QUAKES" <<'EOF'
date,events,max_mag
2025-01-01,1,6.1
2025-01-02,1,6.1
2025-01-05,1,6.2
2025-01-07,1,7.1
TOTAL,4,7.1
EOF
check B5 0 top --min-mag 5.1 --n 4 "$QUAKES" <<'EOF'
time,mag,depth_km,place,id
2025-01-07T01:05:16Z,7.1,10.0,2025 Southern Tibetan Plateau Earthquake,us6000pi9w
2025-01-05T17:18:45Z,6.2,46.0,"56 km SSE of La Libertad, El Salvador",us6000pi09
2025-01-01T13:48:24Z,6.1,70.0,South Sandwich Islands region,us6000pgv4
2025-01-02T20:43:35Z,6.1,99.0,"84 km NNW of Calama, Chile",us6000phap
EOF
# ── C. Distance search ───────────────────────────────────────────────────────────────────
check C1 0 near --lat 27.72 --lon 85.32 --radius 800 "$QUAKES" <<'EOF'
distance_km,time,mag,place,id
214.8,2025-01-07T01:10:54Z,5.2,"100 km NNE of Lobuche, Nepal",us6000pks6
216.8,2025-01-07T01:09:13Z,5.4,"96 km NNE of Lobuche, Nepal",us6000pks1
219.0,2025-01-07T01:14:42Z,5.2,"83 km NE of Lobuche, Nepal",us6000pkpp
222.3,2025-01-07T01:37:13Z,5.0,Southern Tibetan Plateau,us6000piar
224.4,2025-01-07T01:05:16Z,7.1,2025 Southern Tibetan Plateau Earthquake,us6000pi9w
225.3,2025-01-07T01:13:27Z,5.2,Southern Tibetan Plateau,us6000pia7
226.2,2025-01-07T01:24:25Z,5.0,Southern Tibetan Plateau,us6000piak
655.6,2025-01-06T15:26:46Z,5.2,Tibetan Plateau,us6000pi67
EOF
check C2 0 near --lat 35.68 --lon 139.69 --radius 1500 "$QUAKES" <<'EOF'
distance_km,time,mag,place,id
216.3,2025-01-06T16:44:39Z,5.1,"113 km E of Hasaki, Japan",us6000pi7a
466.3,2025-01-07T08:31:30Z,5.6,"Izu Islands, Japan region",us6000pida
1288.3,2025-01-07T17:23:48Z,5.3,"Volcano Islands, Japan region",us6000pife
EOF
check C3 0 near --lat 9.03 --lon 38.74 --radius 300 --min-mag 5.3 "$QUAKES" <<'EOF'
distance_km,time,mag,place,id
159.0,2025-01-04T00:52:21Z,5.7,"52 km N of Āwash, Ethiopia",us6000phrk
174.7,2025-01-02T21:18:26Z,5.4,"52 km NNE of Āwash, Ethiopia",us6000phb3
180.0,2025-01-03T17:01:46Z,5.5,"45 km NNE of Āwash, Ethiopia",us6000phnz
EOF
check C4 0 near --lat 0 --lon 0 --radius 100 "$QUAKES" <<'EOF'
distance_km,time,mag,place,id
EOF
# ── D. Nothing matches ───────────────────────────────────────────────────────────────────
check D1 0 summary --min-mag 9 "$QUAKES" <<'EOF'
events,first,last,min_mag,max_mag,mean_mag,tsunami
0,,,,,,0
EOF
check D2 0 daily --min-mag 9 "$QUAKES" <<'EOF'
date,events,max_mag
TOTAL,0,
EOF
# ── E. Operational failures ──────────────────────────────────────────────────────────────
check E1 1 summary "$WORK/no-such-file.geojson" < /dev/null
check E2 1 summary "$WORK/garbage.json" < /dev/null
check E3 1 summary "$WORK/feature.json" < /dev/null
# ── U. Usage errors ──────────────────────────────────────────────────────────────────────
check U1 2 < /dev/null
check U2 2 frobnicate "$QUAKES" < /dev/null
check U3 2 near --lat 27.72 --lon 85.32 "$QUAKES" < /dev/null
check U4 2 top --n 0 "$QUAKES" < /dev/null
check U5 2 summary --min-mag big "$QUAKES" < /dev/null
check U6 2 near --lat 95 --lon 0 --radius 10 "$QUAKES" < /dev/null
check U7 2 summary --n 3 "$QUAKES" < /dev/null
check U8 2 summary < /dev/null
TOTAL=$((PASSED + FAILED))
echo "Quakes: $PASSED passed, $FAILED failed (of $TOTAL)"
[ "$FAILED" -eq 0 ]
Run artifact