aboutsummaryrefslogtreecommitdiff
path: root/test/test.sh
diff options
context:
space:
mode:
authormithe24 <mithe24@student.sdu.dk>2025-10-10 19:13:05 +0200
committermithe24 <mithe24@student.sdu.dk>2025-10-29 13:49:57 +0100
commit25de1bee3c3f1e84fc6f32f199d69f13b392b41b (patch)
treea3a7cef0acfafb968a120141ad93f4d4dbb246bc /test/test.sh
parent1eceee1ad442ff47ddbf2e9baf8aa5add8fd1f71 (diff)
downloadsorter-25de1bee3c3f1e84fc6f32f199d69f13b392b41b.tar.gz
sorter-25de1bee3c3f1e84fc6f32f199d69f13b392b41b.zip
test(numbers.txt): Test script that compares output with 'sort'
Test case that matches output of the program and 'sort' using the command 'sort -n -k 2'
Diffstat (limited to 'test/test.sh')
-rwxr-xr-xtest/test.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test.sh b/test/test.sh
new file mode 100755
index 0000000..ec9d65c
--- /dev/null
+++ b/test/test.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+TEST_INPUT="numbers.txt"
+
+SORTER="./sorter"
+REF="sort -n -k 2"
+
+SORTER_OUT="sorter_out.txt"
+REF_OUT="ref_output.txt"
+DIFF_FILE="diff.txt"
+
+$SORTER "$TEST_INPUT" > "$SORTER_OUT"
+$REF "$TEST_INPUT" > "$REF_OUT"
+
+# Compare outputs
+if diff -q "$SORTER_OUT" "$REF_OUT" > /dev/null; then
+ echo "Passed: $TEST_INPUT"
+else
+ echo "Failed: $TEST_INPUT"
+ echo "Differences:"
+ diff -u "$SORTER_OUT" "$REF_OUT" > "$DIFF_FILE"
+ diff -u "$SORTER_OUT" "$REF_OUT" | head -n 20
+ echo
+fi
+