Skip to content

Commit

Permalink
Update Swift tools version to 6.0 and refactor tests for Collatz Conj…
Browse files Browse the repository at this point in the history
…ecture
  • Loading branch information
meatball133 committed Dec 18, 2024
1 parent 30f8e4c commit e9114c9
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 318 deletions.
24 changes: 13 additions & 11 deletions exercises/practice/clock/.meta/template.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
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 {
{% outer: for case in cases %}
{%- for subCases in case.cases %}
{%- if forloop.outer.first and forloop.first %}
func test{{subCases.description |camelCase }}() {
@Test("{{subCases.description}}")
{%- else %}
func test{{subCases.description |camelCase }}() throws {
try XCTSkipIf(true && !runAll) // change true to false to run this test
@Test("{{subCases.description}}", .enabled(if: RUNALL))
{%- endif %}
func test{{subCases.description |camelCase }}() {
{%- if subCases.property == "create" %}
XCTAssertEqual(Clock(hours: {{subCases.input.hour}}, minutes: {{subCases.input.minute}}).description, "{{subCases.expected}}")
#expect(Clock(hours: {{subCases.input.hour}}, minutes: {{subCases.input.minute}}).description == "{{subCases.expected}}")
{%- elif subCases.property == "add"%}
let clock = Clock(hours: {{subCases.input.hour}}, minutes: {{subCases.input.minute}}).add(minutes: {{subCases.input.value}})
XCTAssertEqual(clock.description, "{{subCases.expected}}")
#expect(clock.description == "{{subCases.expected}}")
{%- elif subCases.property == "subtract" %}
let clock = Clock(hours: {{subCases.input.hour}}, minutes: {{subCases.input.minute}}).subtract(minutes: {{subCases.input.value}})
XCTAssertEqual(clock.description, "{{subCases.expected}}")
#expect(clock.description == "{{subCases.expected}}")
{%- elif subCases.property == "equal" %}
let clock1 = Clock(hours: {{subCases.input.clock1.hour}}, minutes: {{subCases.input.clock1.minute}})
let clock2 = Clock(hours: {{subCases.input.clock2.hour}}, minutes: {{subCases.input.clock2.minute}})
{%- if subCases.expected %}
XCTAssertEqual(clock1, clock2)
#expect(clock1 == clock2)
{%- else %}
XCTAssertNotEqual(clock1, clock2)
#expect(clock1 != clock2)
{%- endif %}
{%- endif %}
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/clock/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
Loading

0 comments on commit e9114c9

Please sign in to comment.