-
Notifications
You must be signed in to change notification settings - Fork 440
/
IndexedTests.swift
34 lines (29 loc) · 1.06 KB
/
IndexedTests.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
//===----------------------------------------------------------------------===//
//
// 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 IndexedTests: XCTestCase {
func testIndexed() {
let s = "ABCDEFGHIJKLMNOP"
let si = s.indexed()
XCTAssertEqual(s.startIndex, si.first!.index)
XCTAssertEqual("A", si.first!.element)
XCTAssertEqual(s.index(before: s.endIndex), si.last!.index)
XCTAssertEqual("P", si.last!.element)
let indexOfG = si.first(where: { $0.element == "G" })!.index
XCTAssertEqual("G", s[indexOfG])
let indexOfI = si.last(where: { $0.element == "I" })!.index
XCTAssertEqual("I", s[indexOfI])
}
func testIndexedLazy() {
XCTAssertLazyCollection("ABCD".lazy.indexed())
}
}