#[cfg(test)] mod tests { use cycle_map::OptionalPair; use OptionalPair::*; #[test] fn is_tests() { let op: OptionalPair<&str, u64> = SomeLeft("hello"); assert!(op.is_some()); } #[test] fn convert_test() { let op_1: OptionalPair<&str, &str> = SomeLeft("hello"); let op_2: OptionalPair = op_1.convert(); assert_eq!(op_2, SomeLeft(String::from("hello"))); } #[test] fn map_tests() { let no: OptionalPair = Neither; let sl: OptionalPair = SomeLeft(42); let sr: OptionalPair = SomeRight(84); let sb: OptionalPair = SomeBoth(42, 84); // Map tests assert_eq!( no.clone().map(|l| l.to_string(), |r| r.to_string()), Neither ); assert_eq!( sl.clone().map(|l| l.to_string(), |r| r.to_string()), SomeLeft(String::from("42")) ); assert_eq!( sr.clone().map(|l| l.to_string(), |r| r.to_string()), SomeRight(String::from("84")) ); assert_eq!( sb.clone().map(|l| l.to_string(), |r| r.to_string()), SomeBoth(String::from("42"), String::from("84")) ); // Map left tests assert_eq!(no.clone().map_left(|l| l.to_string()), Neither); assert_eq!( sl.clone().map_left(|l| l.to_string()), SomeLeft(String::from("42")) ); assert_eq!(sr.clone().map_left(|l| l.to_string()), SomeRight(84)); assert_eq!( sb.clone().map_left(|l| l.to_string()), SomeBoth(String::from("42"), 84) ); // Map right tests assert_eq!(no.clone().map_right(|r| r.to_string()), Neither); assert_eq!(sl.clone().map_right(|r| r.to_string()), SomeLeft(42)); assert_eq!( sr.clone().map_right(|r| r.to_string()), SomeRight(String::from("84")) ); assert_eq!( sb.clone().map_right(|r| r.to_string()), SomeBoth(42, String::from("84")) ); } #[test] fn from_tests() { // None tests let no: OptionalPair = Neither; let no_opt: Option<(Option, Option)> = no.clone().into(); assert_eq!(no, OptionalPair::from(no_opt)); let no_tup: (Option, Option) = no.clone().into(); assert_eq!(no, OptionalPair::from(no_tup)); // SomeLeft tests let sl: OptionalPair = SomeLeft(42); let sl_opt: Option<(Option, Option)> = sl.clone().into(); assert_eq!(sl, OptionalPair::from(sl_opt)); let sl_tup: (Option, Option) = sl.clone().into(); assert_eq!(sl, OptionalPair::from(sl_tup)); // SomeRight tests let sr: OptionalPair = SomeRight(84); let sr_opt: Option<(Option, Option)> = sr.clone().into(); assert_eq!(sr, OptionalPair::from(sr_opt)); let sr_tup: (Option, Option) = sr.clone().into(); assert_eq!(sr, OptionalPair::from(sr_tup)); // SomeBoth tests let sb: OptionalPair = SomeBoth(42, 84); let sb_opt: Option<(Option, Option)> = sb.clone().into(); assert_eq!(sb, OptionalPair::from(sb_opt)); let sb_tup: (Option, Option) = sb.clone().into(); assert_eq!(sb, OptionalPair::from(sb_tup)); } }