@@ -1033,4 +1033,86 @@ mod tests {
10331033 } ) ) ;
10341034 assert_eq ! ( count, 17 ) ;
10351035 }
1036+
1037+ fn four_arbitrary_keys (
1038+ ) -> ( Arc < StringPolicy > , Arc < StringPolicy > , Arc < StringPolicy > , Arc < StringPolicy > ) {
1039+ let a = Arc :: new ( StringPolicy :: from_str ( "pk(A)" ) . unwrap ( ) ) ;
1040+ let b = Arc :: new ( StringPolicy :: from_str ( "pk(B)" ) . unwrap ( ) ) ;
1041+ let c = Arc :: new ( StringPolicy :: from_str ( "pk(C)" ) . unwrap ( ) ) ;
1042+ let d = Arc :: new ( StringPolicy :: from_str ( "pk(D)" ) . unwrap ( ) ) ;
1043+
1044+ ( a, b, c, d)
1045+ }
1046+
1047+ #[ test]
1048+ fn normalize_nested_and ( ) {
1049+ let ( a, b, c, d) = four_arbitrary_keys ( ) ;
1050+
1051+ let thresh0 = StringPolicy :: Threshold ( 2 , vec ! [ a. clone( ) , b. clone( ) ] ) ;
1052+ let thresh1 = StringPolicy :: Threshold ( 2 , vec ! [ c. clone( ) , d. clone( ) ] ) ;
1053+
1054+ let policy = StringPolicy :: Threshold ( 2 , vec ! [ thresh0. into( ) , thresh1. into( ) ] ) ;
1055+ let got = policy. normalized ( ) ;
1056+
1057+ let want = StringPolicy :: Threshold ( 4 , vec ! [ a, b, c, d] ) ;
1058+
1059+ assert_eq ! ( got, want)
1060+ }
1061+
1062+ #[ test]
1063+ fn normalize_nested_or ( ) {
1064+ let ( a, b, c, d) = four_arbitrary_keys ( ) ;
1065+
1066+ let thresh0 = StringPolicy :: Threshold ( 1 , vec ! [ a. clone( ) , b. clone( ) ] ) ;
1067+ let thresh1 = StringPolicy :: Threshold ( 1 , vec ! [ c. clone( ) , d. clone( ) ] ) ;
1068+
1069+ let policy = StringPolicy :: Threshold ( 1 , vec ! [ thresh0. into( ) , thresh1. into( ) ] ) ;
1070+ let got = policy. normalized ( ) ;
1071+
1072+ let want = StringPolicy :: Threshold ( 1 , vec ! [ a, b, c, d] ) ;
1073+
1074+ assert_eq ! ( got, want)
1075+ }
1076+
1077+ #[ test]
1078+ fn normalize_2_of_5_containing_2_unsatisfiable_1_trivial ( ) {
1079+ let ( a, b, _, _) = four_arbitrary_keys ( ) ;
1080+ let u = Arc :: new ( StringPolicy :: Unsatisfiable ) ;
1081+ let t = Arc :: new ( StringPolicy :: Trivial ) ;
1082+
1083+ // (2,5)-thresh with only 2 satisfiable, 1 trivial
1084+ let policy =
1085+ StringPolicy :: Threshold ( 2 , vec ! [ a. clone( ) , b. clone( ) , u. clone( ) , u. clone( ) , t] ) ;
1086+ let got = policy. normalized ( ) ;
1087+ let want = StringPolicy :: Threshold ( 1 , vec ! [ a, b] ) ;
1088+
1089+ assert_eq ! ( got, want)
1090+ }
1091+
1092+ #[ test]
1093+ fn normalize_2_of_5_containing_3_unsatisfiable ( ) {
1094+ let ( a, b, _, _) = four_arbitrary_keys ( ) ;
1095+ let u = Arc :: new ( StringPolicy :: Unsatisfiable ) ;
1096+
1097+ // (2,5)-thresh with only 2 satisfiable
1098+ let policy =
1099+ StringPolicy :: Threshold ( 2 , vec ! [ a. clone( ) , b. clone( ) , u. clone( ) , u. clone( ) , u. clone( ) ] ) ;
1100+ let got = policy. normalized ( ) ;
1101+ let want = StringPolicy :: Threshold ( 2 , vec ! [ a, b] ) ;
1102+
1103+ assert_eq ! ( got, want)
1104+ }
1105+
1106+ #[ test]
1107+ fn normalize_2_of_3_containing_2_unsatisfiable ( ) {
1108+ let ( a, _, _, _) = four_arbitrary_keys ( ) ;
1109+ let u = Arc :: new ( StringPolicy :: Unsatisfiable ) ;
1110+
1111+ // (2,3)-thresh with only 2 satisfiable
1112+ let policy = StringPolicy :: Threshold ( 2 , vec ! [ a. clone( ) , u. clone( ) , u. clone( ) ] ) ;
1113+ let got = policy. normalized ( ) ;
1114+ let want = StringPolicy :: Unsatisfiable ;
1115+
1116+ assert_eq ! ( got, want)
1117+ }
10361118}
0 commit comments