use mpstthree::role::end::RoleEnd; use mpstthree::role::Role; use mpstthree::{create_multiple_broadcast_role, create_multiple_normal_role}; // Create new normal roles create_multiple_normal_role!( RoleD, RoleDDual | RoleE, RoleEDual | RoleF, RoleFDual | ); // Create new broadcasting roles create_multiple_broadcast_role!( RoleDtoAll, RoleAlltoD | RoleEtoAll, RoleAlltoE | RoleFtoAll, RoleAlltoF | ); pub fn role_a_fields() { let (role_sender, role_receiver) = RoleD::::new(); // role_sender let (here, there) = RoleEnd::new(); role_sender.sender.send(there).unwrap_or(()); assert!(here.sender.send(()).is_err()); assert_eq!(role_sender.self_head_str(), "RoleD".to_string()); assert_eq!(role_sender.self_tail_str(), "RoleEnd<>".to_string()); // role_sender let (here, there) = RoleEnd::new(); role_receiver.sender.send(there).unwrap_or(()); assert!(here.sender.send(()).is_err()); assert_eq!(role_receiver.self_head_str(), "RoleDDual".to_string()); assert_eq!(role_receiver.self_tail_str(), "RoleEnd<>".to_string()); } pub fn role_b_fields() { let (role_sender, role_receiver) = RoleE::::new(); // role_sender let (here, there) = RoleEnd::new(); role_sender.sender.send(there).unwrap_or(()); assert!(here.sender.send(()).is_err()); assert_eq!(role_sender.self_head_str(), "RoleE".to_string()); assert_eq!(role_sender.self_tail_str(), "RoleEnd<>".to_string()); // role_sender let (here, there) = RoleEnd::new(); role_receiver.sender.send(there).unwrap_or(()); assert!(here.sender.send(()).is_err()); assert_eq!(role_receiver.self_head_str(), "RoleEDual".to_string()); assert_eq!(role_receiver.self_tail_str(), "RoleEnd<>".to_string()); } pub fn role_c_fields() { let (role_sender, role_receiver) = RoleF::::new(); // role_sender let (here, there) = RoleEnd::new(); role_sender.sender.send(there).unwrap_or(()); assert!(here.sender.send(()).is_err()); assert_eq!(role_sender.self_head_str(), "RoleF".to_string()); assert_eq!(role_sender.self_tail_str(), "RoleEnd<>".to_string()); // role_sender let (here, there) = RoleEnd::new(); role_receiver.sender.send(there).unwrap_or(()); assert!(here.sender.send(()).is_err()); assert_eq!(role_receiver.self_head_str(), "RoleFDual".to_string()); assert_eq!(role_receiver.self_tail_str(), "RoleEnd<>".to_string()); } pub fn role_a_to_all_fields() { let (role_sender_1, role_sender_2) = RoleDtoAll::::new(); // role_sender_1 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_1.sender1.send(there1).unwrap_or(()); role_sender_1.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); // role_sender_2 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_2.sender1.send(there1).unwrap_or(()); role_sender_2.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); } pub fn role_all_to_a_fields() { let (role_sender_1, role_sender_2) = RoleAlltoD::::new(); // role_sender_1 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_1.sender1.send(there1).unwrap_or(()); role_sender_1.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); // role_sender_2 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_2.sender1.send(there1).unwrap_or(()); role_sender_2.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); } pub fn role_b_to_all_fields() { let (role_sender_1, role_sender_2) = RoleEtoAll::::new(); // role_sender_1 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_1.sender1.send(there1).unwrap_or(()); role_sender_1.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); // role_sender_2 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_2.sender1.send(there1).unwrap_or(()); role_sender_2.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); } pub fn role_all_to_b_fields() { let (role_sender_1, role_sender_2) = RoleAlltoE::::new(); // role_sender_1 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_1.sender1.send(there1).unwrap_or(()); role_sender_1.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); // role_sender_2 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_2.sender1.send(there1).unwrap_or(()); role_sender_2.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); } pub fn role_c_to_all_fields() { let (role_sender_1, role_sender_2) = RoleFtoAll::::new(); // role_sender_1 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_1.sender1.send(there1).unwrap_or(()); role_sender_1.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); // role_sender_2 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_2.sender1.send(there1).unwrap_or(()); role_sender_2.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); } pub fn role_all_to_c_fields() { let (role_sender_1, role_sender_2) = RoleAlltoF::::new(); // role_sender_1 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_1.sender1.send(there1).unwrap_or(()); role_sender_1.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); // role_sender_2 let (here1, there1) = RoleEnd::new(); let (here2, there2) = RoleEnd::new(); role_sender_2.sender1.send(there1).unwrap_or(()); role_sender_2.sender2.send(there2).unwrap_or(()); assert!(here1.sender.send(()).is_err()); assert!(here2.sender.send(()).is_err()); } pub fn role_head_str() { assert_eq!(RoleEnd::head_str(), "RoleEnd".to_string()); assert_eq!(RoleD::::head_str(), "RoleD".to_string()); assert_eq!(RoleE::::head_str(), "RoleE".to_string()); assert_eq!(RoleF::::head_str(), "RoleF".to_string()); assert_eq!(RoleDDual::::head_str(), "RoleDDual".to_string()); assert_eq!(RoleEDual::::head_str(), "RoleEDual".to_string()); assert_eq!(RoleFDual::::head_str(), "RoleFDual".to_string()); assert_eq!( RoleDtoAll::::head_str(), "RoleDtoAll".to_string() ); assert_eq!( RoleEtoAll::::head_str(), "RoleEtoAll".to_string() ); assert_eq!( RoleFtoAll::::head_str(), "RoleFtoAll".to_string() ); assert_eq!( RoleAlltoD::::head_str(), "RoleAlltoD".to_string() ); assert_eq!( RoleAlltoE::::head_str(), "RoleAlltoE".to_string() ); assert_eq!( RoleAlltoF::::head_str(), "RoleAlltoF".to_string() ); } pub fn role_tail_str() { assert!(RoleEnd::tail_str().is_empty()); assert_eq!(RoleD::::tail_str(), "RoleEnd<>".to_string()); assert_eq!(RoleE::::tail_str(), "RoleEnd<>".to_string()); assert_eq!(RoleF::::tail_str(), "RoleEnd<>".to_string()); assert_eq!(RoleDDual::::tail_str(), "RoleEnd<>".to_string()); assert_eq!(RoleEDual::::tail_str(), "RoleEnd<>".to_string()); assert_eq!(RoleFDual::::tail_str(), "RoleEnd<>".to_string()); assert_eq!( RoleDtoAll::::tail_str(), "RoleEnd<> + RoleEnd<>".to_string() ); assert_eq!( RoleEtoAll::::tail_str(), "RoleEnd<> + RoleEnd<>".to_string() ); assert_eq!( RoleFtoAll::::tail_str(), "RoleEnd<> + RoleEnd<>".to_string() ); assert_eq!( RoleAlltoD::::tail_str(), "RoleEnd<> + RoleEnd<>".to_string() ); assert_eq!( RoleAlltoE::::tail_str(), "RoleEnd<> + RoleEnd<>".to_string() ); assert_eq!( RoleAlltoF::::tail_str(), "RoleEnd<> + RoleEnd<>".to_string() ); }