3 import java.util.Arrays;
5 import org.junit.Assert;
8 public class MapListTest
12 public void testSomething()
14 MapList ml = new MapList(new int[]
15 { 1, 5, 10, 15, 25, 20 }, new int[]
17 MapList ml1 = new MapList(new int[]
18 { 1, 3, 17, 4 }, new int[]
20 MapList ml2 = new MapList(new int[]
23 // test internal consistency
24 int to[] = new int[51];
26 MapList mldna = new MapList(new int[]
27 { 2, 2, 6, 8, 12, 16 }, new int[]
29 int[] frm = mldna.locateInFrom(1, 1);
30 testLocateFrom(mldna, 1, 1, new int[]
34 * for (int from=1; from<=51; from++) { int[] too=ml.shiftTo(from); int[]
35 * toofrom=ml.shiftFrom(too[0]);
36 * System.out.println("ShiftFrom("+from+")=="+too[0]+" %
37 * "+too[1]+"\t+-+\tShiftTo("+too[0]+")=="+toofrom[0]+" % "+toofrom[1]); }
41 private static void testLocateFrom(MapList mldna, int i, int j, int[] ks)
43 int[] frm = mldna.locateInFrom(i, j);
44 Assert.assertEquals("Failed test locate from " + i + " to " + j,
45 Arrays.toString(frm), Arrays.toString(ks));
49 * test routine. not incremental.
55 private void testMap(MapList ml, int fromS, int fromE)
57 // todo convert to JUnit style tests
58 for (int from = 1; from <= 25; from++)
60 int[] too = ml.shiftFrom(from);
61 System.out.print("ShiftFrom(" + from + ")==");
64 System.out.print("NaN\n");
68 System.out.print(too[0] + " % " + too[1] + " (" + too[2] + ")");
69 System.out.print("\t+--+\t");
70 int[] toofrom = ml.shiftTo(too[0]);
73 if (toofrom[0] != from)
75 System.err.println("Mapping not reflexive:" + from + " "
76 + too[0] + "->" + toofrom[0]);
78 System.out.println("ShiftTo(" + too[0] + ")==" + toofrom[0]
79 + " % " + toofrom[1] + " (" + toofrom[2] + ")");
83 System.out.println("ShiftTo(" + too[0] + ")=="
84 + "NaN! - not Bijective Mapping!");
88 int mmap[][] = ml.makeFromMap();
89 System.out.println("FromMap : (" + mmap[0][0] + " " + mmap[0][1] + " "
90 + mmap[0][2] + " " + mmap[0][3] + " ");
91 for (int i = 1; i <= mmap[1].length; i++)
93 if (mmap[1][i - 1] == -1)
95 System.out.print(i + "=XXX");
100 System.out.print(i + "=" + (mmap[0][2] + mmap[1][i - 1]));
104 System.out.print("\n");
108 System.out.print(",");
111 // test range function
112 System.out.print("\nTest locateInFrom\n");
114 int f = mmap[0][2], t = mmap[0][3];
117 System.out.println("Range " + f + " to " + t);
118 int rng[] = ml.locateInFrom(f, t);
121 for (int i = 0; i < rng.length; i++)
123 System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));
128 System.out.println("No range!");
130 System.out.print("\nReversed\n");
131 rng = ml.locateInFrom(t, f);
134 for (int i = 0; i < rng.length; i++)
136 System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));
141 System.out.println("No range!");
143 System.out.print("\n");
148 System.out.print("\n");
149 mmap = ml.makeToMap();
150 System.out.println("ToMap : (" + mmap[0][0] + " " + mmap[0][1] + " "
151 + mmap[0][2] + " " + mmap[0][3] + " ");
152 for (int i = 1; i <= mmap[1].length; i++)
154 if (mmap[1][i - 1] == -1)
156 System.out.print(i + "=XXX");
161 System.out.print(i + "=" + (mmap[0][2] + mmap[1][i - 1]));
165 System.out.print("\n");
169 System.out.print(",");
172 System.out.print("\n");
173 // test range function
174 System.out.print("\nTest locateInTo\n");
176 int f = mmap[0][2], t = mmap[0][3];
179 System.out.println("Range " + f + " to " + t);
180 int rng[] = ml.locateInTo(f, t);
183 for (int i = 0; i < rng.length; i++)
185 System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));
190 System.out.println("No range!");
192 System.out.print("\nReversed\n");
193 rng = ml.locateInTo(t, f);
196 for (int i = 0; i < rng.length; i++)
198 System.out.print(rng[i] + ((i % 2 == 0) ? "," : ";"));
203 System.out.println("No range!");
207 System.out.print("\n");