Skip to content

Commit

Permalink
Test for auto traits
Browse files Browse the repository at this point in the history
Along with the desired traits Debug, Clone, Default, PartialEq, test for Send/Sync which are auto traits.

Got this idea from "5 traits your Rust types must implement":

https://youtu.be/Nzclc6MswaI?si=UMJKQTOBFYIOviiR
  • Loading branch information
acgetchell committed Jan 2, 2024
1 parent 650f484 commit ba20c84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/delaunay_core/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,16 @@ mod tests {
// Human readable output for cargo test -- --nocapture
println!("Origin: {:?} is {}-D", point, point.dim());
}

#[test]
fn point_default_trait() {
let point: Point<f64, 4> = Default::default();
assert_eq!(point.coords[0], 0.0);
assert_eq!(point.coords[1], 0.0);
assert_eq!(point.coords[2], 0.0);
assert_eq!(point.coords[3], 0.0);

// Human readable output for cargo test -- --nocapture
println!("Default: {:?} is {}-D", point, point.dim());
}
}
10 changes: 0 additions & 10 deletions src/delaunay_core/triangulation_data_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,6 @@ where
}
}

/// The function "start" will eventually return a triangulation data structure.
///
/// # Returns:
///
/// The function `start()` is returning an `i32` value of `1`.
pub fn start() -> i32 {
println!("Starting ...");
1
}

#[cfg(test)]
mod tests {

Expand Down
19 changes: 15 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ pub mod delaunay_core {
pub mod vertex;
}

/// The function `is_normal` checks that structs implement `auto` traits.
fn is_normal<T: Sized + Send + Sync + Unpin>() {}

#[cfg(test)]
mod tests {
use crate::delaunay_core::triangulation_data_structure::start;
use crate::{
delaunay_core::{
cell::Cell, point::Point, triangulation_data_structure::Tds, vertex::Vertex,
},
is_normal,
};

#[test]
fn it_works() {
let result = start();
assert_eq!(result, 1);
fn normal_types() {
is_normal::<Point<f64, 3>>();
is_normal::<Point<f32, 3>>();
is_normal::<Vertex<f64, Option<()>, 3>>();
is_normal::<Cell<f64, Option<()>, Option<()>, 4>>();
is_normal::<Tds<f64, Option<()>, Option<()>, 3>>();
}
}

0 comments on commit ba20c84

Please sign in to comment.