summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test.sh
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2025-11-06 08:14:58 +0100
committerArnaud Bailly <arnaud@pankzsoft.com>2025-11-06 08:14:58 +0100
commit6d35fd9630238375cc28a282780f597421107469 (patch)
treed4f02ab20c7735396ae0fbed70a3d8434a6a6773 /lambda-calcul/haskell/test.sh
parent15c684d437da53ddfb88bbc9ad566588f89732c1 (diff)
downloadlambda-nantes-6d35fd9630238375cc28a282780f597421107469.tar.gz
updated challenges
Diffstat (limited to 'lambda-calcul/haskell/test.sh')
-rwxr-xr-xlambda-calcul/haskell/test.sh21
1 files changed, 17 insertions, 4 deletions
diff --git a/lambda-calcul/haskell/test.sh b/lambda-calcul/haskell/test.sh
index 1b78960..6bb9dc4 100755
--- a/lambda-calcul/haskell/test.sh
+++ b/lambda-calcul/haskell/test.sh
@@ -4,23 +4,36 @@ set -euo pipefail
HOST=${1:-https://lambda.pankzsoft.net}
-ALICE=$(curl -s -X POST -H 'content-type: application/json' $HOST/api/register -d '"alice"' | jq -r)
+post () {
+ url=$1
+ data=$2
+
+ curl -s -X POST -H 'content-type: application/json' "$url" -d "$data"
+}
+
+get () {
+ url=$1
+
+ curl -s -X GET -H 'content-type: application/json' "$url"
+}
+
+ALICE=$(post $HOST/api/register '"alice"' | jq -r)
echo "registered alice with token '$ALICE'"
sleep 2
for i in $(seq 1 14); do
- GRADE=$(curl -s -X GET -H 'content-type: application/json' "$HOST/api/score?token=$ALICE" | jq -r .grade)
+ GRADE=$(get "$HOST/api/score?token=$ALICE" | jq -r .grade)
echo "alice's grade is $GRADE"
sleep 1
- CHAL=$(curl -s -X GET -H 'content-type: application/json' "$HOST/api/challenge?token=$ALICE" | jq -r .expr)
+ CHAL=$(get "$HOST/api/challenge?token=$ALICE" | jq -r .expr)
echo "alice's challenge is '$CHAL'"
sleep 1
ANSWER=$(echo "$CHAL" | cabal run)
echo "alice's answer is '$ANSWER'"
- RESULT=$(curl -s -X POST -H 'content-type: application/json' "$HOST/api/challenge?token=$ALICE" -d "\"$ANSWER\"")
+ RESULT=$(post "$HOST/api/challenge?token=$ALICE" "\"$ANSWER\"")
if [ "$RESULT" != "[]" ]; then
echo "Failed challenge: $RESULT"