Skip to content

Commit

Permalink
Add tests for VTK IO
Browse files Browse the repository at this point in the history
  • Loading branch information
w1th0utnam3 committed Apr 19, 2023
1 parent e6298ae commit cebad9d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
27 changes: 27 additions & 0 deletions data/cube_8_particles.vtk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# vtk DataFile Version 5.1
vtk output
ASCII
DATASET UNSTRUCTURED_GRID

POINTS 8 double
0.5 0.4995095 0.5 0.5 0.4995095 1 0.5 0.9995095 0.5
0.5 0.9995095 1 1 0.4995095 0.5 1 0.4995095 1
1 0.9995095 0.5 1 0.9995095 1

CELLS 9 8

OFFSETS vtktypeint64
0 1 2 3 4 5 6 7 8

CONNECTIVITY vtktypeint64
0 1 2 3 4 5 6 7

CELL_TYPES 8
1
1
1
1
1
1
1
1
Binary file added data/cube_8_particles.vtu
Binary file not shown.
Binary file added data/fluid_250_particles.vtu
Binary file not shown.
63 changes: 63 additions & 0 deletions data/fluid_encoded_250_particles.vtu

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions splashsurf_lib/src/io/vtk_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,49 @@ where
}
}
}

#[cfg(test)]
pub mod test {
use super::*;

fn test_load_num_particles<P: AsRef<Path>>(input_file: P, num_particles: usize) -> Result<(), anyhow::Error> {
let input_file = input_file.as_ref();
let particles: Vec<Vector3<f32>> = particles_from_vtk(input_file).with_context(|| {
format!(
"Failed to load surface mesh from file \"{}\"",
input_file.display()
)
})?;

assert_eq!(particles.len(), num_particles);

Ok(())
}

#[test]
fn test_cube_8_particles_from_vtu() -> Result<(), anyhow::Error> {
test_load_num_particles("../data/cube_8_particles.vtu", 8)
}

#[test]
#[ignore = "Disabled due to bug in vtkio (https://github.com/elrnv/vtkio/issues/21#issuecomment-1513195315)"]
fn test_cube_8_particles_from_vtk() -> Result<(), anyhow::Error> {
test_load_num_particles("../data/cube_8_particles.vtk", 250)
}

#[test]
fn test_hilbert_46843_particles_from_vtk() -> Result<(), anyhow::Error> {
test_load_num_particles("../data/hilbert_46843_particles.vtk", 46843)
}

#[test]
fn test_fluid_250_particles_from_vtu_encoded() -> Result<(), anyhow::Error> {
test_load_num_particles("../data/fluid_encoded_250_particles.vtu", 250)
}

#[test]
#[ignore = "Disabled due to bug in vtkio/XML parser (https://github.com/elrnv/vtkio/issues/27)"]
fn test_fluid_250_particles_from_vtu() -> Result<(), anyhow::Error> {
test_load_num_particles("../data/fluid_250_particles.vtu", 250)
}
}
2 changes: 1 addition & 1 deletion splashsurf_lib/src/profiling_macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Provides the [`profile`] macro or a dummy implementation depending on the selected feature
//! Provides the [`profile`](crate::profile) macro or a dummy implementation depending on the selected feature

#[cfg(feature = "profiling")]
/// Creates a scope for profiling
Expand Down

0 comments on commit cebad9d

Please sign in to comment.