Skip to content

Commit cc1d780

Browse files
authored
Verify exercise difficulties (#503)
* Adjust config.json to return exercise difficulties to one of 1, 4, 7, 10. Performed with the following command line: ```shell jq '.exercises |= map( if .difficulty == 3 then .difficulty=4 elif .difficulty == 6 then .difficulty=7 else . end )' config.json > config.json.new && \ diff config.json config.json.new ; \ mv config.json.new config.json ``` * Add script to verify exercise difficulties Encompasses #502 and should probably be merged afterward. * Specify correct path for verify-exercise-difficulties * Add executable bit to _test/*.sh
1 parent fae83e7 commit cc1d780

7 files changed

+53
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ script:
88
- "./bin/fetch-configlet"
99
- "sh ./_test/ensure-readmes-are-updated.sh"
1010
- "./bin/configlet lint ."
11+
- "./_test/verify-exercise-difficulties.sh"
1112
sudo: false
1213
rust:
1314
- stable

_test/check-stubs.sh

100644100755
File mode changed.

_test/count-ignores.sh

100644100755
File mode changed.

_test/ensure-lib-src-rs-exist.sh

100644100755
File mode changed.

_test/ensure-readmes-are-updated.sh

100644100755
File mode changed.

_test/ensure-stubs-compile.sh

100644100755
File mode changed.

_test/verify-exercise-difficulties.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
repo=$(cd "$(dirname "$0")/.." && pwd)
4+
config=$repo/config.json
5+
6+
es=0
7+
8+
# ensure every exercise has a difficulty
9+
no_difficulty=$(
10+
jq --raw-output '
11+
.exercises[] |
12+
select((.deprecated | not) and (has("difficulty") | not)) |
13+
.slug
14+
' $config
15+
)
16+
if [ -n "$no_difficulty" ]; then
17+
echo "Exercises without a difficulty in config.json:"
18+
echo "$no_difficulty"
19+
es=1
20+
fi
21+
22+
# ensure that all difficulties are one of 1, 4, 7, 10
23+
invalid_difficulty=$(
24+
jq --raw-output '
25+
.exercises[] |
26+
select(
27+
(.deprecated | not) and
28+
has("difficulty") and
29+
(
30+
.difficulty | tostring |
31+
in({"1":null,"4":null,"7":null,"10":null}) |
32+
not
33+
)
34+
) |
35+
"\(.slug) (\(.difficulty))"
36+
' $config
37+
)
38+
if [ -n "$invalid_difficulty" ]; then
39+
echo "Exercises with invalid difficulty (must be in {1, 4, 7, 10})"
40+
echo "$invalid_difficulty"
41+
es=1
42+
fi
43+
44+
# ensure difficulties are sorted
45+
exercise_order=$(jq --raw-output '.exercises[] | select(.deprecated | not) | .slug' $config)
46+
sorted_order=$(jq --raw-output '.exercises | sort_by(.difficulty) | .[] | select(.deprecated | not) | .slug' $config)
47+
if [ "$exercise_order" != "$sorted_order" ]; then
48+
echo "Exercises are not in sorted order in config.json"
49+
es=1
50+
fi
51+
52+
exit $es

0 commit comments

Comments
 (0)