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
2 changes: 1 addition & 1 deletion exercises/practice/perfect-numbers/.meta/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ aliquot_sum() {
declare -i num=$1

if ((num <= 0)); then
echo "Classification is only possible for natural numbers." >&2
echo "Classification is only possible for positive integers." >&2
exit 1
fi

Expand Down
14 changes: 14 additions & 0 deletions exercises/practice/perfect-numbers/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ header }}
{% for idx, case in cases %}
@test "{{ case["description"] }}" {
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} {{ case["input"]["number"] }}
{%- if case["expect_error"] %}
assert_failure
assert_output "{{ case["expect_error_msg"] }}"
{%- else %}
assert_success
assert_output "{{ case["expected"] }}"
{%- endif %}
}
{% endfor %}
21 changes: 7 additions & 14 deletions exercises/practice/perfect-numbers/perfect_numbers.bats
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env bats
load bats-extra

# local version: 1.1.0.0

# "Perfect numbers"
# generated on 2026-06-29T05:05:58+00:00
# local version: 2.0.0.0

@test "Smallest perfect number is classified correctly" {
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash perfect_numbers.sh 6
assert_success
assert_output "perfect"
Expand All @@ -26,8 +25,6 @@ load bats-extra
assert_output "perfect"
}

# "Abundant numbers"

@test "Smallest abundant number is classified correctly" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash perfect_numbers.sh 12
Expand Down Expand Up @@ -56,8 +53,6 @@ load bats-extra
assert_output "abundant"
}

# "Deficient numbers"

@test "Smallest prime deficient number is classified correctly" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash perfect_numbers.sh 2
Expand Down Expand Up @@ -93,18 +88,16 @@ load bats-extra
assert_output "deficient"
}

# "Invalid inputs"

@test "Zero is rejected (not a natural number)" {
@test "Zero is rejected (as it is not a positive integer)" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash perfect_numbers.sh 0
assert_failure
assert_output "Classification is only possible for natural numbers."
assert_output "Classification is only possible for positive integers."
}

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