a gleam implementation of a CS assignment originally written in cpp
1#!/bin/bash 2temp_file="lab66.output" 3inp_file="lab66.input" 4 5rm -f verses.txt 6./lab66 < "$inp_file" > "$temp_file" 7verses=$(< verses.txt) 8echo "verses.txt : ${verses} " 9 10resp=$(./lab66 < "$inp_file") 11 12if [ $? -eq 0 ] ; then 13 echo "Pass: Program exited zero" 14else 15 echo "Fail: Program did not exit zero" 16 exit 1 17fi 18 19exp_resp=$(< lab66_exp.output) 20 21 22if [[ $resp = $exp_resp ]]; then 23 echo "Pass: Program output matched expected string" 24else 25 # Check if the strings are the same length 26 if [ "${#resp}" -ne "${#exp_resp}" ]; then 27 echo "Strings are different lengths : ${#resp} vs ${#exp_resp}" 28 fi 29 30 # Iterate over the characters in the strings 31 for (( i=0; i<${#resp}; i++ )); do 32 # Extract the character at position i from each string 33 char1="${resp:$i:1}" 34 char2="${exp_resp:$i:1}" 35 ch1_ascii=$(printf "%d" "'$char1") 36 ch2_ascii=$(printf "%d" "'$char2") 37 38 # Compare the characters 39 if [ "$char1" != "$char2" ]; then 40 echo "First difference at position $i: $ch1_ascii vs $ch2_ascii" 41 break 42 fi 43 done 44 echo Error : Expected \"$exp_resp\", your output was \"$resp\" 45 exit 1 46fi 47 48rm -f "$temp_file" 49 50echo 51echo "All tests passed." 52 53exit 0