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));
|
||||
}
|
||||
}
|
||||
|
||||
+105
-1
@@ -5,4 +5,108 @@
|
||||
|
||||
use arc_core::ffi::point::Point;
|
||||
|
||||
#[test]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn point_creation() {
|
||||
let p = Point::new(1.0, 2.0, -3.0).expect("Failed to create point");
|
||||
let coords = p.coordinates();
|
||||
assert_eq!(coords, (1.0, 2.0, -3.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_query() {
|
||||
let p = Point::new(5.5, 3.15, -0.001).expect("Failed to create point");
|
||||
let coords = p.coordinates();
|
||||
assert_eq!(coords, (5.5, 3.15, -0.001));
|
||||
}
|
||||
|
||||
#[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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_creation_extreme_values() {
|
||||
let cases = [
|
||||
(f64::MAX, f64::MIN, 0.0),
|
||||
(0.0, 0.0, 0.0),
|
||||
(-f64::MAX, -f64::MIN, f64::EPSILON),
|
||||
];
|
||||
|
||||
for (x, y, z) in cases {
|
||||
let p = Point::new(x, y, z).expect("Failed to create point with extreme values");
|
||||
let coords = p.coordinates();
|
||||
assert_eq!(coords, (x, y, z));
|
||||
p.delete().expect("Failed to delete point");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_coordinates_immutability() {
|
||||
let p = Point::new(1.5, 2.5, 3.5).expect("Failed to create point");
|
||||
|
||||
let coords1 = p.coordinates();
|
||||
let coords2 = p.coordinates();
|
||||
let coords3 = p.coordinates();
|
||||
|
||||
assert_eq!(coords1, coords2);
|
||||
assert_eq!(coords2, coords3);
|
||||
assert_eq!(coords1, (1.5, 2.5, 3.5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_automatic_cleanup_on_drop() {
|
||||
let coords = {
|
||||
let p = Point::new(7.0, 8.0, 9.0).expect("Failed to create point");
|
||||
p.coordinates()
|
||||
};
|
||||
|
||||
assert_eq!(coords, (7.0, 8.0, 9.0));
|
||||
|
||||
// Verify we can still create points after automatic cleanup
|
||||
let p2 = Point::new(10.0, 11.0, 12.0).expect("Failed to create point after drop");
|
||||
assert_eq!(p2.coordinates(), (10.0, 11.0, 12.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_multiple_instances_independent() {
|
||||
let p1 = Point::new(1.0, 1.0, 1.0).expect("Failed to create point 1");
|
||||
let p2 = Point::new(2.0, 2.0, 2.0).expect("Failed to create point 2");
|
||||
let p3 = Point::new(3.0, 3.0, 3.0).expect("Failed to create point 3");
|
||||
|
||||
assert_eq!(p1.coordinates(), (1.0, 1.0, 1.0));
|
||||
assert_eq!(p2.coordinates(), (2.0, 2.0, 2.0));
|
||||
assert_eq!(p3.coordinates(), (3.0, 3.0, 3.0));
|
||||
|
||||
p2.delete().expect("Failed to delete p2");
|
||||
p1.delete().expect("Failed to delete p1");
|
||||
p3.delete().expect("Failed to delete p3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_debug_format() {
|
||||
let p = Point::new(1.1, 2.2, 3.3).expect("Failed to create point");
|
||||
let debug_output = format!("{:?}", p);
|
||||
|
||||
assert!(debug_output.contains("Point"));
|
||||
assert!(debug_output.contains("1.1"));
|
||||
assert!(debug_output.contains("2.2"));
|
||||
assert!(debug_output.contains("3.3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point_rapid_creation_deletion_cycle_stress_test() {
|
||||
for i in 0..100 {
|
||||
let p = Point::new(i as f64, i as f64, i as f64)
|
||||
.expect(&format!("Failed to create point in iteration {}", i));
|
||||
assert_eq!(p.coordinates(), (i as f64, i as f64, i as f64));
|
||||
p.delete()
|
||||
.expect(&format!("Failed to delete point in iteration {}", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user