Files
Nate Cook 66ae806bbe Enable CI format check (#253)
* Incorporate swift-format formatting fixes
* Resolve linting issues
* Doc edits, mostly to fix linter-identified issues
* Early exit improvements
* Indentation fixes
* Line lengths to 80 maximum
* Implement case binding rule, plus argument line break improvements
* Implement NoForceUnwrap rule
* Format the tests, as well
* Stop masquerading as XCTest
2025-03-05 09:11:17 -06:00

58 lines
1.7 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 Algorithms
import XCTest
final class UniqueTests: XCTestCase {
func testUnique() {
let a = repeatElement(1...10, count: 15).joined().shuffled()
let b = a.uniqued()
XCTAssertEqual(b.sorted(), Set(a).sorted())
XCTAssertEqual(10, Array(b).count)
let c: [Int] = []
expectEqualSequences(c.uniqued(), [])
let d = Array(repeating: 1, count: 10)
expectEqualSequences(d.uniqued(), [1])
}
func testUniqueOn() {
let a = [
"Albemarle", "Abeforth", "Astrology", "Brandywine", "Beatrice", "Axiom",
]
let b = a.uniqued(on: { $0.first })
XCTAssertEqual(["Albemarle", "Brandywine"], b)
let c: [Int] = []
XCTAssertEqual(c.uniqued(on: { $0.bitWidth }), [])
let d = Array(repeating: "Andromeda", count: 10)
expectEqualSequences(d.uniqued(on: { $0.first }), ["Andromeda"])
}
func testLazyUniqueOn() {
let a = [
"Albemarle", "Abeforth", "Astrology", "Brandywine", "Beatrice", "Axiom",
]
let b = a.lazy.uniqued(on: { $0.first })
expectEqualSequences(b, ["Albemarle", "Brandywine"])
requireLazySequence(b)
let c: [Int] = []
expectEqualSequences(c.lazy.uniqued(on: { $0.bitWidth }), [])
let d = Array(repeating: "Andromeda", count: 10)
expectEqualSequences(d.lazy.uniqued(on: { $0.first }), ["Andromeda"])
}
}