blob: fd489af2ae4283dd05134a81a56c7054bcd12571 [file] [log] [blame]
/*
This source file is part of the Swift.org open source project
Copyright 2016 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 Swift project authors
*/
import XCTest
import Basic
typealias OrderedSet = Basic.OrderedSet
class OrderedSetTests: XCTestCase {
func testBasics() {
// Create an empty set.
var set = OrderedSet<String>()
XCTAssertTrue(set.isEmpty)
XCTAssertEqual(set.contents, [])
// Create a new set with some strings.
set = OrderedSet(["one", "two", "three"])
XCTAssertFalse(set.isEmpty)
XCTAssertEqual(set.count, 3)
XCTAssertEqual(set[0], "one")
XCTAssertEqual(set[1], "two")
XCTAssertEqual(set[2], "three")
XCTAssertEqual(set.contents, ["one", "two", "three"])
// Try adding the same item again - the set should be unchanged.
XCTAssertEqual(set.append("two"), false)
XCTAssertEqual(set.count, 3)
XCTAssertEqual(set[0], "one")
XCTAssertEqual(set[1], "two")
XCTAssertEqual(set[2], "three")
// Remove the last element.
let three = set.removeLast()
XCTAssertEqual(set.count, 2)
XCTAssertEqual(set[0], "one")
XCTAssertEqual(set[1], "two")
XCTAssertEqual(three, "three")
// Remove all the objects.
set.removeAll(keepingCapacity: true)
XCTAssertEqual(set.count, 0)
XCTAssertTrue(set.isEmpty)
XCTAssertEqual(set.contents, [])
}
static var allTests = [
("testBasics", testBasics),
]
}