31
32 import java.util.*;
33 import java.io.*;
34
35 public class EnumMapBash {
36 static Random rnd = new Random();
37
38 public static void main(String[] args) {
39 bash(Silly31.class);
40 bash(Silly32.class);
41 bash(Silly33.class);
42 bash(Silly63.class);
43 bash(Silly64.class);
44 bash(Silly65.class);
45 bash(Silly127.class);
46 bash(Silly128.class);
47 bash(Silly129.class);
48 bash(Silly500.class);
49 }
50
51 private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0];
52
53 static <T extends Enum<T>> void bash(Class<T> enumClass) {
54 Enum[] universe = enumClass.getEnumConstants();
55
56 int numItr = 100;
57
58 // Linked List test
59 for (int i=0; i<numItr; i++) {
60 int mapSize = universe.length * 7 / 8;
61
62 // Build the linked list
63 Map<T, T> m = new EnumMap<T, T>(enumClass);
64 if (!m.isEmpty())
65 fail("New instance non empty.");
66 Enum[] perm = (Enum[]) universe.clone();
67 Collections.shuffle(Arrays.asList(perm));
68 T head = (T) perm[0];
69 for (int j = 0; j < mapSize; j++)
70 m.put((T)perm[j], (T)perm[j + 1]);
71 T nil = (T)perm[mapSize];
72
|
31
32 import java.util.*;
33 import java.io.*;
34
35 public class EnumMapBash {
36 static Random rnd = new Random();
37
38 public static void main(String[] args) {
39 bash(Silly31.class);
40 bash(Silly32.class);
41 bash(Silly33.class);
42 bash(Silly63.class);
43 bash(Silly64.class);
44 bash(Silly65.class);
45 bash(Silly127.class);
46 bash(Silly128.class);
47 bash(Silly129.class);
48 bash(Silly500.class);
49 }
50
51 static <T extends Enum<T>> void bash(Class<T> enumClass) {
52 Enum[] universe = enumClass.getEnumConstants();
53
54 int numItr = 100;
55
56 // Linked List test
57 for (int i=0; i<numItr; i++) {
58 int mapSize = universe.length * 7 / 8;
59
60 // Build the linked list
61 Map<T, T> m = new EnumMap<T, T>(enumClass);
62 if (!m.isEmpty())
63 fail("New instance non empty.");
64 Enum[] perm = (Enum[]) universe.clone();
65 Collections.shuffle(Arrays.asList(perm));
66 T head = (T) perm[0];
67 for (int j = 0; j < mapSize; j++)
68 m.put((T)perm[j], (T)perm[j + 1]);
69 T nil = (T)perm[mapSize];
70
|