From 4eec65daf1ecd17049541e3d0d0c2b1ff661b67e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 7 Sep 2022 20:44:59 +0400 Subject: [PATCH] Equality of geoms --- src/geom.rs | 93 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/src/geom.rs b/src/geom.rs index d7fc4ef..89150ce 100644 --- a/src/geom.rs +++ b/src/geom.rs @@ -1,28 +1,28 @@ use std::os::raw::*; #[repr(C)] -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct Position { x: c_int, y: c_int, } #[repr(C)] -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct Sizes { width: c_int, height: c_int, } #[repr(C)] -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct BasicGeom { position: Position, sizes: Sizes, } #[repr(C)] -#[derive(Clone, Copy, Default)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub struct WinGeom { basic: BasicGeom, border_width: c_int, @@ -99,21 +99,96 @@ impl WinGeom { mod tests { use super::*; + #[test] + fn position_eq() { + assert_eq!(Position::new(123, 456), Position::new(123, 456)); + + assert_ne!(Position::new(123, 123), Position::new(123, 456)); + assert_ne!(Position::new(123, 456), Position::new(123, 123)); + + assert_ne!(Position::new(123, 123), Position::new(456, 123)); + assert_ne!(Position::new(456, 123), Position::new(123, 123)); + + assert_ne!(Position::new(123, 123), Position::new(456, 456)); + assert_ne!(Position::new(456, 456), Position::new(123, 123)); + } + + #[test] + fn sizes_eq() { + assert_eq!(Sizes::new(123, 456), Sizes::new(123, 456)); + + assert_ne!(Sizes::new(123, 123), Sizes::new(123, 456)); + assert_ne!(Sizes::new(123, 456), Sizes::new(123, 123)); + + assert_ne!(Sizes::new(123, 123), Sizes::new(456, 123)); + assert_ne!(Sizes::new(456, 123), Sizes::new(123, 123)); + + assert_ne!(Sizes::new(123, 123), Sizes::new(456, 456)); + assert_ne!(Sizes::new(456, 456), Sizes::new(123, 123)); + } + + #[test] + fn basic_geom_eq() { + let pos1 = Position::new(123, 123); + let pos2 = Position::new(123, 456); + + let sizes1 = Sizes::new(123, 123); + let sizes2 = Sizes::new(123, 456); + + assert_eq!(BasicGeom::new(pos1, sizes1), BasicGeom::new(pos1, sizes1)); + assert_eq!(BasicGeom::new(pos1, sizes2), BasicGeom::new(pos1, sizes2)); + assert_eq!(BasicGeom::new(pos2, sizes1), BasicGeom::new(pos2, sizes1)); + assert_eq!(BasicGeom::new(pos2, sizes2), BasicGeom::new(pos2, sizes2)); + + assert_ne!(BasicGeom::new(pos1, sizes1), BasicGeom::new(pos1, sizes2)); + assert_ne!(BasicGeom::new(pos1, sizes2), BasicGeom::new(pos1, sizes1)); + assert_ne!(BasicGeom::new(pos1, sizes1), BasicGeom::new(pos2, sizes1)); + assert_ne!(BasicGeom::new(pos2, sizes2), BasicGeom::new(pos1, sizes2)); + } + + #[test] + fn win_geom_eq() { + let basic_geom1 = + BasicGeom::new(Position::new(123, 123), Sizes::new(123, 123)); + let basic_geom2 = + BasicGeom::new(Position::new(123, 123), Sizes::new(123, 456)); + + assert_eq!( + WinGeom::new(basic_geom1, 99), + WinGeom::new(basic_geom1, 99), + ); + + assert_ne!( + WinGeom::new(basic_geom1, 55), + WinGeom::new(basic_geom1, 99), + ); + assert_ne!( + WinGeom::new(basic_geom1, 99), + WinGeom::new(basic_geom1, 55), + ); + assert_ne!( + WinGeom::new(basic_geom1, 99), + WinGeom::new(basic_geom2, 99), + ); + assert_ne!( + WinGeom::new(basic_geom2, 99), + WinGeom::new(basic_geom1, 99), + ); + } + #[test] fn position_default() { - assert_eq!(Position::default().x(), 0); - assert_eq!(Position::default().y(), 0); + assert_eq!(Position::default(), Position::new(0, 0)); } #[test] fn sizes_default() { - assert_eq!(Sizes::default().width(), 0); - assert_eq!(Sizes::default().height(), 0); + assert_eq!(Sizes::default(), Sizes::new(0, 0)); } #[test] fn win_geom_default() { - assert_eq!(WinGeom::default().border_width(), 0); + assert_eq!(WinGeom::default(), WinGeom::new(Default::default(), 0)); } #[test]