Files
swift-algorithms/Tests/SwiftAlgorithmsTests/IndexedTests.swift
T
Daniel Tull 93c8724c72 Add conformances to LazySequenceProtocol and LazyCollectionProtocol (#47)
* Conform Intersperse to LazySequenceProtocol when the base sequence does

* Add conformance to LazyCollectionProtocol

* Conform Indexed to LazyCollectionProtocol when Base conforms

* Rename XCTAssertLazy to XCTAssertLazySequence

* Add XCTAssertLazyCollection

* Add lazy test for Intersperse

* Update Indexed guide

* Add lazy conformances to SlidingWindows

* Update SlidingWindows guide
2020-12-01 15:47:13 -06:00

35 lines
1.1 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 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())
}
}