Improve testing script.

This commit is contained in:
2025-12-04 11:04:16 +01:00
parent 23c8dd694f
commit 6894d250dd

42
test.sh
View File

@@ -1,28 +1,50 @@
#!/bin/bash #!/bin/bash
echo -n "Prime finding..." DEBUG_BIN="./target/debug/indivisible"
if [[ $(./target/release/indivisible 5) == 11 ]] RELEASE_BIN="./target/release/indivisible"
if [ -f "$DEBUG_BIN" ]
then then
echo " pass" BINARY="$DEBUG_BIN"
elif [ -f "$RELEASE_BIN" ]
then
BINARY="$RELEASE_BIN"
else else
echo " FAIL" >&2 echo "No valid binary found. Please compile the project."
exit 1 exit 1
fi fi
echo -n "Positive prime test..." tests=0
if ./target/release/indivisible -t 11 passed=0
((tests++))
echo -n "${tests}: Find 5th prime number..."
if [[ $("$BINARY" 5) == 11 ]]
then then
echo " pass" echo " pass"
((passed++))
else else
echo " FAIL" echo " FAIL"
exit 1
fi fi
echo -n "Negative prime test..." ((tests++))
if ! ./target/release/indivisible -t 9 echo -n "${tests}: 11 is prime..."
if "$BINARY" -t 11
then then
echo " pass" echo " pass"
((passed++))
else else
echo " FAIL" echo " FAIL"
exit 1
fi 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"