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.30 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.29 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.28 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.27 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.26 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.24 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.23 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.22 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.21 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.20 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.19 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.18 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.17 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.16 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.15 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.14 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.13 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.12 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.11 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift
trackler-2.0.8.10 tracks/swift/exercises/pythagorean-triplet/Tests/PythagoreanTripletTests/PythagoreanTripletTests.swift