Sha256: 56a48e518c63f4e6495f5e619de5baef582b88d971a4b670c5119d1c5ded2e88

Contents?: true

Size: 1.53 KB

Versions: 59

Compression:

Stored size: 1.53 KB

Contents

import XCTest
@testable import PythagoreanTriplet

class PythagoreanTripletTests: XCTestCase {
    func testSum() {
        XCTAssertEqual(12, Triplet(3, 4, 5).sum)
    }

    func testProduct() {
        XCTAssertEqual(60, Triplet(3, 4, 5).product)
    }

    func testPythagorean() {
        XCTAssertTrue(Triplet(3, 4, 5).isPythagorean)
    }

    func testNotPythagorean() {
        XCTAssertTrue(!Triplet(5, 6, 7).isPythagorean)
    }

    func testTripletsUpTo10() {
        let triplets = Triplet.Where(maxFactor: 10)
        let products = triplets.map {$0.product}.sorted(by: <)
        XCTAssertEqual([60, 480], products)
    }

    func testTripletsFrom11UpTo20() {
        let triplets = Triplet.Where(11, maxFactor: 20)
        let products = triplets.map {$0.product}.sorted(by: <)
        XCTAssertEqual([3840], products)
    }

    func testTripletsWhereSumX() {
        let triplets = Triplet.Where( maxFactor: 100, sum: 180)
        let products = triplets.map {$0.product}.sorted(by: <)
        XCTAssertEqual([118_080, 168_480, 202_500], products)
    }

    static var allTests: [(String, (PythagoreanTripletTests) -> () throws -> Void)] {
        return [
            ("testSum", testSum),
            ("testProduct", testProduct),
            ("testPythagorean", testPythagorean),
            ("testNotPythagorean", testNotPythagorean),
            ("testTripletsUpTo10", testTripletsUpTo10),
            ("testTripletsFrom11UpTo20", testTripletsFrom11UpTo20),
            ("testTripletsWhereSumX", testTripletsWhereSumX),
        ]
    }
}

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
trackler-2.0.8.9 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.8 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.7 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.6 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.5 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.4 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.3 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.2 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.1 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.7.0 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.44 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.43 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.42 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.41 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.40 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.39 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.38 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.37 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.36 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.6.35 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift