|
| 1 | +//===--- GCDTests.swift ---------------------------------------*- swift -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import IntegerUtilities |
| 14 | +import XCTest |
| 15 | + |
| 16 | +final class IntegerUtilitiesGCDTests: XCTestCase { |
| 17 | + func testGCDInt() { |
| 18 | + XCTAssertEqual(Int.gcd(0, 0), 0) |
| 19 | + XCTAssertEqual(Int.gcd(0, 1), 1) |
| 20 | + XCTAssertEqual(Int.gcd(1, 0), 1) |
| 21 | + XCTAssertEqual(Int.gcd(0, -1), 1) |
| 22 | + XCTAssertEqual(Int.gcd(1, 1), 1) |
| 23 | + XCTAssertEqual(Int.gcd(1, 2), 1) |
| 24 | + XCTAssertEqual(Int.gcd(2, 2), 2) |
| 25 | + XCTAssertEqual(Int.gcd(4, 2), 2) |
| 26 | + XCTAssertEqual(Int.gcd(6, 8), 2) |
| 27 | + XCTAssertEqual(Int.gcd(77, 91), 7) |
| 28 | + XCTAssertEqual(Int.gcd(24, -36), 12) |
| 29 | + XCTAssertEqual(Int.gcd(-24, -36), 12) |
| 30 | + XCTAssertEqual(Int.gcd(51, 34), 17) |
| 31 | + XCTAssertEqual(Int.gcd(64, 96), 32) |
| 32 | + XCTAssertEqual(Int.gcd(-64, 96), 32) |
| 33 | + XCTAssertEqual(Int.gcd(4*7*19, 27*25), 1) |
| 34 | + XCTAssertEqual(Int.gcd(16*315, 11*315), 315) |
| 35 | + XCTAssertEqual(Int.gcd(97*67*53*27*8, 83*67*53*9*32), 67*53*9*8) |
| 36 | + XCTAssertEqual(Int.gcd(Int.min, 2), 2) |
| 37 | + } |
| 38 | +} |
0 commit comments