diff options
Diffstat (limited to 'lambda-calcul/haskell/test.sh')
| -rwxr-xr-x | lambda-calcul/haskell/test.sh | 21 |
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" |
