| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#, *}; |
| 3 | |
| 4 | use quickcheckrust-analyzer cargo quickcheck 1.1.0 crate/::{quickcheckrust-analyzer cargo quickcheck 1.1.0 tester/quickcheck()., TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#}; |
| 5 | |
| 6 | /// Covers every `std::ops::Range*` plus variants with exclusive start. |
| 7 | type RangeAnyrust-analyzer cargo quickcheck 1.1.0 RangeAny#<T> = (Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<T>, Boundrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#<T>); |
| 8 | |
| 9 | /// Mimic `RangeBounds::contains`, stabilized in Rust 1.35. |
| 10 | trait RangeBoundsrust-analyzer cargo quickcheck 1.1.0 RangeBounds#<T> { |
| 11 | fn containsrust-analyzer cargo quickcheck 1.1.0 RangeBounds#contains().(&self, _: &T) -> bool; |
| 12 | } |
| 13 | |
| 14 | impl<T: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#> RangeBoundsrust-analyzer cargo quickcheck 1.1.0 RangeBounds#<T> for RangeAnyrust-analyzer cargo quickcheck 1.1.0 RangeAny#<T> { |
| 15 | fn containsrust-analyzer cargo quickcheck 1.1.0 impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]contains().(&self, item: &T) -> bool { |
| 16 | (match &self.0 { |
| 17 | Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(start) => start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().item, |
| 18 | Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(start) => start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().item, |
| 19 | Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded# => true, |
| 20 | }) && (match &self.1 { |
| 21 | Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(end) => item rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]le().end, |
| 22 | Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(end) => item rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]lt().end, |
| 23 | Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded# => true, |
| 24 | }) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /// Checks conditions where `BTreeSet::range` panics: |
| 29 | /// - Panics if range start > end. |
| 30 | /// - Panics if range start == end and both bounds are Excluded. |
| 31 | fn panicsrust-analyzer cargo quickcheck 1.1.0 panics().<T: PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#>(range: RangeAnyrust-analyzer cargo quickcheck 1.1.0 RangeAny#<T>) -> bool { |
| 32 | match (&range.0, &range.1) { |
| 33 | (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(start), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(end)) => start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]ge().end, |
| 34 | (Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(start), Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(end) | Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(end)) |
| 35 | | (Excludedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Excluded#(start), Includedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Included#(end)) => start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialOrd<&B>`]gt().end, |
| 36 | (Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#, _) | (_, Unboundedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Bound#Unbounded#) => false, |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /// Checks that `BTreeSet::range` returns all items contained in the given |
| 41 | /// `range`. |
| 42 | fn check_rangerust-analyzer cargo quickcheck 1.1.0 check_range().(set: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<i32>, range: RangeAnyrust-analyzer cargo quickcheck 1.1.0 RangeAny#<i32>) -> TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult# { |
| 43 | if panicsrust-analyzer cargo quickcheck 1.1.0 panics().(range) { |
| 44 | TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#::discardrust-analyzer cargo quickcheck 1.1.0 tester/impl#[TestResult]discard().() |
| 45 | } else { |
| 46 | let xs: BTreeSetrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/BTreeSet#<_> = set.rangerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]range().(range).copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 47 | TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#::from_boolrust-analyzer cargo quickcheck 1.1.0 tester/impl#[TestResult]from_bool().( |
| 48 | set.iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|x| range.containsrust-analyzer cargo quickcheck 1.1.0 impl#[`(Bound<T>, Bound<T>)`][`RangeBounds<T>`]contains().(x) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().xs.containsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/set/impl#[`BTreeSet<T, A>`]contains().(x)), |
| 49 | ) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | fn mainrust-analyzer cargo quickcheck 1.1.0 main().() { |
| 54 | quickcheckrust-analyzer cargo quickcheck 1.1.0 tester/quickcheck().(check_rangerust-analyzer cargo quickcheck 1.1.0 check_range(). as fn(_, _) -> TestResultrust-analyzer cargo quickcheck 1.1.0 tester/TestResult#); |
| 55 | } |