diff options
author | Aria Shrimpton <me@aria.rip> | 2024-01-31 21:34:26 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-01-31 21:34:26 +0000 |
commit | 9bcd8b81cb49b58c8139d574d2cd056ed199f393 (patch) | |
tree | e278a8f9f38a0c58d79f8d1a9c6d38eba922ccaa | |
parent | db30ce4e436641513568d5e5ae37f7100594156c (diff) |
add test for set insertion
-rw-r--r-- | src/tests/Cargo.lock | 62 | ||||
-rw-r--r-- | src/tests/Cargo.toml | 2 | ||||
-rw-r--r-- | src/tests/example_sets/Cargo.toml | 17 | ||||
-rw-r--r-- | src/tests/example_sets/benches/main.rs | 12 | ||||
-rw-r--r-- | src/tests/example_sets/src/lib.rs | 15 | ||||
-rw-r--r-- | src/tests/example_sets/src/types.pr.rs | 7 |
6 files changed, 115 insertions, 0 deletions
diff --git a/src/tests/Cargo.lock b/src/tests/Cargo.lock index a4bd05d..3b7b6dc 100644 --- a/src/tests/Cargo.lock +++ b/src/tests/Cargo.lock @@ -152,6 +152,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] +name = "example_sets" +version = "0.1.0" +dependencies = [ + "criterion", + "primrose-library", + "rand", +] + +[[package]] name = "example_stack" version = "0.1.0" dependencies = [ @@ -160,6 +169,17 @@ dependencies = [ ] [[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] name = "half" version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -272,6 +292,12 @@ dependencies = [ ] [[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] name = "prime_sieve" version = "0.1.0" dependencies = [ @@ -302,6 +328,36 @@ dependencies = [ ] [[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] name = "rayon" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -459,6 +515,12 @@ dependencies = [ ] [[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] name = "wasm-bindgen" version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/src/tests/Cargo.toml b/src/tests/Cargo.toml index 120e0cd..1d6189d 100644 --- a/src/tests/Cargo.toml +++ b/src/tests/Cargo.toml @@ -1,9 +1,11 @@ [workspace] resolver = "2" members = [ + "example_sets", "example_stack", "prime_sieve" ] [workspace.dependencies] criterion = "0.3" +rand = "0.8.5" 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*/ |