aboutsummaryrefslogtreecommitdiff
path: root/src/tests/example_sets
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-01-31 21:34:26 +0000
committerAria Shrimpton <me@aria.rip>2024-01-31 21:34:26 +0000
commit9bcd8b81cb49b58c8139d574d2cd056ed199f393 (patch)
treee278a8f9f38a0c58d79f8d1a9c6d38eba922ccaa /src/tests/example_sets
parentdb30ce4e436641513568d5e5ae37f7100594156c (diff)
add test for set insertion
Diffstat (limited to 'src/tests/example_sets')
-rw-r--r--src/tests/example_sets/Cargo.toml17
-rw-r--r--src/tests/example_sets/benches/main.rs12
-rw-r--r--src/tests/example_sets/src/lib.rs15
-rw-r--r--src/tests/example_sets/src/types.pr.rs7
4 files changed, 51 insertions, 0 deletions
diff --git a/src/tests/example_sets/Cargo.toml b/src/tests/example_sets/Cargo.toml
new file mode 100644
index 0000000..d76263c
--- /dev/null
+++ b/src/tests/example_sets/Cargo.toml
@@ -0,0 +1,17 @@
+[package]
+name = "example_sets"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rand = { workspace = true }
+primrose-library = { path = "../../crates/library" }
+
+[dev-dependencies]
+criterion = { workspace = true }
+
+[[bench]]
+name = "main"
+harness = false
diff --git a/src/tests/example_sets/benches/main.rs b/src/tests/example_sets/benches/main.rs
new file mode 100644
index 0000000..938fd7c
--- /dev/null
+++ b/src/tests/example_sets/benches/main.rs
@@ -0,0 +1,12 @@
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+
+fn run_benches(c: &mut Criterion) {
+ for size in [10, 500, 1000, 5000].iter() {
+ c.bench_with_input(BenchmarkId::new("insert_n", size), size, |b, &n| {
+ b.iter(|| example_sets::insert_n(n));
+ });
+ }
+}
+
+criterion_group!(benches, run_benches);
+criterion_main!(benches);
diff --git a/src/tests/example_sets/src/lib.rs b/src/tests/example_sets/src/lib.rs
new file mode 100644
index 0000000..14670cf
--- /dev/null
+++ b/src/tests/example_sets/src/lib.rs
@@ -0,0 +1,15 @@
+#![feature(type_alias_impl_trait)]
+
+mod types;
+use types::Set;
+
+use primrose_library::traits::*;
+use rand::random;
+
+pub fn insert_n(n: usize) {
+ let mut set: Set<usize> = Set::default();
+
+ for _ in 0..n {
+ set.insert(random());
+ }
+}
diff --git a/src/tests/example_sets/src/types.pr.rs b/src/tests/example_sets/src/types.pr.rs
new file mode 100644
index 0000000..d11ab97
--- /dev/null
+++ b/src/tests/example_sets/src/types.pr.rs
@@ -0,0 +1,7 @@
+/*SPEC*
+property set<T> {
+ \c <: (Container) -> ((for-all-elems c) \a -> ((unique-count? a) c))
+}
+
+type Set<S> = {c impl (Container) | (set c)}
+*ENDSPEC*/