#![cfg(feature = "serde")] #![allow(bad_style)] use bincode::{deserialize, serialize}; use hektor::*; #[test] fn Vec2_serde_roundtrip() { let v = Vec2::new(1.0, 2.0); let buf = serialize(&v).unwrap(); let v_return: Vec2 = deserialize(&buf[..]).unwrap(); assert_eq!(v, v_return); } #[test] fn Vec3_serde_roundtrip() { let v = Vec3::new(1.0, 2.0, 3.0); let buf = serialize(&v).unwrap(); let v_return: Vec3 = deserialize(&buf[..]).unwrap(); assert_eq!(v, v_return); } #[test] fn Vec4_serde_roundtrip() { let v = Vec4::new(1.0, 2.0, 3.0, 4.0); let buf = serialize(&v).unwrap(); let v_return: Vec4 = deserialize(&buf[..]).unwrap(); assert_eq!(v, v_return); } #[test] fn Mat2_serde_roundtrip() { let x_axis = Vec2::new(1.0, 2.0); let y_axis = Vec2::new(11.0, 12.0); let m = Mat2::new(x_axis, y_axis); let buf = serialize(&m).unwrap(); let m_return: Mat2 = deserialize(&buf[..]).unwrap(); assert_eq!(m, m_return); } #[test] fn Mat3_serde_roundtrip() { let x_axis = Vec3::new(1.0, 2.0, 3.0); let y_axis = Vec3::new(11.0, 12.0, 13.0); let z_axis = Vec3::new(21.0, 22.0, 23.0); let m = Mat3::new(x_axis, y_axis, z_axis); let buf = serialize(&m).unwrap(); let m_return: Mat3 = deserialize(&buf[..]).unwrap(); assert_eq!(m, m_return); } #[test] fn Mat4_serde_roundtrip() { let x_axis = Vec4::new(1.0, 2.0, 3.0, 4.0); let y_axis = Vec4::new(11.0, 12.0, 13.0, 14.0); let z_axis = Vec4::new(21.0, 22.0, 23.0, 24.0); let w_axis = Vec4::new(31.0, 32.0, 33.0, 34.0); let m = Mat4::new(x_axis, y_axis, z_axis, w_axis); let buf = serialize(&m).unwrap(); let m_return: Mat4 = deserialize(&buf[..]).unwrap(); assert_eq!(m, m_return); } #[test] fn Quat_serde_roundtrip() { let q = Quat::new(1.0, 2.0, 3.0, 4.0); let buf = serialize(&q).unwrap(); let q_return: Quat = deserialize(&buf[..]).unwrap(); assert_eq!(q, q_return); }