1
+
2
+ namespace CSparse . Tests
3
+ {
4
+ using NUnit . Framework ;
5
+
6
+ public class PermutationTest
7
+ {
8
+ [ Test ]
9
+ public void TestCreate ( )
10
+ {
11
+ var expected = new [ ] { 0 , 1 , 2 } ;
12
+ var actual = Permutation . Create ( 3 , 0 ) ;
13
+
14
+ CollectionAssert . AreEqual ( expected , actual ) ;
15
+
16
+ expected = new [ ] { 2 , 1 , 0 } ;
17
+ actual = Permutation . Create ( 3 , - 1 ) ;
18
+
19
+ CollectionAssert . AreEqual ( expected , actual ) ;
20
+ }
21
+
22
+ [ Test ]
23
+ public void TestApply ( )
24
+ {
25
+ var vector = new double [ ] { 1d , 2d , 3d } ;
26
+ var p = new [ ] { 2 , 0 , 1 } ;
27
+
28
+ var expected = new double [ ] { 3d , 1d , 2d } ;
29
+ var actual = new double [ 3 ] ;
30
+
31
+ Permutation . Apply ( p , vector , actual , 3 ) ;
32
+
33
+ CollectionAssert . AreEqual ( expected , actual ) ;
34
+ }
35
+
36
+ [ Test ]
37
+ public void TestApplyInverse ( )
38
+ {
39
+ var vector = new double [ ] { 1d , 2d , 3d } ;
40
+ var p = new [ ] { 2 , 0 , 1 } ;
41
+
42
+ var expected = new double [ ] { 2d , 3d , 1d } ;
43
+ var actual = new double [ 3 ] ;
44
+
45
+ Permutation . ApplyInverse ( p , vector , actual , 3 ) ;
46
+
47
+ CollectionAssert . AreEqual ( expected , actual ) ;
48
+ }
49
+
50
+ [ Test ]
51
+ public void TestInvert ( )
52
+ {
53
+ var p = new [ ] { 2 , 0 , 1 } ;
54
+
55
+ var expected = new [ ] { 1 , 2 , 0 } ;
56
+ var actual = Permutation . Invert ( p ) ;
57
+
58
+ CollectionAssert . AreEqual ( expected , actual ) ;
59
+ }
60
+
61
+ [ Test ]
62
+ public void TestIsValid ( )
63
+ {
64
+ var p_valid = new [ ] { 2 , 0 , 1 } ;
65
+
66
+ Assert . IsTrue ( Permutation . IsValid ( p_valid ) ) ;
67
+
68
+ var p_invalid = new [ ] { 2 , 1 , 1 } ;
69
+
70
+ Assert . IsFalse ( Permutation . IsValid ( p_invalid ) ) ;
71
+ }
72
+ }
73
+ }
0 commit comments