-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proptest strategy for generating Schema for sparse arrays
- Loading branch information
Showing
5 changed files
with
77 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pub mod attribute; | |
pub mod datatype; | ||
pub mod dimension; | ||
pub mod domain; | ||
pub mod schema; | ||
pub mod strategy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use proptest::prelude::*; | ||
use tiledb::array::{ArrayType, Schema, SchemaBuilder}; | ||
use tiledb::context::Context; | ||
use tiledb::Result as TileDBResult; | ||
|
||
pub fn arbitrary_array_type() -> impl Strategy<Value = ArrayType> { | ||
// TODO: implement Domain scenario for Dense arrays | ||
Just(ArrayType::Sparse) | ||
} | ||
|
||
pub fn arbitrary( | ||
context: &Context, | ||
) -> impl Strategy<Value = TileDBResult<Schema>> { | ||
const MIN_ATTRS: usize = 1; | ||
const MAX_ATTRS: usize = 128; | ||
|
||
arbitrary_array_type() | ||
.prop_flat_map(move |array_type| | ||
( | ||
Just(array_type), | ||
crate::domain::arbitrary(context, array_type), | ||
proptest::collection::vec(crate::attribute::arbitrary(context), MIN_ATTRS..=MAX_ATTRS) | ||
)) | ||
.prop_map(|(array_type, domain, attrs)| { | ||
/* TODO: cell order, tile order, capacity, duplicates */ | ||
let mut b = SchemaBuilder::new(context, array_type, domain?)?; | ||
for attr in attrs { | ||
/* TODO: how to ensure no duplicate names, assuming that matters? */ | ||
b = b.add_attribute(attr)? | ||
} | ||
|
||
Ok(b.build()) | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
/// Test that the arbitrary schema construction always succeeds | ||
#[test] | ||
fn schema_arbitrary() { | ||
let ctx = Context::new().expect("Error creating context"); | ||
|
||
proptest!(|(maybe_schema in arbitrary(&ctx))| { | ||
maybe_schema.expect("Error constructing arbitrary schema"); | ||
}); | ||
} | ||
} |