aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAria <me@aria.rip>2023-10-24 18:08:48 +0100
committerAria <me@aria.rip>2023-10-24 18:08:48 +0100
commit44011e5d781ff7f56182acdc3a5501db343af03f (patch)
tree1760f44b54026e44cac476d187af6bcd9eb695a9
parent78cc657a73c6ea33cf8db49f775a33a47acf4d05 (diff)
style(primrose-library): lints for primrose library
-rw-r--r--primrose/crates/primrose-library/src/eager_sorted_vector.rs240
-rw-r--r--primrose/crates/primrose-library/src/eager_unique_vector.rs229
-rw-r--r--primrose/crates/primrose-library/src/hashset.rs151
-rw-r--r--primrose/crates/primrose-library/src/lazy_sorted_vector.rs248
-rw-r--r--primrose/crates/primrose-library/src/lazy_unique_vector.rs223
-rw-r--r--primrose/crates/primrose-library/src/lib.rs28
-rw-r--r--primrose/crates/primrose-library/src/list.rs194
-rw-r--r--primrose/crates/primrose-library/src/proptest/mod.rs4
-rw-r--r--primrose/crates/primrose-library/src/proptest/strategies.rs5
-rw-r--r--primrose/crates/primrose-library/src/traits.rs2
-rw-r--r--primrose/crates/primrose-library/src/treeset.rs215
-rw-r--r--primrose/crates/primrose-library/src/vector.rs191
12 files changed, 874 insertions, 856 deletions
diff --git a/primrose/crates/primrose-library/src/eager_sorted_vector.rs b/primrose/crates/primrose-library/src/eager_sorted_vector.rs
index e7bfca2..d45e924 100644
--- a/primrose/crates/primrose-library/src/eager_sorted_vector.rs
+++ b/primrose/crates/primrose-library/src/eager_sorted_vector.rs
@@ -1,22 +1,13 @@
/*LIBSPEC-NAME*
-rust-eager-sorted-vec-spec primrose_library::eager_sorted_vector::EagerSortedVec
+rust-eager-sorted-vec-spec primrose_library::EagerSortedVec
*ENDLIBSPEC-NAME*/
-use crate::traits::{Container, Indexable, Stack};
-use std::iter::FromIterator;
-use std::ops::Deref;
+use crate::traits::{Container, Indexable};
+
use std::slice::Iter;
use std::vec::Vec;
-use crate::proptest::strategies::eager_sorted_vec;
-use crate::proptest::*;
-use proptest::prelude::*;
-
-use im::conslist;
-use im::conslist::ConsList;
-use std::sync::Arc;
-
-// A Sorted Vector
+/// A Sorted Vector
#[derive(Debug, Clone)]
pub struct EagerSortedVec<T> {
v: Vec<T>,
@@ -214,116 +205,125 @@ impl<T: Ord> Indexable<T> for EagerSortedVec<T> {
}
}
-fn abstraction<T>(v: EagerSortedVec<T>) -> ConsList<T>
-where
- T: Ord,
-{
- let list: ConsList<T> = ConsList::from(v.to_vec());
- list
-}
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::proptest::{strategies::eager_sorted_vec, *};
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
-
- #[test]
- fn test_eager_sorted_vec_len(ref mut v in eager_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- assert_eq!(Container::<String>::len(v), abs_list.len());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
-
- #[test]
- fn test_eager_sorted_vec_contains(ref mut v in eager_sorted_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(v.clone()), abs_list);
- }
-
- #[test]
- fn test_eager_sorted_vec_is_empty(ref mut v in eager_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
-
- #[test]
- fn test_eager_sorted_vec_insert(ref mut v in eager_sorted_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let after_list = abs_list.append(conslist![a.clone()]).sort();
- Container::<String>::insert(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- }
-
- #[test]
- fn test_eager_sorted_vec_clear(ref mut v in eager_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let after_list = clear(&abs_list);
- Container::<String>::clear(v);
- assert_eq!(abstraction(v.clone()), after_list);
- }
-
- #[test]
- fn test_eager_sorted_vec_remove(ref mut v in eager_sorted_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let (after_list, abs_elem) = remove(&abs_list, a.clone());
- let elem = Container::<String>::remove(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- assert_eq!(elem, abs_elem);
- }
-
- #[test]
- fn test_eager_sorted_vec_first(ref mut v in eager_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let elem = Indexable::<String>::first(v);
- let abs_first = first(&abs_list);
- assert_eq!(elem, abs_first);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ use im::conslist::ConsList;
+ use proptest::prelude::*;
- #[test]
- fn test_eager_sorted_vec_last(ref mut v in eager_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let elem = Indexable::<String>::last(v);
- let abs_last = last(&abs_list);
- assert_eq!(elem, abs_last);
- assert_eq!(abstraction(v.clone()), abs_list);
+ fn abstraction<T>(v: EagerSortedVec<T>) -> ConsList<T>
+ where
+ T: Ord,
+ {
+ let list: ConsList<T> = ConsList::from(v.to_vec());
+ list
}
- #[test]
- fn test_eager_sorted_vec_nth(ref mut v in eager_sorted_vec(".*", 0..100), n in 0usize..100) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let elem = Indexable::<String>::nth(v, n.clone());
- let abs_nth = nth(&abs_list, n);
- assert_eq!(elem, abs_nth);
- assert_eq!(abstraction(v.clone()), abs_list);
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
+
+ #[test]
+ fn test_eager_sorted_vec_len(ref mut v in eager_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ assert_eq!(Container::<String>::len(v), abs_list.len());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_contains(ref mut v in eager_sorted_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_is_empty(ref mut v in eager_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_insert(ref mut v in eager_sorted_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let after_list = abs_list.append(conslist![a.clone()]).sort();
+ Container::<String>::insert(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_clear(ref mut v in eager_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let after_list = clear(&abs_list);
+ Container::<String>::clear(v);
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_remove(ref mut v in eager_sorted_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let (after_list, abs_elem) = remove(&abs_list, a.clone());
+ let elem = Container::<String>::remove(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_first(ref mut v in eager_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let elem = Indexable::<String>::first(v);
+ let abs_first = first(&abs_list);
+ assert_eq!(elem, abs_first);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_last(ref mut v in eager_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let elem = Indexable::<String>::last(v);
+ let abs_last = last(&abs_list);
+ assert_eq!(elem, abs_last);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_eager_sorted_vec_nth(ref mut v in eager_sorted_vec(".*", 0..100), n in 0usize..100) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let elem = Indexable::<String>::nth(v, n.clone());
+ let abs_nth = nth(&abs_list, n);
+ assert_eq!(elem, abs_nth);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/eager_unique_vector.rs b/primrose/crates/primrose-library/src/eager_unique_vector.rs
index 848a286..21e133e 100644
--- a/primrose/crates/primrose-library/src/eager_unique_vector.rs
+++ b/primrose/crates/primrose-library/src/eager_unique_vector.rs
@@ -1,22 +1,13 @@
/*LIBSPEC-NAME*
-rust-eager-unique-vec-spec primrose::library::eager_unique_vector::EagerUniqueVec
+rust-eager-unique-vec-spec primrose::library::EagerUniqueVec
*ENDLIBSPEC-NAME*/
-use crate::traits::{Container, Indexable, Stack};
-use std::iter::FromIterator;
-use std::ops::Deref;
+use crate::traits::{Container, Indexable};
+
use std::slice::Iter;
use std::vec::Vec;
-use crate::proptest::strategies::eager_unique_vec;
-use crate::proptest::*;
-use proptest::prelude::*;
-
-use im::conslist;
-use im::conslist::ConsList;
-use std::sync::Arc;
-
-// A Unique Vector
+/// A Unique Vector
#[derive(Debug, Clone)]
pub struct EagerUniqueVec<T> {
v: Vec<T>,
@@ -221,116 +212,124 @@ impl<T: PartialEq> Indexable<T> for EagerUniqueVec<T> {
}
}
-fn abstraction<T>(v: EagerUniqueVec<T>) -> ConsList<T>
-where
- T: PartialEq,
-{
- let list: ConsList<T> = ConsList::from(v.to_vec());
- list
-}
-
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
-
- #[test]
- fn test_eager_unique_vec_len(ref mut v in eager_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- assert_eq!(Container::<String>::len(v), abs_list.len());
- assert_eq!(abstraction(v.clone()), abs_list);
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::proptest::{strategies::eager_unique_vec, *};
+ use im::conslist::ConsList;
+ use proptest::prelude::*;
+
+ fn abstraction<T>(v: EagerUniqueVec<T>) -> ConsList<T>
+ where
+ T: PartialEq,
+ {
+ let list: ConsList<T> = ConsList::from(v.to_vec());
+ list
}
- #[test]
- fn test_eager_unique_vec_contains(ref mut v in eager_unique_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
+
+ #[test]
+ fn test_eager_unique_vec_len(ref mut v in eager_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ assert_eq!(Container::<String>::len(v), abs_list.len());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_eager_unique_vec_is_empty(ref mut v in eager_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_eager_unique_vec_contains(ref mut v in eager_unique_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_eager_unique_vec_insert(ref mut v in eager_unique_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- let after_list = unique(&abs_list.append(conslist![a.clone()]));
- Container::<String>::insert(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_eager_unique_vec_is_empty(ref mut v in eager_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_eager_unique_vec_clear(ref mut v in eager_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- let after_list = clear(&abs_list);
- Container::<String>::clear(v);
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_eager_unique_vec_insert(ref mut v in eager_unique_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ let after_list = unique(&abs_list.append(conslist![a.clone()]));
+ Container::<String>::insert(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_eager_unique_vec_remove(ref mut v in eager_unique_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- let (after_list, abs_elem) = remove(&abs_list, a.clone());
- let elem = Container::<String>::remove(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- assert_eq!(elem, abs_elem);
- }
+ #[test]
+ fn test_eager_unique_vec_clear(ref mut v in eager_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ let after_list = clear(&abs_list);
+ Container::<String>::clear(v);
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_eager_unique_vec_first(ref mut v in eager_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- let elem = Indexable::<String>::first(v);
- let abs_first = first(&abs_list);
- assert_eq!(elem, abs_first);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_eager_unique_vec_remove(ref mut v in eager_unique_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ let (after_list, abs_elem) = remove(&abs_list, a.clone());
+ let elem = Container::<String>::remove(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
- #[test]
- fn test_eager_unique_vec_last(ref mut v in eager_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- let elem = Indexable::<String>::last(v);
- let abs_last = last(&abs_list);
- assert_eq!(elem, abs_last);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_eager_unique_vec_first(ref mut v in eager_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ let elem = Indexable::<String>::first(v);
+ let abs_first = first(&abs_list);
+ assert_eq!(elem, abs_first);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_eager_unique_vec_nth(ref mut v in eager_unique_vec(".*", 0..100), n in 0usize..100) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list));
- //post
- let elem = Indexable::<String>::nth(v, n.clone());
- let abs_nth = nth(&abs_list, n);
- assert_eq!(elem, abs_nth);
- assert_eq!(abstraction(v.clone()), abs_list);
+ #[test]
+ fn test_eager_unique_vec_last(ref mut v in eager_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ let elem = Indexable::<String>::last(v);
+ let abs_last = last(&abs_list);
+ assert_eq!(elem, abs_last);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_eager_unique_vec_nth(ref mut v in eager_unique_vec(".*", 0..100), n in 0usize..100) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list));
+ //post
+ let elem = Indexable::<String>::nth(v, n.clone());
+ let abs_nth = nth(&abs_list, n);
+ assert_eq!(elem, abs_nth);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/hashset.rs b/primrose/crates/primrose-library/src/hashset.rs
index 06f8df7..d7d8915 100644
--- a/primrose/crates/primrose-library/src/hashset.rs
+++ b/primrose/crates/primrose-library/src/hashset.rs
@@ -3,18 +3,9 @@ rust-hashset-spec std::collections::HashSet
*ENDLIBSPEC-NAME*/
use crate::traits::Container;
-use std::collections::HashSet;
+pub use std::collections::HashSet;
use std::hash::Hash;
-use crate::proptest::*;
-use proptest::collection::hash_set;
-use proptest::prelude::*;
-
-use im::conslist;
-use im::conslist::ConsList;
-use std::iter::FromIterator;
-use std::sync::Arc;
-
/*IMPL*
Container
*ENDIMPL*/
@@ -101,77 +92,87 @@ impl<T: Ord + Hash> Container<T> for HashSet<T> {
}
}
-fn abstraction<T: Ord>(h: HashSet<T>) -> ConsList<T> {
- let list: ConsList<T> = ConsList::from_iter(h);
- list.sort()
-}
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::proptest::*;
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
-
- #[test]
- fn test_hashset_len(ref mut h in hash_set(".*", 0..100)) {
- let abs_list = abstraction(h.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(h), abs_list.len());
- assert_eq!(abstraction(h.clone()), abs_list);
- }
+ use im::conslist::ConsList;
+ use proptest::{collection::hash_set, prelude::*};
+ use std::iter::FromIterator;
- #[test]
- fn test_hashset_contains(ref mut h in hash_set(".*", 0..100), a in ".*") {
- let abs_list = abstraction(h.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- assert_eq!(Container::<String>::contains(h, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(h.clone()), abs_list);
+ fn abstraction<T: Ord>(h: HashSet<T>) -> ConsList<T> {
+ let list: ConsList<T> = ConsList::from_iter(h);
+ list.sort()
}
- #[test]
- fn test_hashset_is_empty(ref mut h in hash_set(".*", 0..100)) {
- let abs_list = abstraction(h.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- assert_eq!(Container::<String>::is_empty(h), abs_list.is_empty());
- assert_eq!(abstraction(h.clone()), abs_list);
- }
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
+
+ #[test]
+ fn test_hashset_len(ref mut h in hash_set(".*", 0..100)) {
+ let abs_list = abstraction(h.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(h), abs_list.len());
+ assert_eq!(abstraction(h.clone()), abs_list);
+ }
- #[test]
- fn test_hashset_insert(ref mut h in hash_set(".*", 0..100), a in ".*") {
- let abs_list = abstraction(h.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(h, a.clone());
- assert_eq!(abstraction(h.clone()), after_list);
- }
+ #[test]
+ fn test_hashset_contains(ref mut h in hash_set(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(h.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ assert_eq!(Container::<String>::contains(h, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(h.clone()), abs_list);
+ }
- #[test]
- fn test_hash_clear(ref mut h in hash_set(".*", 0..100)) {
- let abs_list = abstraction(h.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- let after_list = clear(&abs_list);
- Container::<String>::clear(h);
- assert_eq!(abstraction(h.clone()), after_list);
- }
+ #[test]
+ fn test_hashset_is_empty(ref mut h in hash_set(".*", 0..100)) {
+ let abs_list = abstraction(h.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ assert_eq!(Container::<String>::is_empty(h), abs_list.is_empty());
+ assert_eq!(abstraction(h.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_hashset_insert(ref mut h in hash_set(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(h.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(h, a.clone());
+ assert_eq!(abstraction(h.clone()), after_list);
+ }
- #[test]
- fn test_hashset_remove(ref mut h in hash_set(".*", 0..100), a in ".*") {
- let abs_list = abstraction(h.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(h, a.clone());
- assert_eq!(abstraction(h.clone()), after_list);
- assert_eq!(elem, abs_elem);
+ #[test]
+ fn test_hash_clear(ref mut h in hash_set(".*", 0..100)) {
+ let abs_list = abstraction(h.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ let after_list = clear(&abs_list);
+ Container::<String>::clear(h);
+ assert_eq!(abstraction(h.clone()), after_list);
+ }
+
+ #[test]
+ fn test_hashset_remove(ref mut h in hash_set(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(h.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(h, a.clone());
+ assert_eq!(abstraction(h.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/lazy_sorted_vector.rs b/primrose/crates/primrose-library/src/lazy_sorted_vector.rs
index 4d88f7c..f3060fe 100644
--- a/primrose/crates/primrose-library/src/lazy_sorted_vector.rs
+++ b/primrose/crates/primrose-library/src/lazy_sorted_vector.rs
@@ -1,22 +1,13 @@
/*LIBSPEC-NAME*
-rust-lazy-sorted-vec-spec primrose_library::lazy_sorted_vector::LazySortedVec
+rust-lazy-sorted-vec-spec primrose_library::LazySortedVec
*ENDLIBSPEC-NAME*/
-use crate::traits::{Container, Indexable, Stack};
-use std::iter::FromIterator;
-use std::ops::Deref;
-use std::slice::Iter;
-use std::vec::Vec;
-
-use crate::proptest::strategies::lazy_sorted_vec;
-use crate::proptest::*;
-use proptest::prelude::*;
+use crate::traits::{Container, Indexable};
-use im::conslist;
-use im::conslist::ConsList;
-use std::sync::Arc;
+use std::slice::Iter;
+pub use std::vec::Vec;
-// A Sorted Vector
+/// A Sorted Vector
#[derive(Debug, Clone)]
pub struct LazySortedVec<T> {
v: Vec<T>,
@@ -37,7 +28,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn len(&mut self) -> usize {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -45,7 +36,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn contains(&mut self, x: &T) -> bool {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -53,7 +44,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn is_empty(&mut self) -> bool {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -66,7 +57,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn pop(&mut self) -> Option<T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -74,7 +65,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn remove(&mut self, index: usize) -> T {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -86,7 +77,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn first(&mut self) -> Option<&T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -94,7 +85,7 @@ impl<T: Ord> LazySortedVec<T> {
}
pub fn last(&mut self) -> Option<&T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.modified = false;
}
@@ -250,116 +241,125 @@ impl<T: Ord> Indexable<T> for LazySortedVec<T> {
}
}
-fn abstraction<T>(v: LazySortedVec<T>) -> ConsList<T>
-where
- T: Ord,
-{
- let list: ConsList<T> = ConsList::from(v.to_vec());
- list.sort()
-}
-
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
-
- #[test]
- fn test_lazy_sorted_vec_len(ref mut v in lazy_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- assert_eq!(Container::<String>::len(v), abs_list.len());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::proptest::{strategies::lazy_sorted_vec, *};
+ use proptest::prelude::*;
+
+ use im::conslist::ConsList;
+
+ fn abstraction<T>(v: LazySortedVec<T>) -> ConsList<T>
+ where
+ T: Ord,
+ {
+ let list: ConsList<T> = ConsList::from(v.to_vec());
+ list.sort()
+ }
+
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
+
+ #[test]
+ fn test_lazy_sorted_vec_len(ref mut v in lazy_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ assert_eq!(Container::<String>::len(v), abs_list.len());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_contains(ref mut v in lazy_sorted_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_sorted_vec_contains(ref mut v in lazy_sorted_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_is_empty(ref mut v in lazy_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_sorted_vec_is_empty(ref mut v in lazy_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_insert(ref mut v in lazy_sorted_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let after_list = abs_list.append(conslist![a.clone()]).sort();
- Container::<String>::insert(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_lazy_sorted_vec_insert(ref mut v in lazy_sorted_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let after_list = abs_list.append(conslist![a.clone()]).sort();
+ Container::<String>::insert(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_clear(ref mut v in lazy_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let after_list = clear(&abs_list);
- Container::<String>::clear(v);
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_lazy_sorted_vec_clear(ref mut v in lazy_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let after_list = clear(&abs_list);
+ Container::<String>::clear(v);
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_remove(ref mut v in lazy_sorted_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let (after_list, abs_elem) = remove(&abs_list, a.clone());
- let elem = Container::<String>::remove(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- assert_eq!(elem, abs_elem);
- }
+ #[test]
+ fn test_lazy_sorted_vec_remove(ref mut v in lazy_sorted_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let (after_list, abs_elem) = remove(&abs_list, a.clone());
+ let elem = Container::<String>::remove(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
- #[test]
- fn test_lazy_sorted_vec_first(ref mut v in lazy_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let elem = Indexable::<String>::first(v);
- let abs_first = first(&abs_list);
- assert_eq!(elem, abs_first);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_sorted_vec_first(ref mut v in lazy_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let elem = Indexable::<String>::first(v);
+ let abs_first = first(&abs_list);
+ assert_eq!(elem, abs_first);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_last(ref mut v in lazy_sorted_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let elem = Indexable::<String>::last(v);
- let abs_last = last(&abs_list);
- assert_eq!(elem, abs_last);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_sorted_vec_last(ref mut v in lazy_sorted_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let elem = Indexable::<String>::last(v);
+ let abs_last = last(&abs_list);
+ assert_eq!(elem, abs_last);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_sorted_vec_nth(ref mut v in lazy_sorted_vec(".*", 0..100), n in 0usize..100) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, abs_list.sort());
- //post
- let elem = Indexable::<String>::nth(v, n.clone());
- let abs_nth = nth(&abs_list, n);
- assert_eq!(elem, abs_nth);
- assert_eq!(abstraction(v.clone()), abs_list);
+ #[test]
+ fn test_lazy_sorted_vec_nth(ref mut v in lazy_sorted_vec(".*", 0..100), n in 0usize..100) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, abs_list.sort());
+ //post
+ let elem = Indexable::<String>::nth(v, n.clone());
+ let abs_nth = nth(&abs_list, n);
+ assert_eq!(elem, abs_nth);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/lazy_unique_vector.rs b/primrose/crates/primrose-library/src/lazy_unique_vector.rs
index 2d14b1e..1ee940a 100644
--- a/primrose/crates/primrose-library/src/lazy_unique_vector.rs
+++ b/primrose/crates/primrose-library/src/lazy_unique_vector.rs
@@ -1,21 +1,13 @@
/*LIBSPEC-NAME*
-rust-lazy-unique-vec-spec primrose::library::lazy_unique_vector::LazyUniqueVec
+rust-lazy-unique-vec-spec primrose::library::LazyUniqueVec
*ENDLIBSPEC-NAME*/
-use crate::traits::{Container, Indexable, Stack};
-use std::ops::Deref;
+use crate::traits::{Container, Indexable};
+
use std::slice::Iter;
use std::vec::Vec;
-use crate::proptest::strategies::lazy_unique_vec;
-use crate::proptest::*;
-use proptest::prelude::*;
-
-use im::conslist;
-use im::conslist::ConsList;
-use std::sync::Arc;
-
-// A Unique and Ascending Vector
+/// A Unique and Ascending Vector
#[derive(Debug, Clone)]
pub struct LazyUniqueVec<T> {
v: Vec<T>,
@@ -37,7 +29,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn len(&mut self) -> usize {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -46,7 +38,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn contains(&mut self, x: &T) -> bool {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -55,7 +47,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn is_empty(&mut self) -> bool {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -70,7 +62,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn pop(&mut self) -> Option<T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -79,7 +71,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn remove(&mut self, index: usize) -> T {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -92,7 +84,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn first(&mut self) -> Option<&T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -101,7 +93,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn last(&mut self) -> Option<&T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -110,7 +102,7 @@ impl<T: Ord> LazyUniqueVec<T> {
}
pub fn iter(&mut self) -> Iter<'_, T> {
- if (self.modified) {
+ if self.modified {
self.v.sort();
self.v.dedup();
self.modified = false;
@@ -259,105 +251,114 @@ impl<T: Ord> Indexable<T> for LazyUniqueVec<T> {
}
}
-fn abstraction<T>(v: LazyUniqueVec<T>) -> ConsList<T>
-where
- T: Ord,
-{
- let list: ConsList<T> = ConsList::from(v.to_vec());
- unique(&list.sort())
-}
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::proptest::{strategies::lazy_unique_vec, *};
+ use proptest::prelude::*;
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
-
- #[test]
- fn test_lazy_unique_vec_len(ref mut v in lazy_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- assert_eq!(Container::<String>::len(v), abs_list.len());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ use im::conslist::ConsList;
- #[test]
- fn test_lazy_unique_vec_contains(ref mut v in lazy_unique_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(v.clone()), abs_list);
+ fn abstraction<T>(v: LazyUniqueVec<T>) -> ConsList<T>
+ where
+ T: Ord,
+ {
+ let list: ConsList<T> = ConsList::from(v.to_vec());
+ unique(&list.sort())
}
- #[test]
- fn test_lazy_unique_vec_insert(ref mut v in lazy_unique_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.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(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
+
+ #[test]
+ fn test_lazy_unique_vec_len(ref mut v in lazy_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ assert_eq!(Container::<String>::len(v), abs_list.len());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_vec_is_empty(ref mut v in lazy_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_unique_vec_contains(ref mut v in lazy_unique_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_unique_vec_remove(ref mut v in lazy_unique_vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.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(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- assert_eq!(elem, abs_elem);
- }
+ #[test]
+ fn test_lazy_unique_vec_insert(ref mut v in lazy_unique_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.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(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_lazy_unique_vec_first(ref mut v in lazy_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- let elem = Indexable::<String>::first(v);
- let abs_first = first(&abs_list);
- assert_eq!(elem, abs_first);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_vec_is_empty(ref mut v in lazy_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_lazy_unique_vec_last(ref mut v in lazy_unique_vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- let elem = Indexable::<String>::last(v);
- let abs_last = last(&abs_list);
- assert_eq!(elem, abs_last);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_lazy_unique_vec_remove(ref mut v in lazy_unique_vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.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(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
- #[test]
- fn test_lazy_unique_vec_nth(ref mut v in lazy_unique_vec(".*", 0..100), n in 0usize..100) {
- let abs_list = abstraction(v.clone());
- //pre
- assert_eq!(abs_list, unique(&abs_list.sort()));
- //post
- let elem = Indexable::<String>::nth(v, n.clone());
- let abs_nth = nth(&abs_list, n);
- assert_eq!(elem, abs_nth);
- assert_eq!(abstraction(v.clone()), abs_list);
+ #[test]
+ fn test_lazy_unique_vec_first(ref mut v in lazy_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ let elem = Indexable::<String>::first(v);
+ let abs_first = first(&abs_list);
+ assert_eq!(elem, abs_first);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_lazy_unique_vec_last(ref mut v in lazy_unique_vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ let elem = Indexable::<String>::last(v);
+ let abs_last = last(&abs_list);
+ assert_eq!(elem, abs_last);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_lazy_unique_vec_nth(ref mut v in lazy_unique_vec(".*", 0..100), n in 0usize..100) {
+ let abs_list = abstraction(v.clone());
+ //pre
+ assert_eq!(abs_list, unique(&abs_list.sort()));
+ //post
+ let elem = Indexable::<String>::nth(v, n.clone());
+ let abs_nth = nth(&abs_list, n);
+ assert_eq!(elem, abs_nth);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/lib.rs b/primrose/crates/primrose-library/src/lib.rs
index 98d0ab2..19ff7af 100644
--- a/primrose/crates/primrose-library/src/lib.rs
+++ b/primrose/crates/primrose-library/src/lib.rs
@@ -1,13 +1,23 @@
+//! Container implementations that primrose can select from, and traits.
+
#![feature(linked_list_cursors)]
-pub mod proptest;
pub mod traits;
-pub mod eager_sorted_vector;
-pub mod eager_unique_vector;
-pub mod hashset;
-pub mod lazy_sorted_vector;
-pub mod lazy_unique_vector;
-pub mod list;
-pub mod treeset;
-pub mod vector;
+mod eager_sorted_vector;
+mod eager_unique_vector;
+mod lazy_sorted_vector;
+mod lazy_unique_vector;
+
+mod hashset;
+mod list;
+mod treeset;
+mod vector;
+
+pub use eager_sorted_vector::EagerSortedVec;
+pub use eager_unique_vector::EagerUniqueVec;
+pub use lazy_sorted_vector::LazySortedVec;
+pub use lazy_unique_vector::LazyUniqueVec;
+
+#[cfg(test)]
+pub mod proptest;
diff --git a/primrose/crates/primrose-library/src/list.rs b/primrose/crates/primrose-library/src/list.rs
index daf4c02..d27bc61 100644
--- a/primrose/crates/primrose-library/src/list.rs
+++ b/primrose/crates/primrose-library/src/list.rs
@@ -2,20 +2,11 @@
rust-linked-list-spec std::collections::LinkedList
*ENDLIBSPEC-NAME*/
+use crate::traits::{Container, Indexable, Stack};
+
use std::cmp::Ordering;
use std::collections::LinkedList;
-use std::iter::FromIterator;
use std::marker::PhantomData;
-// nightly features
-use crate::proptest::*;
-use crate::traits::{Container, Indexable, Stack};
-use proptest::collection::linked_list;
-use proptest::prelude::*;
-use std::collections::linked_list::CursorMut;
-
-use im::conslist;
-use im::conslist::ConsList;
-use std::sync::Arc;
/*IMPL*
Container
@@ -213,103 +204,114 @@ impl<T: 'static + Ord> Constructor for Con<T> {
}
}
-fn abstraction<T>(l: LinkedList<T>) -> ConsList<T> {
- let list: ConsList<T> = ConsList::from_iter(l);
- list
-}
+#[cfg(test)]
+mod tests {
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
+ use std::sync::Arc;
- #[test]
- fn test_list_len(ref mut l in linked_list(".*", 0..100)) {
- let abs_list = abstraction(l.clone());
- assert_eq!(Container::<String>::len(l), abs_list.len());
- assert_eq!(abstraction(l.clone()), abs_list);
- }
+ use super::*;
+ use crate::proptest::*;
+ use proptest::{collection::linked_list, prelude::*};
- #[test]
- fn test_list_contains(ref mut l in linked_list(".*", 0..100), a in ".*") {
- let abs_list = abstraction(l.clone());
- assert_eq!(Container::<String>::contains(l, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(l.clone()), abs_list);
+ use im::conslist::ConsList;
+ fn abstraction<T>(l: LinkedList<T>) -> ConsList<T> {
+ let list: ConsList<T> = ConsList::from_iter(l);
+ list
}
- #[test]
- fn test_list_is_empty(ref mut l in linked_list(".*", 0..100)) {
- let abs_list = abstraction(l.clone());
- assert_eq!(Container::<String>::is_empty(l), abs_list.is_empty());
- assert_eq!(abstraction(l.clone()), abs_list);
- }
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
- #[test]
- fn test_list_insert(ref mut l in linked_list(".*", 0..100), a in ".*") {
- let abs_list = abstraction(l.clone());
- let after_list = abs_list.append(conslist![a.clone()]);
- Container::<String>::insert(l, a.clone());
- assert_eq!(abstraction(l.clone()), after_list);
- }
+ #[test]
+ fn test_list_len(ref mut l in linked_list(".*", 0..100)) {
+ let abs_list = abstraction(l.clone());
+ assert_eq!(Container::<String>::len(l), abs_list.len());
+ assert_eq!(abstraction(l.clone()), abs_list);
+ }
- #[test]
- fn test_list_clear(ref mut l in linked_list(".*", 0..100)) {
- let abs_list = abstraction(l.clone());
- let after_list = clear(&abs_list);
- Container::<String>::clear(l);
- assert_eq!(abstraction(l.clone()), after_list);
- }
+ #[test]
+ fn test_list_contains(ref mut l in linked_list(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(l.clone());
+ assert_eq!(Container::<String>::contains(l, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(l.clone()), abs_list);
+ }
- #[test]
- fn test_list_remove(ref mut l in linked_list(".*", 0..100), a in ".*") {
- let abs_list = abstraction(l.clone());
- let (after_list, abs_elem) = remove(&abs_list, a.clone());
- let elem = Container::<String>::remove(l, a.clone());
- assert_eq!(abstraction(l.clone()), after_list);
- assert_eq!(elem, abs_elem);
- }
+ #[test]
+ fn test_list_is_empty(ref mut l in linked_list(".*", 0..100)) {
+ let abs_list = abstraction(l.clone());
+ assert_eq!(Container::<String>::is_empty(l), abs_list.is_empty());
+ assert_eq!(abstraction(l.clone()), abs_list);
+ }
- #[test]
- fn test_list_first(ref mut l in linked_list(".*", 0..100)) {
- let abs_list = abstraction(l.clone());
- let elem = Indexable::<String>::first(l);
- let abs_first = first(&abs_list);
- assert_eq!(elem, abs_first);
- assert_eq!(abstraction(l.clone()), abs_list);
- }
+ #[test]
+ fn test_list_insert(ref mut l in linked_list(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(l.clone());
+ let after_list = abs_list.append(conslist![a.clone()]);
+ Container::<String>::insert(l, a.clone());
+ assert_eq!(abstraction(l.clone()), after_list);
+ }
- #[test]
- fn test_list_last(ref mut l in linked_list(".*", 0..100)) {
- let abs_list = abstraction(l.clone());
- let elem = Indexable::<String>::last(l);
- let abs_last = last(&abs_list);
- assert_eq!(elem, abs_last);
- assert_eq!(abstraction(l.clone()), abs_list);
- }
+ #[test]
+ fn test_list_clear(ref mut l in linked_list(".*", 0..100)) {
+ let abs_list = abstraction(l.clone());
+ let after_list = clear(&abs_list);
+ Container::<String>::clear(l);
+ assert_eq!(abstraction(l.clone()), after_list);
+ }
- #[test]
- fn test_list_nth(ref mut l in linked_list(".*", 0..100), n in 0usize..100) {
- let abs_list = abstraction(l.clone());
- let elem = Indexable::<String>::nth(l, n.clone());
- let abs_nth = nth(&abs_list, n);
- assert_eq!(elem, abs_nth);
- assert_eq!(abstraction(l.clone()), abs_list);
- }
+ #[test]
+ fn test_list_remove(ref mut l in linked_list(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(l.clone());
+ let (after_list, abs_elem) = remove(&abs_list, a.clone());
+ let elem = Container::<String>::remove(l, a.clone());
+ assert_eq!(abstraction(l.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
- #[test]
- fn test_list_push(ref mut l in linked_list(".*", 0..100), a in ".*") {
- let abs_list = abstraction(l.clone());
- let after_list = push(&abs_list, a.clone());
- Stack::<String>::push(l, a.clone());
- assert_eq!(abstraction(l.clone()), after_list);
- }
+ #[test]
+ fn test_list_first(ref mut l in linked_list(".*", 0..100)) {
+ let abs_list = abstraction(l.clone());
+ let elem = Indexable::<String>::first(l);
+ let abs_first = first(&abs_list);
+ assert_eq!(elem, abs_first);
+ assert_eq!(abstraction(l.clone()), abs_list);
+ }
- #[test]
- fn test_list_pop(ref mut l in linked_list(".*", 0..100)) {
- let abs_list = abstraction(l.clone());
- let (after_list, abs_elem) = pop(&abs_list);
- let elem = Stack::<String>::pop(l);
- assert_eq!(abstraction(l.clone()), after_list);
- assert_eq!(elem.map(|x| Arc::new(x)), abs_elem);
+ #[test]
+ fn test_list_last(ref mut l in linked_list(".*", 0..100)) {
+ let abs_list = abstraction(l.clone());
+ let elem = Indexable::<String>::last(l);
+ let abs_last = last(&abs_list);
+ assert_eq!(elem, abs_last);
+ assert_eq!(abstraction(l.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_list_nth(ref mut l in linked_list(".*", 0..100), n in 0usize..100) {
+ let abs_list = abstraction(l.clone());
+ let elem = Indexable::<String>::nth(l, n.clone());
+ let abs_nth = nth(&abs_list, n);
+ assert_eq!(elem, abs_nth);
+ assert_eq!(abstraction(l.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_list_push(ref mut l in linked_list(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(l.clone());
+ let after_list = push(&abs_list, a.clone());
+ Stack::<String>::push(l, a.clone());
+ assert_eq!(abstraction(l.clone()), after_list);
+ }
+
+ #[test]
+ fn test_list_pop(ref mut l in linked_list(".*", 0..100)) {
+ let abs_list = abstraction(l.clone());
+ let (after_list, abs_elem) = pop(&abs_list);
+ let elem = Stack::<String>::pop(l);
+ assert_eq!(abstraction(l.clone()), after_list);
+ assert_eq!(elem.map(|x| Arc::new(x)), abs_elem);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/proptest/mod.rs b/primrose/crates/primrose-library/src/proptest/mod.rs
index a21ad10..7807854 100644
--- a/primrose/crates/primrose-library/src/proptest/mod.rs
+++ b/primrose/crates/primrose-library/src/proptest/mod.rs
@@ -1,6 +1,6 @@
pub mod strategies;
-use im::conslist;
+pub use im::conslist;
use im::conslist::ConsList;
use std::sync::Arc;
@@ -8,7 +8,7 @@ pub fn contains<T: PartialEq>(list: &ConsList<T>, elem: &T) -> bool {
list.iter().any(|x| x.as_ref() == elem)
}
-pub fn clear<T>(list: &ConsList<T>) -> ConsList<T> {
+pub fn clear<T>(_list: &ConsList<T>) -> ConsList<T> {
ConsList::<T>::new()
}
diff --git a/primrose/crates/primrose-library/src/proptest/strategies.rs b/primrose/crates/primrose-library/src/proptest/strategies.rs
index aeb7b0a..d087fcc 100644
--- a/primrose/crates/primrose-library/src/proptest/strategies.rs
+++ b/primrose/crates/primrose-library/src/proptest/strategies.rs
@@ -1,14 +1,13 @@
use proptest::prelude::*;
-use proptest::strategy::*;
+
use std::ops::Range;
use crate::eager_sorted_vector::EagerSortedVec;
use crate::eager_unique_vector::EagerUniqueVec;
use crate::lazy_sorted_vector::LazySortedVec;
use crate::lazy_unique_vector::LazyUniqueVec;
-use im::conslist::ConsList;
+
use proptest::collection::vec;
-use proptest::prelude::*;
pub fn eager_unique_vec<T: Strategy + 'static>(
element: T,
diff --git a/primrose/crates/primrose-library/src/traits.rs b/primrose/crates/primrose-library/src/traits.rs
index 6e372ad..a33f3d9 100644
--- a/primrose/crates/primrose-library/src/traits.rs
+++ b/primrose/crates/primrose-library/src/traits.rs
@@ -1,3 +1,5 @@
+//! Common traits for primrose container types
+
pub trait Container<T> {
fn len(&mut self) -> usize;
fn contains(&mut self, x: &T) -> bool;
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);
+ }
}
}
diff --git a/primrose/crates/primrose-library/src/vector.rs b/primrose/crates/primrose-library/src/vector.rs
index d41a3c5..fe15b98 100644
--- a/primrose/crates/primrose-library/src/vector.rs
+++ b/primrose/crates/primrose-library/src/vector.rs
@@ -2,16 +2,8 @@
rust-vec-spec std::vec::Vec
*ENDLIBSPEC-NAME*/
-use crate::proptest::*;
use crate::traits::{Container, Indexable, Stack};
-use std::vec::Vec;
-
-use proptest::collection::vec;
-use proptest::prelude::*;
-
-use im::conslist;
-use im::conslist::ConsList;
-use std::sync::Arc;
+pub use std::vec::Vec;
/*IMPL*
Container
@@ -181,103 +173,114 @@ impl<T> Indexable<T> for Vec<T> {
}
}
-fn abstraction<T>(v: Vec<T>) -> ConsList<T> {
- let list: ConsList<T> = ConsList::from(v);
- list
-}
+#[cfg(test)]
+mod test {
+ use std::sync::Arc;
-proptest! {
- #![proptest_config(ProptestConfig {
- cases: 100, .. ProptestConfig::default()
- })]
+ use super::*;
+ use crate::proptest::*;
+ use im::conslist::ConsList;
+ use proptest::collection::vec;
+ use proptest::prelude::*;
- #[test]
- fn test_vec_len(ref mut v in vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- assert_eq!(Container::<String>::len(v), abs_list.len());
- assert_eq!(abstraction(v.clone()), abs_list);
+ fn abstraction<T>(v: Vec<T>) -> ConsList<T> {
+ let list: ConsList<T> = ConsList::from(v);
+ list
}
- #[test]
- fn test_vec_contains(ref mut v in vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ proptest! {
+ #![proptest_config(ProptestConfig {
+ cases: 100, .. ProptestConfig::default()
+ })]
- #[test]
- fn test_vec_is_empty(ref mut v in vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_vec_len(ref mut v in vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ assert_eq!(Container::<String>::len(v), abs_list.len());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_vec_insert(ref mut v in vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- let after_list = abs_list.append(conslist![a.clone()]);
- Container::<String>::insert(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_vec_contains(ref mut v in vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ assert_eq!(Container::<String>::contains(v, &a), contains(&abs_list, &a));
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_vec_clear(ref mut v in vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- let after_list = clear(&abs_list);
- Container::<String>::clear(v);
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_vec_is_empty(ref mut v in vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ assert_eq!(Container::<String>::is_empty(v), abs_list.is_empty());
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_vec_remove(ref mut v in vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- let (after_list, abs_elem) = remove(&abs_list, a.clone());
- let elem = Container::<String>::remove(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- assert_eq!(elem, abs_elem);
- }
+ #[test]
+ fn test_vec_insert(ref mut v in vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ let after_list = abs_list.append(conslist![a.clone()]);
+ Container::<String>::insert(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_vec_first(ref mut v in vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- let elem = Indexable::<String>::first(v);
- let abs_first = first(&abs_list);
- assert_eq!(elem, abs_first);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_vec_clear(ref mut v in vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ let after_list = clear(&abs_list);
+ Container::<String>::clear(v);
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_vec_last(ref mut v in vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- let elem = Indexable::<String>::last(v);
- let abs_last = last(&abs_list);
- assert_eq!(elem, abs_last);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_vec_remove(ref mut v in vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ let (after_list, abs_elem) = remove(&abs_list, a.clone());
+ let elem = Container::<String>::remove(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ assert_eq!(elem, abs_elem);
+ }
- #[test]
- fn test_vec_nth(ref mut v in vec(".*", 0..100), n in 0usize..100) {
- let abs_list = abstraction(v.clone());
- let elem = Indexable::<String>::nth(v, n.clone());
- let abs_nth = nth(&abs_list, n);
- assert_eq!(elem, abs_nth);
- assert_eq!(abstraction(v.clone()), abs_list);
- }
+ #[test]
+ fn test_vec_first(ref mut v in vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ let elem = Indexable::<String>::first(v);
+ let abs_first = first(&abs_list);
+ assert_eq!(elem, abs_first);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
- #[test]
- fn test_vec_push(ref mut v in vec(".*", 0..100), a in ".*") {
- let abs_list = abstraction(v.clone());
- let after_list = push(&abs_list, a.clone());
- Stack::<String>::push(v, a.clone());
- assert_eq!(abstraction(v.clone()), after_list);
- }
+ #[test]
+ fn test_vec_last(ref mut v in vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ let elem = Indexable::<String>::last(v);
+ let abs_last = last(&abs_list);
+ assert_eq!(elem, abs_last);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_vec_nth(ref mut v in vec(".*", 0..100), n in 0usize..100) {
+ let abs_list = abstraction(v.clone());
+ let elem = Indexable::<String>::nth(v, n.clone());
+ let abs_nth = nth(&abs_list, n);
+ assert_eq!(elem, abs_nth);
+ assert_eq!(abstraction(v.clone()), abs_list);
+ }
+
+ #[test]
+ fn test_vec_push(ref mut v in vec(".*", 0..100), a in ".*") {
+ let abs_list = abstraction(v.clone());
+ let after_list = push(&abs_list, a.clone());
+ Stack::<String>::push(v, a.clone());
+ assert_eq!(abstraction(v.clone()), after_list);
+ }
- #[test]
- fn test_vec_pop(ref mut v in vec(".*", 0..100)) {
- let abs_list = abstraction(v.clone());
- let (after_list, abs_elem) = pop(&abs_list);
- let elem = Stack::<String>::pop(v);
- assert_eq!(abstraction(v.clone()), after_list);
- assert_eq!(elem.map(|x| Arc::new(x)), abs_elem);
+ #[test]
+ fn test_vec_pop(ref mut v in vec(".*", 0..100)) {
+ let abs_list = abstraction(v.clone());
+ let (after_list, abs_elem) = pop(&abs_list);
+ let elem = Stack::<String>::pop(v);
+ assert_eq!(abstraction(v.clone()), after_list);
+ assert_eq!(elem.map(|x| Arc::new(x)), abs_elem);
+ }
}
}