From 6894d250dda6c50ef8293947262812024cdb3214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 4 Dec 2025 11:04:16 +0100 Subject: [PATCH] Improve testing script. --- test.sh | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/test.sh b/test.sh index 7761095..5e795f4 100755 --- a/test.sh +++ b/test.sh @@ -1,28 +1,50 @@ #!/bin/bash -echo -n "Prime finding..." -if [[ $(./target/release/indivisible 5) == 11 ]] +DEBUG_BIN="./target/debug/indivisible" +RELEASE_BIN="./target/release/indivisible" + +if [ -f "$DEBUG_BIN" ] then - echo " pass" + BINARY="$DEBUG_BIN" +elif [ -f "$RELEASE_BIN" ] +then + BINARY="$RELEASE_BIN" else - echo " FAIL" + >&2 echo "No valid binary found. Please compile the project." exit 1 fi -echo -n "Positive prime test..." -if ./target/release/indivisible -t 11 +tests=0 +passed=0 + +((tests++)) +echo -n "${tests}: Find 5th prime number..." +if [[ $("$BINARY" 5) == 11 ]] then echo " pass" + ((passed++)) else echo " FAIL" - exit 1 fi -echo -n "Negative prime test..." -if ! ./target/release/indivisible -t 9 +((tests++)) +echo -n "${tests}: 11 is prime..." +if "$BINARY" -t 11 then echo " pass" + ((passed++)) else echo " FAIL" - exit 1 fi + +((tests++)) +echo -n "${tests}: 9 is not prime..." +if ! "$BINARY" -t 9 +then + echo " pass" + ((passed++)) +else + echo " FAIL" +fi + +echo "Results: $passed/$tests"