-
Notifications
You must be signed in to change notification settings - Fork 152
/
TestSetAlgebra.swift
50 lines (45 loc) · 1.42 KB
/
TestSetAlgebra.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Async Algorithms open source project
//
// Copyright (c) 2022 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 AsyncAlgorithms
final class TestSetAlgebra: XCTestCase {
func test_Set() async {
let source = [1, 2, 3]
let expected = Set(source)
let actual = await Set(source.async)
XCTAssertEqual(expected, actual)
}
func test_Set_duplicate() async {
let source = [1, 2, 3, 3]
let expected = Set(source)
let actual = await Set(source.async)
XCTAssertEqual(expected, actual)
}
func test_IndexSet() async {
let source = [1, 2, 3]
let expected = IndexSet(source)
let actual = await IndexSet(source.async)
XCTAssertEqual(expected, actual)
}
func test_throwing() async {
let source = Array([1, 2, 3, 4, 5, 6])
let input = source.async.map { (value: Int) async throws -> Int in
if value == 4 { throw NSError(domain: NSCocoaErrorDomain, code: -1, userInfo: nil) }
return value
}
do {
_ = try await Set(input)
XCTFail()
} catch {
XCTAssertEqual((error as NSError).code, -1)
}
}
}