Skip to content

Commit

Permalink
Revert new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 committed Dec 17, 2024
1 parent 5f659a4 commit 8eff39b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

func isArmstrongNumber(_ number: Int128) -> Bool {
func isArmstrongNumber(_ number: Int) -> Bool {
let stringNumber = String(number)
let numberLength = stringNumber.count
let sum = stringNumber.compactMap { Int(String($0)) }.reduce(0) { $0 + Int(pow(Double($1), Double(numberLength))) }
let sum: Int = stringNumber.compactMap { Int(String($0)) }.reduce(0) { $0 + Int(pow(Double($1), Double(numberLength))) }
return sum == number
}
30 changes: 15 additions & 15 deletions exercises/practice/armstrong-numbers/.meta/template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import Foundation

let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false

{% for case in cases %}
{% if forloop.first -%}
@Test("{{case.description}}")
func test{{case.description |camelCase }}() {
{% else -%}
@Test("{{case.description}}", .enabled(if: RUNALL))
func test{{case.description |camelCase }}() throws {
{% endif -%}
{%- if case.expected -%}
#expect(isArmstrongNumber({{case.input.number}}))
{%- else -%}
#expect(isArmstrongNumber({{case.input.number}}))
{%- endif %}
@Suite struct {{exercise|camelCase}}Tests {
{% for case in cases %}
{% if forloop.first -%}
@Test("{{case.description}}")
{% else -%}
@Test("{{case.description}}", .enabled(if: RUNALL))
{% endif -%}
func test{{case.description |camelCase }}() {
{%- if case.expected -%}
#expect(isArmstrongNumber({{case.input.number}}))
{%- else -%}
#expect(!isArmstrongNumber({{case.input.number}}))
{%- endif %}
}
{% endfor -%}
}
{% endfor -%}

2 changes: 2 additions & 0 deletions exercises/practice/armstrong-numbers/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ description = "Seven-digit number that is not an Armstrong number"

[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148]
description = "Armstrong number containing seven zeroes"
include = false

[12ffbf10-307a-434e-b4ad-c925680e1dd4]
description = "The largest and last Armstrong number"
include = false
Original file line number Diff line number Diff line change
@@ -1,61 +1,54 @@
import Testing
import Foundation
import Testing

@testable import ArmstrongNumbers

let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false

@Test("Zero is an Armstrong number")
func testZeroIsAnArmstrongNumber() {
#expect(isArmstrongNumber(0))
}

@Test("Single-digit numbers are Armstrong numbers", .enabled(if: RUNALL))
func testSingleDigitNumbersAreArmstrongNumbers() throws {
#expect(isArmstrongNumber(5))
}

@Test("There are no two-digit Armstrong numbers", .enabled(if: RUNALL))
func testThereAreNoTwoDigitArmstrongNumbers() throws {
#expect(isArmstrongNumber(10))
}

@Test("Three-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testThreeDigitNumberThatIsAnArmstrongNumber() throws {
#expect(isArmstrongNumber(153))
}

@Test("Three-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testThreeDigitNumberThatIsNotAnArmstrongNumber() throws {
#expect(isArmstrongNumber(100))
}

@Test("Four-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testFourDigitNumberThatIsAnArmstrongNumber() throws {
#expect(isArmstrongNumber(9474))
}

@Test("Four-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testFourDigitNumberThatIsNotAnArmstrongNumber() throws {
#expect(isArmstrongNumber(9475))
}

@Test("Seven-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testSevenDigitNumberThatIsAnArmstrongNumber() throws {
#expect(isArmstrongNumber(9_926_315))
}

@Test("Seven-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testSevenDigitNumberThatIsNotAnArmstrongNumber() throws {
#expect(isArmstrongNumber(9_926_314))
}

@Test("Armstrong number containing seven zeroes", .enabled(if: RUNALL))
func testArmstrongNumberContainingSevenZeroes() throws {
#expect(isArmstrongNumber(186_709_961_001_538_790_100_634_132_976_990))
}

@Test("The largest and last Armstrong number", .enabled(if: RUNALL))
func testTheLargestAndLastArmstrongNumber() throws {
#expect(isArmstrongNumber(115_132_219_018_763_992_565_095_597_973_971_522_401))
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "true"]) ?? false

@Suite struct ArmstrongNumbersTests {

@Test("Zero is an Armstrong number")
func testZeroIsAnArmstrongNumber() {
#expect(isArmstrongNumber(0))
}

@Test("Single-digit numbers are Armstrong numbers", .enabled(if: RUNALL))
func testSingleDigitNumbersAreArmstrongNumbers() {
#expect(isArmstrongNumber(5))
}

@Test("There are no two-digit Armstrong numbers", .enabled(if: RUNALL))
func testThereAreNoTwoDigitArmstrongNumbers() {
#expect(!isArmstrongNumber(10))
}

@Test("Three-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testThreeDigitNumberThatIsAnArmstrongNumber() {
#expect(isArmstrongNumber(153))
}

@Test("Three-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testThreeDigitNumberThatIsNotAnArmstrongNumber() {
#expect(!isArmstrongNumber(100))
}

@Test("Four-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testFourDigitNumberThatIsAnArmstrongNumber() {
#expect(isArmstrongNumber(9474))
}

@Test("Four-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testFourDigitNumberThatIsNotAnArmstrongNumber() {
#expect(!isArmstrongNumber(9475))
}

@Test("Seven-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testSevenDigitNumberThatIsAnArmstrongNumber() {
#expect(isArmstrongNumber(9_926_315))
}

@Test("Seven-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testSevenDigitNumberThatIsNotAnArmstrongNumber() {
#expect(!isArmstrongNumber(9_926_314))
}
}

0 comments on commit 8eff39b

Please sign in to comment.