Files
swift-mirror/validation-test/stdlib/Concatenate.swift
Dave Abrahams ad43a596bd [stdlib] Retire the old lazy subsystem...
...replacing it with the new, after passing API review!

* The lazy free function has become a property.

* Before we could extend protocols, we lacked a means for value types to
  share implementations, and each new lazy algorithm had to be added to
  each of up to four types: LazySequence, LazyForwardCollection,
  LazyBidirectionalCollection, and LazyRandomAccessCollection. These
  generic adapters hid the usual algorithms by defining their own
  versions that returned new lazy generic adapters. Now users can extend
  just one of two protocols to do the same thing: LazySequenceType or
  LazyCollectionType.

* To avoid making the code duplication worse than it already was, the
  generic adapters mentioned above were used to add the lazy generic
  algorithms around simpler adapters such as MapSequence that just
  provided the basic requirements of SequenceType by applying a
  transformation to some base sequence, resulting in deeply nested
  generic types as shown here. Now, MapSequence is an instance of
  LazySequenceType (and is renamed LazyMapSequence), and thus transmits
  laziness to its algorithms automatically.

* Documentation comments have been rewritten.

* The .array property was retired

* various renamings

* A bunch of Gyb files were retired.

Swift SVN r30902
2015-08-01 03:52:13 +00:00

56 lines
1.8 KiB
Swift

//===--- Concatenate.swift - Tests for lazy/eager concatenate -------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
var ConcatenateTests = TestSuite("ConcatenateTests")
// Help the type checker (<rdar://problem/17897413> Slow type deduction)
typealias X = ContiguousArray<Range<Int>>
let samples: ContiguousArray<(Range<Int>, X)> = [
(0..<8, [ 1..<1, 0..<5, 7..<7, 5..<7, 7..<8 ] as X),
(0..<8, [ 0..<5, 7..<7, 5..<7, 7..<8 ] as X),
(0..<8, [ 1..<1, 0..<5, 7..<7, 5..<7, 7..<8, 11..<11 ] as X),
(0..<8, [ 0..<5, 7..<7, 5..<7, 7..<8, 11..<11 ] as X),
(0..<0, [ 11..<11 ] as X),
(0..<0, [ 3..<3, 11..<11 ] as X),
(0..<0, [] as X),
]
let expected = ContiguousArray(0..<8)
for (expected, source) in samples {
ConcatenateTests.test("forward-\(source)") {
checkBidirectionalCollection(expected, source.flatten())
}
ConcatenateTests.test("reverse-\(source)") {
// FIXME: separate 'expected' and 'reversed' variables are a workaround
// for: <rdar://problem/20789500>
let expected = ContiguousArray(expected.lazy.reverse())
let reversed = source.flatten().reverse()
checkBidirectionalCollection(expected, reversed)
}
ConcatenateTests.test("sequence-\(source)") {
checkSequence(
ContiguousArray(expected),
AnySequence(source).flatten())
}
}
runAllTests()