Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from lorentey/set-API-checker
[test] Check baseline API expectations for set-like types
- Loading branch information
Showing
9 changed files
with
173 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Sources/_CollectionsTestSupport/Utilities/SetAPIChecker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift Collections open source project | ||
// | ||
// Copyright (c) 2022 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// A test protocol for validating that set-like types implement users' | ||
/// baseline expectations. | ||
/// | ||
/// To ensure maximum utility, this protocol refines neither `Collection` nor | ||
/// `SetAlgebra` although it does share some of the same requirements. | ||
public protocol SetAPIChecker { | ||
associatedtype Element | ||
associatedtype Index | ||
|
||
var isEmpty: Bool { get } | ||
var count: Int { get } | ||
|
||
init() | ||
|
||
mutating func remove(at index: Index) -> Element | ||
|
||
func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> Self | ||
|
||
func isSubset<S: Sequence>(of other: S) -> Bool | ||
where S.Element == Element | ||
|
||
func isSuperset<S: Sequence>(of other: S) -> Bool | ||
where S.Element == Element | ||
|
||
func isStrictSubset<S: Sequence>(of other: S) -> Bool | ||
where S.Element == Element | ||
|
||
func isStrictSuperset<S: Sequence>(of other: S) -> Bool | ||
where S.Element == Element | ||
|
||
func isDisjoint<S: Sequence>(with other: S) -> Bool | ||
where S.Element == Element | ||
|
||
|
||
func intersection<S: Sequence>(_ other: S) -> Self | ||
where S.Element == Element | ||
|
||
func union<S: Sequence>(_ other: __owned S) -> Self | ||
where S.Element == Element | ||
|
||
__consuming func subtracting<S: Sequence>(_ other: S) -> Self | ||
where S.Element == Element | ||
|
||
func symmetricDifference<S: Sequence>(_ other: __owned S) -> Self | ||
where S.Element == Element | ||
|
||
mutating func formIntersection<S: Sequence>(_ other: S) | ||
where S.Element == Element | ||
|
||
mutating func formUnion<S: Sequence>(_ other: __owned S) | ||
where S.Element == Element | ||
|
||
mutating func subtract<S: Sequence>(_ other: S) | ||
where S.Element == Element | ||
|
||
mutating func formSymmetricDifference<S: Sequence>(_ other: __owned S) | ||
where S.Element == Element | ||
} | ||
|
||
extension Set: SetAPIChecker {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters