mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-30 04:48:43 +00:00
* Change representation of `Product2`'s `endIndex` * Fix `Product2.index(before:)` * Fix `Product2.distance(from:to:)` * Make comment more specific
41 lines
1.2 KiB
Swift
41 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Algorithms open source project
|
|
//
|
|
// Copyright (c) 2020 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import XCTest
|
|
import Algorithms
|
|
|
|
final class ProductTests: XCTestCase {
|
|
func testProduct() {
|
|
XCTAssertEqualSequences(
|
|
[(1, "A" as Character), (1, "B"), (2, "A"), (2, "B")],
|
|
product(1...2, "AB"),
|
|
by: ==)
|
|
|
|
XCTAssertEqualSequences(product(1...10, ""), [], by: ==)
|
|
XCTAssertEqualSequences(product("", 1...10), [], by: ==)
|
|
}
|
|
|
|
func testProductReversed() {
|
|
XCTAssertEqualSequences(
|
|
[(2, "B" as Character), (2, "A"), (1, "B"), (1, "A")],
|
|
product(1...2, "AB").reversed(),
|
|
by: ==)
|
|
|
|
XCTAssertEqualSequences(product(1...10, "").reversed(), [], by: ==)
|
|
XCTAssertEqualSequences(product("", 1...10).reversed(), [], by: ==)
|
|
}
|
|
|
|
func testProductDistanceFromTo() {
|
|
let p = product([1, 2], "abc")
|
|
XCTAssertEqual(p.distance(from: p.startIndex, to: p.endIndex), 6)
|
|
}
|
|
}
|