Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift 6.0]: Update armstrong number with new testing files #784

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 10 additions & 8 deletions exercises/practice/armstrong-numbers/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import XCTest
import Testing
import Foundation
@testable import {{exercise|camelCase}}
class {{exercise|camelCase}}Tests: XCTestCase {
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false

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

@Suite struct {{exercise|camelCase}}Tests {
{% for case in cases %}
{% if forloop.first -%}
func test{{case.description |camelCase }}() {
@Test("{{case.description}}")
{% else -%}
func test{{case.description |camelCase }}() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("{{case.description}}", .enabled(if: RUNALL))
{% endif -%}
func test{{case.description |camelCase }}() {
{%- if case.expected -%}
XCTAssertTrue(isArmstrongNumber({{case.input.number}}))
#expect(isArmstrongNumber({{case.input.number}}))
{%- else -%}
XCTAssertFalse(isArmstrongNumber({{case.input.number}}))
#expect(!isArmstrongNumber({{case.input.number}}))
{%- endif %}
}
{% endfor -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ include = false

[12ffbf10-307a-434e-b4ad-c925680e1dd4]
description = "The largest and last Armstrong number"
include = false
include = false
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
import XCTest
import Foundation
import Testing

@testable import ArmstrongNumbers

class ArmstrongNumbersTests: XCTestCase {
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "true"]) ?? false

@Suite struct ArmstrongNumbersTests {

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

func testSingleDigitNumbersAreArmstrongNumbers() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isArmstrongNumber(5))
@Test("Single-digit numbers are Armstrong numbers", .enabled(if: RUNALL))
func testSingleDigitNumbersAreArmstrongNumbers() {
#expect(isArmstrongNumber(5))
}

func testThereAreNoTwoDigitArmstrongNumbers() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isArmstrongNumber(10))
@Test("There are no two-digit Armstrong numbers", .enabled(if: RUNALL))
func testThereAreNoTwoDigitArmstrongNumbers() {
#expect(!isArmstrongNumber(10))
}

func testThreeDigitNumberThatIsAnArmstrongNumber() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isArmstrongNumber(153))
@Test("Three-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testThreeDigitNumberThatIsAnArmstrongNumber() {
#expect(isArmstrongNumber(153))
}

func testThreeDigitNumberThatIsNotAnArmstrongNumber() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isArmstrongNumber(100))
@Test("Three-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testThreeDigitNumberThatIsNotAnArmstrongNumber() {
#expect(!isArmstrongNumber(100))
}

func testFourDigitNumberThatIsAnArmstrongNumber() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isArmstrongNumber(9474))
@Test("Four-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testFourDigitNumberThatIsAnArmstrongNumber() {
#expect(isArmstrongNumber(9474))
}

func testFourDigitNumberThatIsNotAnArmstrongNumber() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isArmstrongNumber(9475))
@Test("Four-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testFourDigitNumberThatIsNotAnArmstrongNumber() {
#expect(!isArmstrongNumber(9475))
}

func testSevenDigitNumberThatIsAnArmstrongNumber() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertTrue(isArmstrongNumber(9_926_315))
@Test("Seven-digit number that is an Armstrong number", .enabled(if: RUNALL))
func testSevenDigitNumberThatIsAnArmstrongNumber() {
#expect(isArmstrongNumber(9_926_315))
}

func testSevenDigitNumberThatIsNotAnArmstrongNumber() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
XCTAssertFalse(isArmstrongNumber(9_926_314))
@Test("Seven-digit number that is not an Armstrong number", .enabled(if: RUNALL))
func testSevenDigitNumberThatIsNotAnArmstrongNumber() {
#expect(!isArmstrongNumber(9_926_314))
}
}
Loading