Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions exercises/practice/resistor-color-trio/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ header }}
{% for idx, case in cases %}
@test "{{ case["description"] }}" {
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} "{{ case["input"]["colors"] | join('" "') }}"
assert_success
assert_output "{{ case["expected"]["value"] }} {{ case["expected"]["unit"] }}"
}
{% endfor %}

@test "Invalid first color" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} "foo" "white" "white"
assert_failure
assert_output # there is _some_ output
}

@test "Invalid second color" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} "white" "bar" "white"
assert_failure
assert_output # there is _some_ output
}

@test "Invalid third color" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} "white" "white" "baz"
assert_failure
assert_output # there is _some_ output
}
43 changes: 18 additions & 25 deletions exercises/practice/resistor-color-trio/resistor_color_trio.bats
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bats
load bats-extra

# local version: 1.0.0.2
# additional tests for: invalid color, invalid octal number, too many colors
# generated on 2026-06-29T06:21:03+00:00
# local version: 2.0.0.0

@test "Orange and orange and black" {
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "orange" "orange" "black"
assert_success
assert_output "33 ohms"
Expand All @@ -18,13 +18,6 @@ load bats-extra
assert_output "680 ohms"
}

@test "Brown and red and red" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "brown" "red" "red"
assert_success
assert_output "1200 ohms"
}

@test "Red and black and red" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "red" "black" "red"
Expand All @@ -46,7 +39,7 @@ load bats-extra
assert_output "470 kiloohms"
}

@test "Blue and violet and grey" {
@test "Blue and violet and blue" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "blue" "violet" "blue"
assert_success
Expand All @@ -67,6 +60,20 @@ load bats-extra
assert_output "99 gigaohms"
}

@test "First two colors make an invalid octal number" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "black" "grey" "black"
assert_success
assert_output "8 ohms"
}

@test "Ignore extra colors" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "blue" "green" "yellow" "orange"
assert_success
assert_output "650 kiloohms"
}


@test "Invalid first color" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
Expand All @@ -88,17 +95,3 @@ load bats-extra
assert_failure
assert_output # there is _some_ output
}

@test "First two colors make an invalid octal number" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "black" "grey" "black"
assert_success
assert_output "8 ohms"
}

@test "Ignore extra colors" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash resistor_color_trio.sh "blue" "green" "yellow" "orange"
assert_success
assert_output "650 kiloohms"
}