@@ -43,6 +43,35 @@ public class PermutationTestCases {
43
43
// that use a source of randomness that is seedable.
44
44
private static final boolean disableChiSquareTests = true ;
45
45
46
+ @ Test
47
+ public void testUnaryOperator () {
48
+ Permutation p = new Permutation (10 );
49
+ p .apply (perm -> { for (int i = 0 ; i < perm .length ; i ++) { perm [i ] = i ; }});
50
+ for (int i = 0 ; i < 10 ; i ++) {
51
+ assertEquals (i , p .get (i ));
52
+ }
53
+ p .apply (perm -> { for (int i = 0 ; i < perm .length ; i ++) { perm [perm .length -1 -i ] = i ; }});
54
+ for (int i = 0 ; i < 10 ; i ++) {
55
+ assertEquals (9 -i , p .get (i ));
56
+ }
57
+ }
58
+
59
+ @ Test
60
+ public void testBinaryOperator () {
61
+ Permutation p1 = new Permutation (10 );
62
+ Permutation p2 = new Permutation (10 );
63
+ p1 .apply ((perm1 , perm2 ) -> { for (int i = 0 ; i < perm1 .length ; i ++) { perm1 [i ] = i ; perm2 [perm1 .length -1 -i ] = i ; }}, p2 );
64
+ for (int i = 0 ; i < 10 ; i ++) {
65
+ assertEquals (i , p1 .get (i ));
66
+ assertEquals (9 -i , p2 .get (i ));
67
+ }
68
+ p1 .apply ((perm1 , perm2 ) -> { for (int i = 0 ; i < perm1 .length ; i ++) { perm2 [i ] = i ; perm1 [perm1 .length -1 -i ] = i ; }}, p2 );
69
+ for (int i = 0 ; i < 10 ; i ++) {
70
+ assertEquals (i , p2 .get (i ));
71
+ assertEquals (9 -i , p1 .get (i ));
72
+ }
73
+ }
74
+
46
75
@ Test
47
76
public void testZeroLengthPermutations () {
48
77
// different ways of constructing 0 length permutations.
0 commit comments