Skip to content

Commit

Permalink
Remove cfg(test) for Datatype::iter (TileDB-Inc#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
rroelke authored Aug 6, 2024
1 parent e55bd39 commit ca5917e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
23 changes: 17 additions & 6 deletions tiledb/api/src/datatype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub use logical::*;
pub use physical::PhysicalType;

use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
#[cfg(test)]
use std::slice::Iter;

use serde::{Deserialize, Serialize};
use util::option::OptionSubset;
Expand Down Expand Up @@ -393,8 +391,9 @@ impl Datatype {
})
}

#[cfg(test)]
pub fn iter() -> Iter<'static, Datatype> {
/// Returns an `Iterator` which yields each variant of `Datatype`
/// exactly once in an unspecified order.
pub fn iter() -> impl Iterator<Item = Datatype> {
static DATATYPES: [Datatype; 43] = [
Datatype::Int32,
Datatype::Int64,
Expand Down Expand Up @@ -440,7 +439,7 @@ impl Datatype {
Datatype::GeometryWkb,
Datatype::GeometryWkt,
];
DATATYPES.iter()
DATATYPES.iter().copied()
}
}

Expand Down Expand Up @@ -804,10 +803,13 @@ pub mod strategy;

#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashSet;

use proptest::prelude::*;
use util::{assert_not_option_subset, assert_option_subset};

use super::*;

#[test]
fn datatype_roundtrips() {
for i in 0..256 {
Expand Down Expand Up @@ -840,6 +842,15 @@ mod tests {
}
}

#[test]
fn iter() {
let mut yielded = HashSet::<Datatype>::new();
for dt in Datatype::iter() {
let prev = yielded.insert(dt);
assert!(prev);
}
}

fn check_valid(dt: &Datatype) -> bool {
let mut count = 0;

Expand Down
12 changes: 6 additions & 6 deletions tiledb/api/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1765,14 +1765,14 @@ mod tests {

let range = Range::from(&[start, end]);
test_clone(&range);
test_dimension_compatibility(&range, *datatype)?;
test_dimension_compatibility(&range, datatype)?;
test_serialization_roundtrip(&range);

let start_slice = start.to_le_bytes();
let end_slice = end.to_le_bytes();
test_from_slices(
&range,
*datatype,
datatype,
CellValNum::try_from(1)?,
&start_slice[..],
&end_slice[..]
Expand All @@ -1796,7 +1796,7 @@ mod tests {
let range = Range::try_from(
(cell_val_num, start.clone(), end.clone()))?;
test_clone(&range);
test_dimension_compatibility(&range, *datatype)?;
test_dimension_compatibility(&range, datatype)?;
test_serialization_roundtrip(&range);

let nbytes = (len as u64 * datatype.size()) as usize;
Expand All @@ -1819,7 +1819,7 @@ mod tests {

test_from_slices(
&range,
*datatype,
datatype,
CellValNum::try_from(len)?,
start_slice,
end_slice
Expand Down Expand Up @@ -1858,7 +1858,7 @@ mod tests {

let range = Range::from((start.clone(), end.clone()));
test_clone(&range);
test_dimension_compatibility(&range, *datatype)?;
test_dimension_compatibility(&range, datatype)?;
test_serialization_roundtrip(&range);

// Test from slices
Expand All @@ -1878,7 +1878,7 @@ mod tests {

test_from_slices(
&range,
*datatype,
datatype,
CellValNum::Var,
start_slice,
end_slice
Expand Down

0 comments on commit ca5917e

Please sign in to comment.