Skip to content

Commit

Permalink
Resistor-color-duo: add test with 3 colors, and third color is ignore…
Browse files Browse the repository at this point in the history
…d. (#379)

Based on problem-specifications pull request 1569
exercism/problem-specifications#1569
  • Loading branch information
glennj authored and guygastineau committed Aug 19, 2019
1 parent 65c3684 commit f88a93f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion exercises/resistor-color-duo/.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.1.0
5 changes: 3 additions & 2 deletions exercises/resistor-color-duo/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ code() {
if [[ -n $code ]]; then
echo "$code"
else
echo "invalid color" >&2
echo "invalid color: $1" >&2
return 1
fi
}

# silently ignore extra colors
result=""
for color; do
for color in "$1" "$2"; do
if code=$(code "$color"); then
result+="$code"
else
Expand Down
9 changes: 8 additions & 1 deletion exercises/resistor-color-duo/resistor_color_duo_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash resistor_color_duo.sh foo
[[ $status -eq 1 ]]
[[ $output == "invalid color" ]]
[[ $output == *"invalid color"* ]]
}

@test "ignore too many colors" {
[[ $BATS_RUN_SKIPPED == true ]] || skip
run bash resistor_color_duo.sh green brown orange
[[ $status -eq 0 ]]
[[ $output == "51" ]]
}

0 comments on commit f88a93f

Please sign in to comment.