diff options
Diffstat (limited to 'primrose/crates/primrose-library/src/treeset.rs')
-rw-r--r-- | primrose/crates/primrose-library/src/treeset.rs | 215 |
1 files changed, 108 insertions, 107 deletions
diff --git a/primrose/crates/primrose-library/src/treeset.rs b/primrose/crates/primrose-library/src/treeset.rs index 6e016a2..cf0fbb4 100644 --- a/primrose/crates/primrose-library/src/treeset.rs +++ b/primrose/crates/primrose-library/src/treeset.rs @@ -2,17 +2,8 @@ rust-btreeset-spec std::collections::BTreeSet *ENDLIBSPEC-NAME*/ -use crate::proptest::*; use crate::traits::{Container, Indexable}; -use std::collections::BTreeSet; -use std::iter::FromIterator; - -use proptest::collection::btree_set; -use proptest::prelude::*; - -use im::conslist; -use im::conslist::ConsList; -use std::sync::Arc; +pub use std::collections::BTreeSet; /*IMPL* Container @@ -151,112 +142,122 @@ impl<T: Ord> Indexable<T> for BTreeSet<T> { } } -fn abstraction<T>(t: BTreeSet<T>) -> ConsList<T> { - let list: ConsList<T> = ConsList::from_iter(t); - list -} +#[cfg(test)] +mod test { + use super::*; -proptest! { - #![proptest_config(ProptestConfig { - cases: 100, .. ProptestConfig::default() - })] - #[test] - fn test_btree_len(ref mut t in btree_set(".*", 0..100)) { - let abs_list = abstraction(t.clone()); - // pre: our list model is a sorted and unique list - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - assert_eq!(Container::<String>::len(t), abs_list.len()); - assert_eq!(abstraction(t.clone()), abs_list); - } + use crate::proptest::*; + use im::conslist::ConsList; + use proptest::{collection::btree_set, prelude::*}; + use std::iter::FromIterator; - #[test] - fn test_btree_contains(ref mut t in btree_set(".*", 0..100), a in ".*") { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - assert_eq!(Container::<String>::contains(t, &a), contains(&abs_list, &a)); - assert_eq!(abstraction(t.clone()), abs_list); + fn abstraction<T>(t: BTreeSet<T>) -> ConsList<T> { + let list: ConsList<T> = ConsList::from_iter(t); + list } - #[test] - fn test_btree_is_empty(ref mut t in btree_set(".*", 0..100)) { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - assert_eq!(Container::<String>::is_empty(t), abs_list.is_empty()); - assert_eq!(abstraction(t.clone()), abs_list); - } + proptest! { + #![proptest_config(ProptestConfig { + cases: 100, .. ProptestConfig::default() + })] + #[test] + fn test_btree_len(ref mut t in btree_set(".*", 0..100)) { + let abs_list = abstraction(t.clone()); + // pre: our list model is a sorted and unique list + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + assert_eq!(Container::<String>::len(t), abs_list.len()); + assert_eq!(abstraction(t.clone()), abs_list); + } - #[test] - fn test_btree_insert(ref mut t in btree_set(".*", 0..100), a in ".*") { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - let after_list = unique(&abs_list.append(conslist![a.clone()]).sort()); - Container::<String>::insert(t, a.clone()); - assert_eq!(abstraction(t.clone()), after_list); - } + #[test] + fn test_btree_contains(ref mut t in btree_set(".*", 0..100), a in ".*") { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + assert_eq!(Container::<String>::contains(t, &a), contains(&abs_list, &a)); + assert_eq!(abstraction(t.clone()), abs_list); + } - #[test] - fn test_btree_clear(ref mut t in btree_set(".*", 0..100)) { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - let after_list = clear(&abs_list); - Container::<String>::clear(t); - assert_eq!(abstraction(t.clone()), after_list); - } + #[test] + fn test_btree_is_empty(ref mut t in btree_set(".*", 0..100)) { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + assert_eq!(Container::<String>::is_empty(t), abs_list.is_empty()); + assert_eq!(abstraction(t.clone()), abs_list); + } - #[test] - fn test_btree_remove(ref mut t in btree_set(".*", 0..100), a in ".*") { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - let (after_list, abs_elem) = remove(&abs_list, a.clone()); - let elem = Container::<String>::remove(t, a.clone()); - assert_eq!(abstraction(t.clone()), after_list); - assert_eq!(elem, abs_elem); - } + #[test] + fn test_btree_insert(ref mut t in btree_set(".*", 0..100), a in ".*") { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + let after_list = unique(&abs_list.append(conslist![a.clone()]).sort()); + Container::<String>::insert(t, a.clone()); + assert_eq!(abstraction(t.clone()), after_list); + } - #[test] - fn test_btree_first(ref mut t in btree_set(".*", 0..100)) { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - let elem = Indexable::<String>::first(t); - let abs_first = first(&abs_list); - assert_eq!(elem, abs_first); - assert_eq!(abstraction(t.clone()), abs_list); - } + #[test] + fn test_btree_clear(ref mut t in btree_set(".*", 0..100)) { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + let after_list = clear(&abs_list); + Container::<String>::clear(t); + assert_eq!(abstraction(t.clone()), after_list); + } - #[test] - fn test_btree_last(ref mut t in btree_set(".*", 0..100)) { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - let elem = Indexable::<String>::last(t); - let abs_last = last(&abs_list); - assert_eq!(elem, abs_last); - assert_eq!(abstraction(t.clone()), abs_list); - } + #[test] + fn test_btree_remove(ref mut t in btree_set(".*", 0..100), a in ".*") { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + let (after_list, abs_elem) = remove(&abs_list, a.clone()); + let elem = Container::<String>::remove(t, a.clone()); + assert_eq!(abstraction(t.clone()), after_list); + assert_eq!(elem, abs_elem); + } - #[test] - fn test_btree_nth(ref mut t in btree_set(".*", 0..100), n in 0usize..100) { - let abs_list = abstraction(t.clone()); - //pre - assert_eq!(abs_list, unique(&abs_list.sort())); - //post - let elem = Indexable::<String>::nth(t, n.clone()); - let abs_nth = nth(&abs_list, n); - assert_eq!(elem, abs_nth); - assert_eq!(abstraction(t.clone()), abs_list); + #[test] + fn test_btree_first(ref mut t in btree_set(".*", 0..100)) { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + let elem = Indexable::<String>::first(t); + let abs_first = first(&abs_list); + assert_eq!(elem, abs_first); + assert_eq!(abstraction(t.clone()), abs_list); + } + + #[test] + fn test_btree_last(ref mut t in btree_set(".*", 0..100)) { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + let elem = Indexable::<String>::last(t); + let abs_last = last(&abs_list); + assert_eq!(elem, abs_last); + assert_eq!(abstraction(t.clone()), abs_list); + } + + #[test] + fn test_btree_nth(ref mut t in btree_set(".*", 0..100), n in 0usize..100) { + let abs_list = abstraction(t.clone()); + //pre + assert_eq!(abs_list, unique(&abs_list.sort())); + //post + let elem = Indexable::<String>::nth(t, n.clone()); + let abs_nth = nth(&abs_list, n); + assert_eq!(elem, abs_nth); + assert_eq!(abstraction(t.clone()), abs_list); + } } } |