From 9c9d517c8473bfa0d81c60f45af2953b3319f599 Mon Sep 17 00:00:00 2001 From: Michele Sessa Date: Mon, 27 Mar 2023 17:44:10 +0100 Subject: [PATCH] test(greatest-of-all): refactor challenge function is now more modular and got called once for every test --- sh/tests/greatest-of-all_test.sh | 36 +++++++++++++++----------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/sh/tests/greatest-of-all_test.sh b/sh/tests/greatest-of-all_test.sh index 7a4556ed6..138a7a266 100755 --- a/sh/tests/greatest-of-all_test.sh +++ b/sh/tests/greatest-of-all_test.sh @@ -5,25 +5,23 @@ IFS=' script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) challenge() { - - submitted=$(echo -e "0\n3\n2\n5\n7\n1\n4\n9\n8\n6\n10" | bash -c ""$script_dirS"/student/greatest-of-all.sh") - expected=$(echo -e "0\n3\n2\n5\n7\n1\n4\n9\n8\n6\n10" | bash -c ""$script_dirS"/solutions/greatest-of-all.sh") - diff <(echo "$submitted") <(echo "$expected") - submitted=$(echo -e "26\n85\n21\n94\n68\n60\n99\n31\n10\n98\n" | bash -c ""$script_dirS"/student/greatest-of-all.sh") - expected=$(echo -e "26\n85\n21\n94\n68\n60\n99\n31\n10\n98\n" | bash -c ""$script_dirS"/solutions/greatest-of-all.sh") - diff <(echo "$submitted") <(echo "$expected") - submitted=$(echo -e "152\n485\n569\n611\n871\n551\n984\n895\n285\n989\n" | bash -c ""$script_dirS"/student/greatest-of-all.sh") - expected=$(echo -e "152\n485\n569\n611\n871\n551\n984\n895\n285\n989\n" | bash -c ""$script_dirS"/solutions/greatest-of-all.sh") - diff <(echo "$submitted") <(echo "$expected") - submitted=$(echo -e "152\n10001\n569" | bash -c ""$script_dirS"/student/greatest-of-all.sh") - expected=$(echo -e "152\n10001\n569" | bash -c ""$script_dirS"/solutions/greatest-of-all.sh") - diff <(echo "$submitted") <(echo "$expected") - submitted=$(echo -e "152\n485\nalpha\n" | bash -c ""$script_dirS"/student/greatest-of-all.sh") - expected=$(echo -e "152\n485\nalpha\n" | bash -c ""$script_dirS"/solutions/greatest-of-all.sh") - diff <(echo "$submitted") <(echo "$expected") - submitted=$(echo -e "152\n485\n-45\n45\n" | bash -c ""$script_dirS"/student/greatest-of-all.sh") - expected=$(echo -e "152\n485\n-45\n45" | bash -c ""$script_dirS"/solutions/greatest-of-all.sh") + submitted=$(echo -e $1 | bash "./student/greatest-of-all.sh") + expected=$(echo -e $1 | bash "./solutions/greatest-of-all.sh") diff <(echo "$submitted") <(echo "$expected") + if [ $? != 0 ] + then + exit 1 + fi } -challenge +challenge "0\n3\n2\n5\n7\n1\n4\n9\n8\n6\n10" + +challenge "26\n85\n21\n94\n68\n60\n99\n31\n10\n98\n" + +challenge "152\n485\n569\n611\n871\n551\n984\n895\n285\n989\n" + +challenge "152\n10001\n569" + +challenge "152\n485\nalpha\n" + +challenge "152\n485\n-45\n45\n"