Skip to content

Commit

Permalink
add utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cookiephone committed Aug 9, 2023
1 parent 0ad6ee0 commit 061c6f6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/utils/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::{
/// // create a visualizer and use it to visualize the output of the generator
/// let path = "output.png";
/// # let tmp_dir = TempDir::new("libnoise").unwrap();
/// # let mut path = &tmp_dir.path().join(path).into_os_string().into_string().unwrap();
/// # let path = &tmp_dir.path().join(path).into_os_string().into_string().unwrap();
/// Visualizer::<3>::new([30, 20, 25], &generator).write_to_file(path);
/// ```
///
Expand All @@ -59,7 +59,7 @@ use std::{
/// // create a visualizer and use it to visualize the output of the generator
/// let path = "output.png";
/// # let tmp_dir = TempDir::new("libnoise").unwrap();
/// # let mut path = &tmp_dir.path().join(path).into_os_string().into_string().unwrap();
/// # let path = &tmp_dir.path().join(path).into_os_string().into_string().unwrap();
/// Visualizer::from(buf).write_to_file(path);
/// ```
pub struct Visualizer<const D: usize> {
Expand Down
76 changes: 76 additions & 0 deletions tests/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use libnoise::prelude::*;
use proptest::prelude::*;
use tempdir::TempDir;

macro_rules! strategy_float_numeric {
() => {
prop::num::f64::NORMAL
| prop::num::f64::NEGATIVE
| prop::num::f64::POSITIVE
| prop::num::f64::ZERO
};
}

proptest! {
// =================================================================
// test NoiseBuffer
// =================================================================
#[test]
fn test_noises_buffer_1d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
NoiseBuffer::<1>::new([1000], &generator);
}

#[test]
fn test_noises_buffer_2d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
NoiseBuffer::<2>::new([100, 100], &generator);
}

#[test]
fn test_noises_buffer_3d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
NoiseBuffer::<3>::new([30, 30, 30], &generator);
}

#[test]
fn test_noises_buffer_4d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
NoiseBuffer::<4>::new([10, 10, 10, 10], &generator);
}

// =================================================================
// test Visualizer
// =================================================================
#[test]
fn test_visualizer_1d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
let tmp_dir = TempDir::new("libnoise").unwrap();
let path = &tmp_dir.path().join("output.png").into_os_string().into_string().unwrap();
Visualizer::<1>::new([1000], &generator).write_to_file(path);
}

#[test]
fn test_visualizer_2d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
let tmp_dir = TempDir::new("libnoise").unwrap();
let path = &tmp_dir.path().join("output.png").into_os_string().into_string().unwrap();
Visualizer::<2>::new([100, 100], &generator).write_to_file(path);
}

#[test]
fn test_visualizer_3d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
let tmp_dir = TempDir::new("libnoise").unwrap();
let path = &tmp_dir.path().join("output.png").into_os_string().into_string().unwrap();
Visualizer::<3>::new([30, 30, 30], &generator).write_to_file(path);
}

#[test]
fn test_visualizer_4d(val in strategy_float_numeric!()) {
let generator = Source::constant(val);
let tmp_dir = TempDir::new("libnoise").unwrap();
let path = &tmp_dir.path().join("output.png").into_os_string().into_string().unwrap();
Visualizer::<4>::new([10, 10, 10, 10], &generator).write_to_file(path);
}
}

0 comments on commit 061c6f6

Please sign in to comment.