KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgrapht > experimental > permutation > CompoundPermutationIterTest


1 /* ==========================================
2  * JGraphT : a free Java graph-theory library
3  * ==========================================
4  *
5  * Project Info: http://jgrapht.sourceforge.net/
6  * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
7  *
8  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation,
22  * Inc.,
23  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  */

25 /* -----------------
26  * CompoundPermutationIterTest.java
27  * -----------------
28  * (C) Copyright 2005-2006, by Assaf Lehr and Contributors.
29  *
30  * Original Author: Assaf Lehr
31  * Contributor(s): -
32  *
33  * $Id: CompoundPermutationIterTest.java 504 2006-07-03 02:37:26Z perfecthash $
34  *
35  * Changes
36  * -------
37  */

38 package org.jgrapht.experimental.permutation;
39
40 import junit.framework.*;
41
42 import org.jgrapht.util.*;
43
44
45 /**
46  * @author Assaf
47  * @since May 30, 2005
48  */

49 public class CompoundPermutationIterTest
50     extends TestCase
51 {
52
53     //~ Instance fields -------------------------------------------------------
54

55     private CompoundPermutationIter complexPerm;
56
57     //~ Methods ---------------------------------------------------------------
58

59     /**
60      * Asserts that the number of permutations is the same as getMax. It also
61      * verifies that the number is the same when using different internal order
62      * of the permutation components. Note: The prints and timer can be unmarked
63      * to see performance results and the permutations array themselves.
64      */

65     public void testGetNext()
66     {
67         // System.out.println("testing complex perm {1,1,1,2,2,3,4,5} ");
68
// StopperTimer timer = new StopperTimer();
69
// timer.start();
70

71         this.complexPerm =
72             new CompoundPermutationIter(new int [] {
73                     1,
74                     1,
75                     1,
76                     2,
77                     2,
78                     3,
79                     4,
80                     5
81                 });
82         int maxPermNum = this.complexPerm.getMax();
83
84         // System.out.println(Arrays.toString(this.complexPerm.getPermAsArray()));
85
int counter = 0;
86         while (this.complexPerm.hasNext()) {
87             int [] resultArray = this.complexPerm.getNext();
88
89             if (false) {
90                 System.out.println(ArrayUtil.toString(resultArray));
91             }
92             counter++;
93         }
94
95         // System.out.println(counter);
96
assertEquals(maxPermNum, counter);
97
98         // timer.stopAndReport();
99

100         // timer.start();
101
this.complexPerm =
102             new CompoundPermutationIter(new int [] {
103                     5,
104                     4,
105                     3,
106                     2,
107                     2,
108                     1,
109                     1,
110                     1
111                 });
112
113         // System.out.println("testing complex perm {5,4,3,2,2,1,1,1} ");
114
// System.out.println(Arrays.toString(this.complexPerm.getPermAsArray()));
115
counter = 0;
116         while (this.complexPerm.hasNext()) {
117             int [] resultArray = this.complexPerm.getNext();
118
119             if (false) {
120                 System.out.println(ArrayUtil.toString(resultArray));
121             }
122             counter++;
123         }
124
125         // System.out.println(counter);
126
assertEquals(maxPermNum, counter);
127         // timer.stopAndReport();
128
}
129 }
130
Popular Tags