test: separate tests into debug and API level tests
This commit is contained in:
+47
-10
@@ -90,25 +90,62 @@ pub use ffi_point::Point;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::os::raw::c_double;
|
||||
|
||||
#[test]
|
||||
fn point_creation() {
|
||||
let p = Point::new(1.0, 2.0, -3.0).expect("Failed to create point");
|
||||
fn point_debug_precision() {
|
||||
let p = Point::new(1.123456789, 2.987654321, -3.555555555).expect("Failed to create point");
|
||||
let debug_str = format!("{:?}", p);
|
||||
|
||||
let coords = p.coordinates();
|
||||
assert_eq!(coords, (1.0, 2.0, -3.0));
|
||||
assert!(debug_str.contains(&coords.0.to_string()));
|
||||
assert!(debug_str.contains(&coords.1.to_string()));
|
||||
assert!(debug_str.contains(&coords.2.to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_query() {
|
||||
let p = Point::new(5.5, 3.15, -0.001).expect("Failed to create point");
|
||||
fn point_null_pointer_safety() {
|
||||
let result = Point::new(1.0, 2.0, 3.0);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let p = result.unwrap();
|
||||
let coords = p.coordinates();
|
||||
assert_eq!(coords, (5.5, 3.15, -0.001));
|
||||
|
||||
assert_eq!(coords, (1.0, 2.0, 3.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_deletion() {
|
||||
let p = Point::new(1.0, 2.0, 3.0).expect("Failed to create point");
|
||||
let result = p.delete();
|
||||
assert!(result.is_ok(), "Deletion should succeed for valid point");
|
||||
fn point_drop_impl_safety() {
|
||||
{
|
||||
let p = Point::new(1.0, 2.0, 3.0).expect("Failed to create point");
|
||||
// p goes out of scope here and should be dropped
|
||||
}
|
||||
let p2 = Point::new(4.0, 5.0, 6.0).expect("Failed to create point after drop");
|
||||
assert_eq!(p2.coordinates(), (4.0, 5.0, 6.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_ffi_repr_c() {
|
||||
use std::mem;
|
||||
|
||||
// PointShape should be repr(C) and zero-sized in Rust
|
||||
assert_eq!(mem::size_of::<ffi_point::PointShape>(), 0);
|
||||
|
||||
// c_double should match f64
|
||||
assert_eq!(mem::size_of::<c_double>(), mem::size_of::<f64>());
|
||||
assert_eq!(mem::align_of::<c_double>(), mem::align_of::<f64>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_coordinates_after_multiple_uses() {
|
||||
let p = Point::new(1.1, 2.2, 3.3).expect("Failed to create point");
|
||||
|
||||
let _coords1 = p.coordinates();
|
||||
let _debug1 = format!("{:?}", p);
|
||||
let _coords2 = p.coordinates();
|
||||
let _debug2 = format!("{:?}", p);
|
||||
let final_coords = p.coordinates();
|
||||
|
||||
assert_eq!(final_coords, (1.1, 2.2, 3.3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user