-
Notifications
You must be signed in to change notification settings - Fork 445
/
Copy pathAccumulateTests.swift
56 lines (51 loc) · 1.78 KB
/
AccumulateTests.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
51
52
53
54
55
56
//===----------------------------------------------------------------------===//
//
// 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
/// Unit tests for the `accumulate(via:)` and `disperse(via:)` methods.
final class AccumulateTests: XCTestCase {
/// Check that nothing happens with empty collections.
func testEmpty() {
var empty = EmptyCollection<Double>()
XCTAssertEqualSequences(empty, [])
empty.accumulate(via: +)
XCTAssertEqualSequences(empty, [])
empty.disperse(via: -)
XCTAssertEqualSequences(empty, [])
}
/// Check that nothing happens with one-element collections.
func testSingle() {
var single = CollectionOfOne(1.1)
XCTAssertEqualSequences(single, [1.1])
single.accumulate(via: +)
XCTAssertEqualSequences(single, [1.1])
single.disperse(via: -)
XCTAssertEqualSequences(single, [1.1])
}
/// Check a two-element collection.
func testDouble() {
var sample = [5, 2]
XCTAssertEqualSequences(sample, [5, 2])
sample.accumulate(via: *)
XCTAssertEqualSequences(sample, [5, 10])
sample.disperse(via: /)
XCTAssertEqualSequences(sample, [5, 2])
}
/// Check a long collection.
func testLong() {
var sample1 = Array(repeating: 1, count: 5)
XCTAssertEqualSequences(sample1, repeatElement(1, count: 5))
sample1.accumulate(via: +)
XCTAssertEqualSequences(sample1, 1...5)
sample1.disperse(via: -)
XCTAssertEqualSequences(sample1, repeatElement(1, count: 5))
}
}