|
9 | 9 | import fj.F7; |
10 | 10 | import fj.F8; |
11 | 11 | import fj.Function; |
| 12 | +import fj.Bottom; |
| 13 | + |
12 | 14 | import static fj.Function.compose; |
13 | 15 | import static fj.P.p; |
14 | 16 | import fj.P1; |
@@ -1115,22 +1117,59 @@ public Stack<A> f(final Array<A> a) { |
1115 | 1117 | } |
1116 | 1118 |
|
1117 | 1119 | /** |
1118 | | - * Returns an arbitrary implementation for tree maps. |
| 1120 | + * Returns an arbitrary implementation for java.util tree maps. |
1119 | 1121 | * |
1120 | 1122 | * @param ak An arbitrary implementation for the type over which the tree map's keys are defined. |
1121 | 1123 | * @param av An arbitrary implementation for the type over which the tree map's values are |
1122 | 1124 | * defined. |
1123 | 1125 | * @return An arbitrary implementation for tree maps. |
1124 | 1126 | */ |
1125 | | - public static <K, V> Arbitrary<TreeMap<K, V>> arbTreeMap(final Arbitrary<K> ak, final Arbitrary<V> av) { |
1126 | | - return arbitrary(arbHashtable(ak, av).gen.map(new F<Hashtable<K, V>, TreeMap<K, V>>() { |
| 1127 | + public static <K, V> Arbitrary<java.util.TreeMap<K, V>> arbJavaTreeMap(final Arbitrary<K> ak, final Arbitrary<V> av) { |
| 1128 | + return arbitrary(arbHashtable(ak, av).gen.map(new F<Hashtable<K, V>, java.util.TreeMap<K, V>>() { |
1127 | 1129 | @SuppressWarnings({"UseOfObsoleteCollectionType"}) |
1128 | | - public TreeMap<K, V> f(final Hashtable<K, V> ht) { |
1129 | | - return new TreeMap<K, V>(ht); |
| 1130 | + public java.util.TreeMap<K, V> f(final Hashtable<K, V> ht) { |
| 1131 | + return new java.util.TreeMap<K, V>(ht); |
1130 | 1132 | } |
1131 | 1133 | })); |
1132 | 1134 | } |
1133 | 1135 |
|
| 1136 | + /** |
| 1137 | + * Returns an arbitrary implementation for tree maps. |
| 1138 | + */ |
| 1139 | + public static <K, V> Arbitrary<fj.data.TreeMap<K, V>> arbTreeMap(Ord<K> ord, Arbitrary<List<P2<K, V>>> al) { |
| 1140 | + return arbitrary(al.gen.map(list -> fj.data.TreeMap.treeMap(ord, list))); |
| 1141 | + } |
| 1142 | + |
| 1143 | + /** |
| 1144 | + * Returns an arbitrary implementation for tree maps. |
| 1145 | + */ |
| 1146 | + public static <K, V> Arbitrary<fj.data.TreeMap<K, V>> arbTreeMap(Ord<K> ord, Arbitrary<K> ak, Arbitrary<V> av) { |
| 1147 | + return arbTreeMap(ord, arbList(arbP2(ak, av))); |
| 1148 | + } |
| 1149 | + |
| 1150 | + /** |
| 1151 | + * Returns an arbitrary implementation for tree maps where the map size is the given arbitrary integer. |
| 1152 | + */ |
| 1153 | + public static <K, V> Arbitrary<fj.data.TreeMap<K, V>> arbTreeMap(Ord<K> ord, Arbitrary<K> ak, Arbitrary<V> av, Arbitrary<Integer> ai) { |
| 1154 | + Gen<List<P2<K, V>>> gl2 = ai.gen.bind(i -> { |
| 1155 | + if (i < 0) { |
| 1156 | + Bottom.error("Undefined: arbitrary natural is negative (" + i + ")"); |
| 1157 | + } |
| 1158 | + return Gen.sequenceN(Math.max(i, 0), Arbitrary.arbP2(ak, av).gen); |
| 1159 | + }); |
| 1160 | + return arbTreeMap(ord, arbitrary(gl2)); |
| 1161 | + } |
| 1162 | + |
| 1163 | + /** |
| 1164 | + * Returns an arbitrary implementation for tree maps where the size is less than or equal to the max size. |
| 1165 | + */ |
| 1166 | + public static <K, V> Arbitrary<fj.data.TreeMap<K, V>> arbTreeMap(Ord<K> ord, Arbitrary<K> ak, Arbitrary<V> av, int maxSize) { |
| 1167 | + if (maxSize < 0) { |
| 1168 | + Bottom.error("Undefined: arbitrary natural is negative (" + maxSize + ")"); |
| 1169 | + } |
| 1170 | + return arbTreeMap(ord, ak, av, arbitrary(Gen.choose(0, maxSize))); |
| 1171 | + } |
| 1172 | + |
1134 | 1173 | /** |
1135 | 1174 | * Returns an arbitrary implementation for tree sets. |
1136 | 1175 | * |
|
0 commit comments