2017-08-14 18:07:06 +08:00
|
|
|
extern crate rand;
|
|
|
|
extern crate nalgebra;
|
|
|
|
extern crate abomonation;
|
|
|
|
|
|
|
|
use rand::random;
|
|
|
|
use abomonation::{Abomonation, encode, decode};
|
2017-08-14 18:37:16 +08:00
|
|
|
use nalgebra::{DMatrix, Matrix3x4, Point3, Translation3};
|
2017-08-14 18:07:06 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn abomonate_matrix3x4() {
|
|
|
|
assert_encode_and_decode(&random::<Matrix3x4<f32>>());
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:18:47 +08:00
|
|
|
#[test]
|
|
|
|
fn abomonate_point3() {
|
|
|
|
assert_encode_and_decode(&random::<Point3<f64>>());
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:30:50 +08:00
|
|
|
#[test]
|
|
|
|
fn abomonate_dmatrix() {
|
|
|
|
assert_encode_and_decode(&DMatrix::<f32>::new_random(3, 5));
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:37:16 +08:00
|
|
|
#[test]
|
|
|
|
fn abomonate_translation3() {
|
|
|
|
assert_encode_and_decode(&random::<Translation3<f32>>());
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:07:06 +08:00
|
|
|
fn assert_encode_and_decode<T: Abomonation + PartialEq>(data: &T) {
|
|
|
|
let mut bytes = Vec::new();
|
|
|
|
unsafe { encode(data, &mut bytes); }
|
|
|
|
|
|
|
|
if let Some((result, rest)) = unsafe { decode::<T>(&mut bytes) } {
|
|
|
|
assert!(result == data);
|
|
|
|
assert!(rest.len() == 0, "binary data was not decoded completely");
|
|
|
|
}
|
|
|
|
}
|