Skip to content

Commit 8d1ed39

Browse files
authored
[perfect-numbers] Add a Jinja test template (#853)
1 parent 8460cab commit 8d1ed39

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

exercises/practice/perfect-numbers/.meta/example.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ aliquot_sum() {
2929
declare -i num=$1
3030

3131
if ((num <= 0)); then
32-
echo "Classification is only possible for natural numbers." >&2
32+
echo "Classification is only possible for positive integers." >&2
3333
exit 1
3434
fi
3535

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ header }}
2+
{% for idx, case in cases %}
3+
@test "{{ case["description"] }}" {
4+
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
5+
run bash {{ solution }} {{ case["input"]["number"] }}
6+
{%- if case["expect_error"] %}
7+
assert_failure
8+
assert_output "{{ case["expect_error_msg"] }}"
9+
{%- else %}
10+
assert_success
11+
assert_output "{{ case["expected"] }}"
12+
{%- endif %}
13+
}
14+
{% endfor %}

exercises/practice/perfect-numbers/perfect_numbers.bats

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env bats
22
load bats-extra
33

4-
# local version: 1.1.0.0
5-
6-
# "Perfect numbers"
4+
# generated on 2026-06-29T05:05:58+00:00
5+
# local version: 2.0.0.0
76

87
@test "Smallest perfect number is classified correctly" {
9-
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
8+
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
109
run bash perfect_numbers.sh 6
1110
assert_success
1211
assert_output "perfect"
@@ -26,8 +25,6 @@ load bats-extra
2625
assert_output "perfect"
2726
}
2827

29-
# "Abundant numbers"
30-
3128
@test "Smallest abundant number is classified correctly" {
3229
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
3330
run bash perfect_numbers.sh 12
@@ -56,8 +53,6 @@ load bats-extra
5653
assert_output "abundant"
5754
}
5855

59-
# "Deficient numbers"
60-
6156
@test "Smallest prime deficient number is classified correctly" {
6257
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
6358
run bash perfect_numbers.sh 2
@@ -93,18 +88,16 @@ load bats-extra
9388
assert_output "deficient"
9489
}
9590

96-
# "Invalid inputs"
97-
98-
@test "Zero is rejected (not a natural number)" {
91+
@test "Zero is rejected (as it is not a positive integer)" {
9992
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
10093
run bash perfect_numbers.sh 0
10194
assert_failure
102-
assert_output "Classification is only possible for natural numbers."
95+
assert_output "Classification is only possible for positive integers."
10396
}
10497

105-
@test "Negative integer is rejected (not a natural number)" {
98+
@test "Negative integer is rejected (as it is not a positive integer)" {
10699
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
107100
run bash perfect_numbers.sh -1
108101
assert_failure
109-
assert_output "Classification is only possible for natural numbers."
102+
assert_output "Classification is only possible for positive integers."
110103
}

0 commit comments

Comments
 (0)