/core/src/main/java/fj/test/Coarbitrary.java

https://github.com/rafalrusin/functionaljava · Java · 1176 lines · 640 code · 90 blank · 446 comment · 3 complexity · 5648c280b34d401f5e1feb463eeb085f MD5 · raw file

  1. package fj.test;
  2. import fj.F;
  3. import fj.F2;
  4. import fj.F3;
  5. import fj.F4;
  6. import fj.F5;
  7. import fj.F6;
  8. import fj.F7;
  9. import fj.F8;
  10. import static fj.Function.curry;
  11. import static fj.P.p;
  12. import fj.P1;
  13. import fj.P2;
  14. import fj.P3;
  15. import fj.P4;
  16. import fj.P5;
  17. import fj.P6;
  18. import fj.P7;
  19. import fj.P8;
  20. import fj.data.Array;
  21. import static fj.data.Array.array;
  22. import fj.data.Either;
  23. import fj.data.List;
  24. import static fj.data.List.fromString;
  25. import static fj.data.List.nil;
  26. import fj.data.Option;
  27. import fj.data.Stream;
  28. import static fj.test.Variant.variant;
  29. import static java.lang.Double.doubleToRawLongBits;
  30. import static java.lang.Float.floatToRawIntBits;
  31. import java.math.BigDecimal;
  32. import java.math.BigInteger;
  33. import java.sql.Time;
  34. import java.sql.Timestamp;
  35. import java.util.ArrayList;
  36. import java.util.BitSet;
  37. import java.util.Calendar;
  38. import java.util.Date;
  39. import java.util.EnumMap;
  40. import java.util.EnumSet;
  41. import java.util.GregorianCalendar;
  42. import java.util.HashMap;
  43. import java.util.HashSet;
  44. import java.util.Hashtable;
  45. import java.util.IdentityHashMap;
  46. import java.util.LinkedHashMap;
  47. import java.util.LinkedHashSet;
  48. import java.util.LinkedList;
  49. import java.util.PriorityQueue;
  50. import java.util.Properties;
  51. import java.util.Stack;
  52. import java.util.TreeMap;
  53. import java.util.TreeSet;
  54. import java.util.Vector;
  55. import java.util.WeakHashMap;
  56. import java.util.concurrent.ArrayBlockingQueue;
  57. import java.util.concurrent.ConcurrentHashMap;
  58. import java.util.concurrent.ConcurrentLinkedQueue;
  59. import java.util.concurrent.CopyOnWriteArrayList;
  60. import java.util.concurrent.CopyOnWriteArraySet;
  61. import java.util.concurrent.DelayQueue;
  62. import java.util.concurrent.Delayed;
  63. import java.util.concurrent.LinkedBlockingQueue;
  64. import java.util.concurrent.PriorityBlockingQueue;
  65. import java.util.concurrent.SynchronousQueue;
  66. /**
  67. * Transforms a type and a generator to produce a new generator. This function is used to generate
  68. * {@link Arbitrary arbitrary} functions.
  69. *
  70. * @version %build.number%
  71. */
  72. public abstract class Coarbitrary<A> {
  73. /**
  74. * Transforms the given value and generator to a new generator with a high probability of being
  75. * independent.
  76. *
  77. * @param a The value to produce the generator from.
  78. * @param g The generator to produce the new generator from.
  79. * @return A new generator with a high probability of being independent.
  80. */
  81. public abstract <B> Gen<B> coarbitrary(A a, Gen<B> g);
  82. /**
  83. * A curried version of {@link #coarbitrary(Object, Gen)}.
  84. *
  85. * @param a The value to produce the generator from.
  86. * @return A curried version of {@link #coarbitrary(Object, Gen)}.
  87. */
  88. public final <B> F<Gen<B>, Gen<B>> coarbitrary(final A a) {
  89. return new F<Gen<B>, Gen<B>>() {
  90. public Gen<B> f(final Gen<B> g) {
  91. return coarbitrary(a, g);
  92. }
  93. };
  94. }
  95. /**
  96. * Composes the given function with this coarbitrary to produce a new coarbitrary.
  97. *
  98. * @param f The function to compose.
  99. * @return A new coarbitrary composed with the given function.
  100. */
  101. public final <B> Coarbitrary<B> compose(final F<B, A> f) {
  102. return new Coarbitrary<B>() {
  103. public <X> Gen<X> coarbitrary(final B b, final Gen<X> g) {
  104. return Coarbitrary.this.coarbitrary(f.f(b), g);
  105. }
  106. };
  107. }
  108. /**
  109. * Co-maps this coarbitrary using the given function.
  110. *
  111. * @param f The function to co-map with.
  112. * @return A co-mapped coarbitrary.
  113. */
  114. public final <B> Coarbitrary<B> comap(final F<B, A> f) {
  115. return new Coarbitrary<B>() {
  116. public <X> Gen<X> coarbitrary(final B b, final Gen<X> g) {
  117. return Coarbitrary.this.coarbitrary(f.f(b), g);
  118. }
  119. };
  120. }
  121. /**
  122. * A coarbitrary for a function.
  123. *
  124. * @param a An arbitrary for the domain of the function.
  125. * @param c A coarbitrary for the codomain of the function.
  126. * @return A coarbitrary for a function.
  127. */
  128. public static <A, B> Coarbitrary<F<A, B>> coarbF(final Arbitrary<A> a, final Coarbitrary<B> c) {
  129. return new Coarbitrary<F<A, B>>() {
  130. public <X> Gen<X> coarbitrary(final F<A, B> f, final Gen<X> g) {
  131. return a.gen.bind(new F<A, Gen<X>>() {
  132. public Gen<X> f(final A a) {
  133. return c.coarbitrary(f.f(a), g);
  134. }
  135. });
  136. }
  137. };
  138. }
  139. /**
  140. * A coarbitrary for a function-2.
  141. *
  142. * @param aa An arbitrary for part of the domain of the function.
  143. * @param ab An arbitrary for part of the domain of the function.
  144. * @param c A coarbitrary for the codomain of the function.
  145. * @return A coarbitrary for a function-2.
  146. */
  147. public static <A, B, C> Coarbitrary<F2<A, B, C>> coarbF2(final Arbitrary<A> aa, final Arbitrary<B> ab,
  148. final Coarbitrary<C> c) {
  149. return new Coarbitrary<F2<A, B, C>>() {
  150. public <X> Gen<X> coarbitrary(final F2<A, B, C> f, final Gen<X> g) {
  151. return coarbF(aa, coarbF(ab, c)).coarbitrary(curry(f), g);
  152. }
  153. };
  154. }
  155. /**
  156. * A coarbitrary for a function-3.
  157. *
  158. * @param aa An arbitrary for part of the domain of the function.
  159. * @param ab An arbitrary for part of the domain of the function.
  160. * @param ac An arbitrary for part of the domain of the function.
  161. * @param c A coarbitrary for the codomain of the function.
  162. * @return A coarbitrary for a function-3.
  163. */
  164. public static <A, B, C, D> Coarbitrary<F3<A, B, C, D>> coarbF3(final Arbitrary<A> aa, final Arbitrary<B> ab,
  165. final Arbitrary<C> ac, final Coarbitrary<D> c) {
  166. return new Coarbitrary<F3<A, B, C, D>>() {
  167. public <X> Gen<X> coarbitrary(final F3<A, B, C, D> f, final Gen<X> g) {
  168. return coarbF(aa, coarbF(ab, coarbF(ac, c))).coarbitrary(curry(f), g);
  169. }
  170. };
  171. }
  172. /**
  173. * A coarbitrary for a function-4.
  174. *
  175. * @param aa An arbitrary for part of the domain of the function.
  176. * @param ab An arbitrary for part of the domain of the function.
  177. * @param ac An arbitrary for part of the domain of the function.
  178. * @param ad An arbitrary for part of the domain of the function.
  179. * @param c A coarbitrary for the codomain of the function.
  180. * @return A coarbitrary for a function-4.
  181. */
  182. public static <A, B, C, D, E> Coarbitrary<F4<A, B, C, D, E>> coarbF4(final Arbitrary<A> aa, final Arbitrary<B> ab,
  183. final Arbitrary<C> ac, final Arbitrary<D> ad,
  184. final Coarbitrary<E> c) {
  185. return new Coarbitrary<F4<A, B, C, D, E>>() {
  186. public <X> Gen<X> coarbitrary(final F4<A, B, C, D, E> f, final Gen<X> g) {
  187. return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, c)))).coarbitrary(curry(f), g);
  188. }
  189. };
  190. }
  191. /**
  192. * A coarbitrary for a function-5.
  193. *
  194. * @param aa An arbitrary for part of the domain of the function.
  195. * @param ab An arbitrary for part of the domain of the function.
  196. * @param ac An arbitrary for part of the domain of the function.
  197. * @param ad An arbitrary for part of the domain of the function.
  198. * @param ae An arbitrary for part of the domain of the function.
  199. * @param c A coarbitrary for the codomain of the function.
  200. * @return A coarbitrary for a function-5.
  201. */
  202. public static <A, B, C, D, E, F$> Coarbitrary<F5<A, B, C, D, E, F$>> coarbF5(final Arbitrary<A> aa,
  203. final Arbitrary<B> ab,
  204. final Arbitrary<C> ac,
  205. final Arbitrary<D> ad,
  206. final Arbitrary<E> ae,
  207. final Coarbitrary<F$> c) {
  208. return new Coarbitrary<F5<A, B, C, D, E, F$>>() {
  209. public <X> Gen<X> coarbitrary(final F5<A, B, C, D, E, F$> f, final Gen<X> g) {
  210. return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, c))))).coarbitrary(curry(f), g);
  211. }
  212. };
  213. }
  214. /**
  215. * A coarbitrary for a function-6.
  216. *
  217. * @param aa An arbitrary for part of the domain of the function.
  218. * @param ab An arbitrary for part of the domain of the function.
  219. * @param ac An arbitrary for part of the domain of the function.
  220. * @param ad An arbitrary for part of the domain of the function.
  221. * @param ae An arbitrary for part of the domain of the function.
  222. * @param af An arbitrary for part of the domain of the function.
  223. * @param c A coarbitrary for the codomain of the function.
  224. * @return A coarbitrary for a function-6.
  225. */
  226. public static <A, B, C, D, E, F$, G> Coarbitrary<F6<A, B, C, D, E, F$, G>> coarbF6(final Arbitrary<A> aa,
  227. final Arbitrary<B> ab,
  228. final Arbitrary<C> ac,
  229. final Arbitrary<D> ad,
  230. final Arbitrary<E> ae,
  231. final Arbitrary<F$> af,
  232. final Coarbitrary<G> c) {
  233. return new Coarbitrary<F6<A, B, C, D, E, F$, G>>() {
  234. public <X> Gen<X> coarbitrary(final F6<A, B, C, D, E, F$, G> f, final Gen<X> g) {
  235. return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, c)))))).coarbitrary(curry(f), g);
  236. }
  237. };
  238. }
  239. /**
  240. * A coarbitrary for a function-7.
  241. *
  242. * @param aa An arbitrary for part of the domain of the function.
  243. * @param ab An arbitrary for part of the domain of the function.
  244. * @param ac An arbitrary for part of the domain of the function.
  245. * @param ad An arbitrary for part of the domain of the function.
  246. * @param ae An arbitrary for part of the domain of the function.
  247. * @param af An arbitrary for part of the domain of the function.
  248. * @param ag An arbitrary for part of the domain of the function.
  249. * @param c A coarbitrary for the codomain of the function.
  250. * @return A coarbitrary for a function-7.
  251. */
  252. public static <A, B, C, D, E, F$, G, H> Coarbitrary<F7<A, B, C, D, E, F$, G, H>> coarbF7(final Arbitrary<A> aa,
  253. final Arbitrary<B> ab,
  254. final Arbitrary<C> ac,
  255. final Arbitrary<D> ad,
  256. final Arbitrary<E> ae,
  257. final Arbitrary<F$> af,
  258. final Arbitrary<G> ag,
  259. final Coarbitrary<H> c) {
  260. return new Coarbitrary<F7<A, B, C, D, E, F$, G, H>>() {
  261. public <X> Gen<X> coarbitrary(final F7<A, B, C, D, E, F$, G, H> f, final Gen<X> g) {
  262. return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, coarbF(ag, c)))))))
  263. .coarbitrary(curry(f), g);
  264. }
  265. };
  266. }
  267. /**
  268. * A coarbitrary for a function-8.
  269. *
  270. * @param aa An arbitrary for part of the domain of the function.
  271. * @param ab An arbitrary for part of the domain of the function.
  272. * @param ac An arbitrary for part of the domain of the function.
  273. * @param ad An arbitrary for part of the domain of the function.
  274. * @param ae An arbitrary for part of the domain of the function.
  275. * @param af An arbitrary for part of the domain of the function.
  276. * @param ag An arbitrary for part of the domain of the function.
  277. * @param ah An arbitrary for part of the domain of the function.
  278. * @param c A coarbitrary for the codomain of the function.
  279. * @return A coarbitrary for a function-8.
  280. */
  281. public static <A, B, C, D, E, F$, G, H, I> Coarbitrary<F8<A, B, C, D, E, F$, G, H, I>> coarbF8(final Arbitrary<A> aa,
  282. final Arbitrary<B> ab,
  283. final Arbitrary<C> ac,
  284. final Arbitrary<D> ad,
  285. final Arbitrary<E> ae,
  286. final Arbitrary<F$> af,
  287. final Arbitrary<G> ag,
  288. final Arbitrary<H> ah,
  289. final Coarbitrary<I> c) {
  290. return new Coarbitrary<F8<A, B, C, D, E, F$, G, H, I>>() {
  291. public <X> Gen<X> coarbitrary(final F8<A, B, C, D, E, F$, G, H, I> f, final Gen<X> g) {
  292. return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, coarbF(ag, coarbF(ah, c))))))))
  293. .coarbitrary(curry(f), g);
  294. }
  295. };
  296. }
  297. /**
  298. * A coarbitrary for booleans.
  299. */
  300. public static final Coarbitrary<Boolean> coarbBoolean = new Coarbitrary<Boolean>() {
  301. public <B> Gen<B> coarbitrary(final Boolean b, final Gen<B> g) {
  302. return variant(b ? 0 : 1, g);
  303. }
  304. };
  305. /**
  306. * A coarbitrary for integers.
  307. */
  308. public static final Coarbitrary<Integer> coarbInteger = new Coarbitrary<Integer>() {
  309. public <B> Gen<B> coarbitrary(final Integer i, final Gen<B> g) {
  310. return variant(i >= 0 ? 2 * i : -2 * i + 1, g);
  311. }
  312. };
  313. /**
  314. * A coarbitrary for bytes.
  315. */
  316. public static final Coarbitrary<Byte> coarbByte = new Coarbitrary<Byte>() {
  317. public <B> Gen<B> coarbitrary(final Byte b, final Gen<B> g) {
  318. return variant(b >= 0 ? 2 * b : -2 * b + 1, g);
  319. }
  320. };
  321. /**
  322. * A coarbitrary for shorts.
  323. */
  324. public static final Coarbitrary<Short> coarbShort = new Coarbitrary<Short>() {
  325. public <B> Gen<B> coarbitrary(final Short s, final Gen<B> g) {
  326. return variant(s >= 0 ? 2 * s : -2 * s + 1, g);
  327. }
  328. };
  329. /**
  330. * A coarbitrary for longs.
  331. */
  332. public static final Coarbitrary<Long> coarbLong = new Coarbitrary<Long>() {
  333. public <B> Gen<B> coarbitrary(final Long l, final Gen<B> g) {
  334. return variant(l >= 0L ? 2L * l : -2L * l + 1L, g);
  335. }
  336. };
  337. /**
  338. * A coarbitrary for characters.
  339. */
  340. public static final Coarbitrary<Character> coarbCharacter = new Coarbitrary<Character>() {
  341. public <B> Gen<B> coarbitrary(final Character c, final Gen<B> g) {
  342. return variant(c << 1, g);
  343. }
  344. };
  345. /**
  346. * A coarbitrary for floats.
  347. */
  348. public static final Coarbitrary<Float> coarbFloat = new Coarbitrary<Float>() {
  349. public <B> Gen<B> coarbitrary(final Float f, final Gen<B> g) {
  350. return coarbInteger.coarbitrary(floatToRawIntBits(f), g);
  351. }
  352. };
  353. /**
  354. * A coarbitrary for doubles.
  355. */
  356. public static final Coarbitrary<Double> coarbDouble = new Coarbitrary<Double>() {
  357. public <B> Gen<B> coarbitrary(final Double d, final Gen<B> g) {
  358. return coarbLong.coarbitrary(doubleToRawLongBits(d), g);
  359. }
  360. };
  361. /**
  362. * A coarbitrary for the optional value.
  363. *
  364. * @param ca A coarbitrary for the type of the optional value.
  365. * @return A coarbitrary for the optional value.
  366. */
  367. public static <A> Coarbitrary<Option<A>> coarbOption(final Coarbitrary<A> ca) {
  368. return new Coarbitrary<Option<A>>() {
  369. public <B> Gen<B> coarbitrary(final Option<A> o, final Gen<B> g) {
  370. return o.isNone() ? variant(0, g) : variant(1, ca.coarbitrary(o.some(), g));
  371. }
  372. };
  373. }
  374. /**
  375. * A coarbitrary for the disjoint union.
  376. *
  377. * @param ca A coarbitrary for one side of the disjoint union.
  378. * @param cb A coarbitrary for one side of the disjoint union.
  379. * @return A coarbitrary for the disjoint union.
  380. */
  381. public static <A, B> Coarbitrary<Either<A, B>> coarbEither(final Coarbitrary<A> ca, final Coarbitrary<B> cb) {
  382. return new Coarbitrary<Either<A, B>>() {
  383. public <X> Gen<X> coarbitrary(final Either<A, B> e, final Gen<X> g) {
  384. return e.isLeft() ?
  385. variant(0, ca.coarbitrary(e.left().value(), g)) :
  386. variant(1, cb.coarbitrary(e.right().value(), g));
  387. }
  388. };
  389. }
  390. /**
  391. * A coarbitrary for lists.
  392. *
  393. * @param ca A coarbitrary for the elements of the list.
  394. * @return A coarbitrary for lists.
  395. */
  396. public static <A> Coarbitrary<List<A>> coarbList(final Coarbitrary<A> ca) {
  397. return new Coarbitrary<List<A>>() {
  398. public <B> Gen<B> coarbitrary(final List<A> as, final Gen<B> g) {
  399. return as.isEmpty() ?
  400. variant(0, g) :
  401. variant(1, ca.coarbitrary(as.head(), coarbitrary(as.tail(), g)));
  402. }
  403. };
  404. }
  405. /**
  406. * A coarbitrary for strings.
  407. */
  408. public static final Coarbitrary<String> coarbString = new Coarbitrary<String>() {
  409. public <B> Gen<B> coarbitrary(final String s, final Gen<B> g) {
  410. return coarbList(coarbCharacter).coarbitrary(fromString(s), g);
  411. }
  412. };
  413. /**
  414. * A coarbitrary for string buffers.
  415. */
  416. public static final Coarbitrary<StringBuffer> coarbStringBuffer = new Coarbitrary<StringBuffer>() {
  417. public <B> Gen<B> coarbitrary(final StringBuffer s, final Gen<B> g) {
  418. return coarbString.coarbitrary(s.toString(), g);
  419. }
  420. };
  421. /**
  422. * A coarbitrary for string builders.
  423. */
  424. public static final Coarbitrary<StringBuilder> coarbStringBuilder = new Coarbitrary<StringBuilder>() {
  425. public <B> Gen<B> coarbitrary(final StringBuilder s, final Gen<B> g) {
  426. return coarbString.coarbitrary(s.toString(), g);
  427. }
  428. };
  429. /**
  430. * A coarbitrary for streams.
  431. *
  432. * @param ca A coarbitrary for the elements of the stream.
  433. * @return A coarbitrary for streams.
  434. */
  435. public static <A> Coarbitrary<Stream<A>> coarbStream(final Coarbitrary<A> ca) {
  436. return new Coarbitrary<Stream<A>>() {
  437. public <B> Gen<B> coarbitrary(final Stream<A> as, final Gen<B> g) {
  438. return as.isEmpty() ?
  439. variant(0, g) :
  440. variant(1, ca.coarbitrary(as.head(), coarbitrary(as.tail()._1(), g)));
  441. }
  442. };
  443. }
  444. /**
  445. * A coarbitrary for arrays.
  446. *
  447. * @param ca A coarbitrary for the elements of the array.
  448. * @return A coarbitrary for arrays.
  449. */
  450. public static <A> Coarbitrary<Array<A>> coarbArray(final Coarbitrary<A> ca) {
  451. return new Coarbitrary<Array<A>>() {
  452. public <B> Gen<B> coarbitrary(final Array<A> as, final Gen<B> g) {
  453. return coarbList(ca).coarbitrary(as.toList(), g);
  454. }
  455. };
  456. }
  457. /**
  458. * A coarbitrary for throwables.
  459. *
  460. * @param cs A coarbitrary for the throwable message.
  461. * @return A coarbitrary for throwables.
  462. */
  463. public static Coarbitrary<Throwable> coarbThrowable(final Coarbitrary<String> cs) {
  464. return cs.comap(new F<Throwable, String>() {
  465. public String f(final Throwable t) {
  466. return t.getMessage();
  467. }
  468. });
  469. }
  470. /**
  471. * A coarbitrary for throwables.
  472. */
  473. public static final Coarbitrary<Throwable> coarbThrowable =
  474. coarbThrowable(coarbString);
  475. // BEGIN java.util
  476. /**
  477. * A coarbitrary for array lists.
  478. *
  479. * @param ca A coarbitrary for the elements of the array list.
  480. * @return A coarbitrary for array lists.
  481. */
  482. public static <A> Coarbitrary<ArrayList<A>> coarbArrayList(final Coarbitrary<A> ca) {
  483. return new Coarbitrary<ArrayList<A>>() {
  484. @SuppressWarnings({"unchecked"})
  485. public <B> Gen<B> coarbitrary(final ArrayList<A> as, final Gen<B> g) {
  486. return coarbArray(ca).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  487. }
  488. };
  489. }
  490. /**
  491. * A coarbitrary for bit sets.
  492. */
  493. public static final Coarbitrary<BitSet> coarbBitSet = new Coarbitrary<BitSet>() {
  494. public <B> Gen<B> coarbitrary(final BitSet s, final Gen<B> g) {
  495. List<Boolean> x = nil();
  496. for (int i = 0; i < s.size(); i++) {
  497. x = x.snoc(s.get(i));
  498. }
  499. return coarbList(coarbBoolean).coarbitrary(x, g);
  500. }
  501. };
  502. /**
  503. * A coarbitrary for calendars.
  504. */
  505. public static final Coarbitrary<Calendar> coarbCalendar = new Coarbitrary<Calendar>() {
  506. public <B> Gen<B> coarbitrary(final Calendar c, final Gen<B> g) {
  507. return coarbLong.coarbitrary(c.getTime().getTime(), g);
  508. }
  509. };
  510. /**
  511. * A coarbitrary for dates.
  512. */
  513. public static final Coarbitrary<Date> coarbDate = new Coarbitrary<Date>() {
  514. public <B> Gen<B> coarbitrary(final Date d, final Gen<B> g) {
  515. return coarbLong.coarbitrary(d.getTime(), g);
  516. }
  517. };
  518. /**
  519. * A coarbitrary for enum maps.
  520. *
  521. * @param ck A coarbitrary for the map keys.
  522. * @param cv A coarbitrary for the map values.
  523. * @return A coarbitrary for enum maps.
  524. */
  525. public static <K extends Enum<K>, V> Coarbitrary<EnumMap<K, V>> coarbEnumMap(final Coarbitrary<K> ck,
  526. final Coarbitrary<V> cv) {
  527. return new Coarbitrary<EnumMap<K, V>>() {
  528. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  529. public <B> Gen<B> coarbitrary(final EnumMap<K, V> m, final Gen<B> g) {
  530. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  531. }
  532. };
  533. }
  534. /**
  535. * A coarbitrary for enum sets.
  536. *
  537. * @param c A coarbitrary for the elements of the enum set.
  538. * @return A coarbitrary for enum sets.
  539. */
  540. public static <A extends Enum<A>> Coarbitrary<EnumSet<A>> coarbEnumSet(final Coarbitrary<A> c) {
  541. return new Coarbitrary<EnumSet<A>>() {
  542. @SuppressWarnings({"unchecked"})
  543. public <B> Gen<B> coarbitrary(final EnumSet<A> as, final Gen<B> g) {
  544. return coarbHashSet(c).coarbitrary(new HashSet<A>(as), g);
  545. }
  546. };
  547. }
  548. /**
  549. * A coarbitrary for gregorian calendars.
  550. */
  551. public static final Coarbitrary<GregorianCalendar> coarbGregorianCalendar = new Coarbitrary<GregorianCalendar>() {
  552. public <B> Gen<B> coarbitrary(final GregorianCalendar c, final Gen<B> g) {
  553. return coarbLong.coarbitrary(c.getTime().getTime(), g);
  554. }
  555. };
  556. /**
  557. * A coarbitrary for hash maps.
  558. *
  559. * @param ck A coarbitrary for the map keys.
  560. * @param cv A coarbitrary for the map values.
  561. * @return A coarbitrary for hash maps.
  562. */
  563. public static <K, V> Coarbitrary<HashMap<K, V>> coarbHashMap(final Coarbitrary<K> ck, final Coarbitrary<V> cv) {
  564. return new Coarbitrary<HashMap<K, V>>() {
  565. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  566. public <B> Gen<B> coarbitrary(final HashMap<K, V> m, final Gen<B> g) {
  567. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  568. }
  569. };
  570. }
  571. /**
  572. * A coarbitrary for hash sets.
  573. *
  574. * @param c A coarbitrary for the elements of the hash set.
  575. * @return A coarbitrary for hash sets.
  576. */
  577. public static <A> Coarbitrary<HashSet<A>> coarbHashSet(final Coarbitrary<A> c) {
  578. return new Coarbitrary<HashSet<A>>() {
  579. @SuppressWarnings({"unchecked"})
  580. public <B> Gen<B> coarbitrary(final HashSet<A> as, final Gen<B> g) {
  581. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  582. }
  583. };
  584. }
  585. /**
  586. * A coarbitrary for hash tables.
  587. *
  588. * @param ck A coarbitrary for the map keys.
  589. * @param cv A coarbitrary for the map values.
  590. * @return A coarbitrary for hash tables.
  591. */
  592. public static <K, V> Coarbitrary<Hashtable<K, V>> coarbHashtable(final Coarbitrary<K> ck, final Coarbitrary<V> cv) {
  593. return new Coarbitrary<Hashtable<K, V>>() {
  594. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  595. public <B> Gen<B> coarbitrary(final Hashtable<K, V> h, final Gen<B> g) {
  596. List<P2<K, V>> x = nil();
  597. for (final K k : h.keySet()) {
  598. x = x.snoc(p(k, h.get(k)));
  599. }
  600. return coarbList(coarbP2(ck, cv)).coarbitrary(x, g);
  601. }
  602. };
  603. }
  604. /**
  605. * A coarbitrary for identity hash maps.
  606. *
  607. * @param ck A coarbitrary for the map keys.
  608. * @param cv A coarbitrary for the map values.
  609. * @return A coarbitrary for identity hash maps.
  610. */
  611. public static <K, V> Coarbitrary<IdentityHashMap<K, V>> coarbIdentityHashMap(final Coarbitrary<K> ck,
  612. final Coarbitrary<V> cv) {
  613. return new Coarbitrary<IdentityHashMap<K, V>>() {
  614. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  615. public <B> Gen<B> coarbitrary(final IdentityHashMap<K, V> m, final Gen<B> g) {
  616. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  617. }
  618. };
  619. }
  620. /**
  621. * A coarbitrary for linked hash maps.
  622. *
  623. * @param ck A coarbitrary for the map keys.
  624. * @param cv A coarbitrary for the map values.
  625. * @return A coarbitrary for linked hash maps.
  626. */
  627. public static <K, V> Coarbitrary<LinkedHashMap<K, V>> coarbLinkedHashMap(final Coarbitrary<K> ck,
  628. final Coarbitrary<V> cv) {
  629. return new Coarbitrary<LinkedHashMap<K, V>>() {
  630. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  631. public <B> Gen<B> coarbitrary(final LinkedHashMap<K, V> m, final Gen<B> g) {
  632. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  633. }
  634. };
  635. }
  636. /**
  637. * A coarbitrary for linked hash sets.
  638. *
  639. * @param c A coarbitrary for the elements of the linked hash set.
  640. * @return A coarbitrary for linked hash sets.
  641. */
  642. public static <A> Coarbitrary<LinkedHashSet<A>> coarbLinkedHashSet(final Coarbitrary<A> c) {
  643. return new Coarbitrary<LinkedHashSet<A>>() {
  644. @SuppressWarnings({"unchecked"})
  645. public <B> Gen<B> coarbitrary(final LinkedHashSet<A> as, final Gen<B> g) {
  646. return coarbHashSet(c).coarbitrary(new HashSet<A>(as), g);
  647. }
  648. };
  649. }
  650. /**
  651. * A coarbitrary for linked lists.
  652. *
  653. * @param c A coarbitrary for the elements of the linked list.
  654. * @return A coarbitrary for linked lists.
  655. */
  656. public static <A> Coarbitrary<LinkedList<A>> coarbLinkedList(final Coarbitrary<A> c) {
  657. return new Coarbitrary<LinkedList<A>>() {
  658. @SuppressWarnings({"unchecked"})
  659. public <B> Gen<B> coarbitrary(final LinkedList<A> as, final Gen<B> g) {
  660. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  661. }
  662. };
  663. }
  664. /**
  665. * A coarbitrary for priority queues.
  666. *
  667. * @param c A coarbitrary for the elements of the priority queue.
  668. * @return A coarbitrary for priority queues.
  669. */
  670. public static <A> Coarbitrary<PriorityQueue<A>> coarbPriorityQueue(final Coarbitrary<A> c) {
  671. return new Coarbitrary<PriorityQueue<A>>() {
  672. @SuppressWarnings({"unchecked"})
  673. public <B> Gen<B> coarbitrary(final PriorityQueue<A> as, final Gen<B> g) {
  674. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  675. }
  676. };
  677. }
  678. /**
  679. * A coarbitrary for properties.
  680. */
  681. public static final Coarbitrary<Properties> coarbProperties = new Coarbitrary<Properties>() {
  682. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  683. public <B> Gen<B> coarbitrary(final Properties p, final Gen<B> g) {
  684. final Hashtable<String, String> t = new Hashtable<String, String>();
  685. for (final Object s : p.keySet()) {
  686. t.put((String) s, p.getProperty((String) s));
  687. }
  688. return coarbHashtable(coarbString, coarbString).coarbitrary(t, g);
  689. }
  690. };
  691. /**
  692. * A coarbitrary for stacks.
  693. *
  694. * @param c A coarbitrary for the elements of the stack.
  695. * @return A coarbitrary for stacks.
  696. */
  697. public static <A> Coarbitrary<Stack<A>> coarbStack(final Coarbitrary<A> c) {
  698. return new Coarbitrary<Stack<A>>() {
  699. @SuppressWarnings({"unchecked"})
  700. public <B> Gen<B> coarbitrary(final Stack<A> as, final Gen<B> g) {
  701. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  702. }
  703. };
  704. }
  705. /**
  706. * A coarbitrary for tree maps.
  707. *
  708. * @param ck A coarbitrary for the map keys.
  709. * @param cv A coarbitrary for the map values.
  710. * @return A coarbitrary for tree maps.
  711. */
  712. public static <K, V> Coarbitrary<TreeMap<K, V>> coarbTreeMap(final Coarbitrary<K> ck, final Coarbitrary<V> cv) {
  713. return new Coarbitrary<TreeMap<K, V>>() {
  714. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  715. public <B> Gen<B> coarbitrary(final TreeMap<K, V> m, final Gen<B> g) {
  716. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  717. }
  718. };
  719. }
  720. /**
  721. * A coarbitrary for tree sets.
  722. *
  723. * @param c A coarbitrary for the elements of the tree set.
  724. * @return A coarbitrary for tree sets.
  725. */
  726. public static <A> Coarbitrary<TreeSet<A>> coarbTreeSet(final Coarbitrary<A> c) {
  727. return new Coarbitrary<TreeSet<A>>() {
  728. @SuppressWarnings({"unchecked"})
  729. public <B> Gen<B> coarbitrary(final TreeSet<A> as, final Gen<B> g) {
  730. return coarbHashSet(c).coarbitrary(new HashSet<A>(as), g);
  731. }
  732. };
  733. }
  734. /**
  735. * A coarbitrary for vectors.
  736. *
  737. * @param c A coarbitrary for the elements of the vector.
  738. * @return A coarbitrary for vectors.
  739. */
  740. public static <A> Coarbitrary<Vector<A>> coarbVector(final Coarbitrary<A> c) {
  741. return new Coarbitrary<Vector<A>>() {
  742. @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"})
  743. public <B> Gen<B> coarbitrary(final Vector<A> as, final Gen<B> g) {
  744. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  745. }
  746. };
  747. }
  748. /**
  749. * A coarbitrary for weak hash maps.
  750. *
  751. * @param ck A coarbitrary for the map keys.
  752. * @param cv A coarbitrary for the map values.
  753. * @return A coarbitrary for weak hash maps.
  754. */
  755. public static <K, V> Coarbitrary<WeakHashMap<K, V>> coarbWeakHashMap(final Coarbitrary<K> ck,
  756. final Coarbitrary<V> cv) {
  757. return new Coarbitrary<WeakHashMap<K, V>>() {
  758. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  759. public <B> Gen<B> coarbitrary(final WeakHashMap<K, V> m, final Gen<B> g) {
  760. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  761. }
  762. };
  763. }
  764. // END java.util
  765. // BEGIN java.util.concurrent
  766. /**
  767. * A coarbitrary for array blocking queues.
  768. *
  769. * @param c A coarbitrary for the elements of the array blocking queue.
  770. * @return A coarbitrary for array blocking queues.
  771. */
  772. public static <A> Coarbitrary<ArrayBlockingQueue<A>> coarbArrayBlockingQueue(final Coarbitrary<A> c) {
  773. return new Coarbitrary<ArrayBlockingQueue<A>>() {
  774. @SuppressWarnings({"unchecked"})
  775. public <B> Gen<B> coarbitrary(final ArrayBlockingQueue<A> as, final Gen<B> g) {
  776. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  777. }
  778. };
  779. }
  780. /**
  781. * A coarbitrary for concurrent hash maps.
  782. *
  783. * @param ck A coarbitrary for the map keys.
  784. * @param cv A coarbitrary for the map values.
  785. * @return A coarbitrary for concurrent hash maps.
  786. */
  787. public static <K, V> Coarbitrary<ConcurrentHashMap<K, V>> coarbConcurrentHashMap(final Coarbitrary<K> ck,
  788. final Coarbitrary<V> cv) {
  789. return new Coarbitrary<ConcurrentHashMap<K, V>>() {
  790. @SuppressWarnings({"UseOfObsoleteCollectionType"})
  791. public <B> Gen<B> coarbitrary(final ConcurrentHashMap<K, V> m, final Gen<B> g) {
  792. return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
  793. }
  794. };
  795. }
  796. /**
  797. * A coarbitrary for concurrent linked queues.
  798. *
  799. * @param c A coarbitrary for the elements of the concurrent linked queue.
  800. * @return A coarbitrary for concurrent linked queues.
  801. */
  802. public static <A> Coarbitrary<ConcurrentLinkedQueue<A>> coarbConcurrentLinkedQueue(final Coarbitrary<A> c) {
  803. return new Coarbitrary<ConcurrentLinkedQueue<A>>() {
  804. @SuppressWarnings({"unchecked"})
  805. public <B> Gen<B> coarbitrary(final ConcurrentLinkedQueue<A> as, final Gen<B> g) {
  806. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  807. }
  808. };
  809. }
  810. /**
  811. * A coarbitrary for copy-on-write array lists.
  812. *
  813. * @param c A coarbitrary for the elements of the copy-on-write array list.
  814. * @return A coarbitrary for copy-on-write array lists.
  815. */
  816. public static <A> Coarbitrary<CopyOnWriteArrayList<A>> coarbCopyOnWriteArrayList(final Coarbitrary<A> c) {
  817. return new Coarbitrary<CopyOnWriteArrayList<A>>() {
  818. @SuppressWarnings({"unchecked"})
  819. public <B> Gen<B> coarbitrary(final CopyOnWriteArrayList<A> as, final Gen<B> g) {
  820. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  821. }
  822. };
  823. }
  824. /**
  825. * A coarbitrary for copy-on-write array sets.
  826. *
  827. * @param c A coarbitrary for the elements of the copy-on-write array set.
  828. * @return A coarbitrary for copy-on-write array sets.
  829. */
  830. public static <A> Coarbitrary<CopyOnWriteArraySet<A>> coarbCopyOnWriteArraySet(final Coarbitrary<A> c) {
  831. return new Coarbitrary<CopyOnWriteArraySet<A>>() {
  832. @SuppressWarnings({"unchecked"})
  833. public <B> Gen<B> coarbitrary(final CopyOnWriteArraySet<A> as, final Gen<B> g) {
  834. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  835. }
  836. };
  837. }
  838. /**
  839. * A coarbitrary for delay queues.
  840. *
  841. * @param c A coarbitrary for the elements of the delay queue.
  842. * @return A coarbitrary for delay queues.
  843. */
  844. public static <A extends Delayed> Coarbitrary<DelayQueue<A>> coarbDelayQueue(final Coarbitrary<A> c) {
  845. return new Coarbitrary<DelayQueue<A>>() {
  846. @SuppressWarnings({"unchecked"})
  847. public <B> Gen<B> coarbitrary(final DelayQueue<A> as, final Gen<B> g) {
  848. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  849. }
  850. };
  851. }
  852. /**
  853. * A coarbitrary for linked blocking queues.
  854. *
  855. * @param c A coarbitrary for the elements of the linked blocking queue.
  856. * @return A coarbitrary for linked blocking queues.
  857. */
  858. public static <A> Coarbitrary<LinkedBlockingQueue<A>> coarbLinkedBlockingQueue(final Coarbitrary<A> c) {
  859. return new Coarbitrary<LinkedBlockingQueue<A>>() {
  860. @SuppressWarnings({"unchecked"})
  861. public <B> Gen<B> coarbitrary(final LinkedBlockingQueue<A> as, final Gen<B> g) {
  862. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  863. }
  864. };
  865. }
  866. /**
  867. * A coarbitrary for priority blocking queues.
  868. *
  869. * @param c A coarbitrary for the elements of the priority blocking queue.
  870. * @return A coarbitrary for priority blocking queues.
  871. */
  872. public static <A> Coarbitrary<PriorityBlockingQueue<A>> coarbPriorityBlockingQueue(final Coarbitrary<A> c) {
  873. return new Coarbitrary<PriorityBlockingQueue<A>>() {
  874. @SuppressWarnings({"unchecked"})
  875. public <B> Gen<B> coarbitrary(final PriorityBlockingQueue<A> as, final Gen<B> g) {
  876. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  877. }
  878. };
  879. }
  880. /**
  881. * A coarbitrary for synchronous queues.
  882. *
  883. * @param c A coarbitrary for the elements of the synchronous queue.
  884. * @return A coarbitrary for synchronous queues.
  885. */
  886. public static <A> Coarbitrary<SynchronousQueue<A>> coarbSynchronousQueue(final Coarbitrary<A> c) {
  887. return new Coarbitrary<SynchronousQueue<A>>() {
  888. @SuppressWarnings({"unchecked"})
  889. public <B> Gen<B> coarbitrary(final SynchronousQueue<A> as, final Gen<B> g) {
  890. return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
  891. }
  892. };
  893. }
  894. // END java.util.concurrent
  895. // BEGIN java.sql
  896. public static final Coarbitrary<java.sql.Date> coarbSQLDate = new Coarbitrary<java.sql.Date>() {
  897. public <B> Gen<B> coarbitrary(final java.sql.Date d, final Gen<B> g) {
  898. return coarbLong.coarbitrary(d.getTime(), g);
  899. }
  900. };
  901. public static final Coarbitrary<Timestamp> coarbTimestamp = new Coarbitrary<Timestamp>() {
  902. public <B> Gen<B> coarbitrary(final Timestamp t, final Gen<B> g) {
  903. return coarbLong.coarbitrary(t.getTime(), g);
  904. }
  905. };
  906. public static final Coarbitrary<Time> coarbTime = new Coarbitrary<Time>() {
  907. public <B> Gen<B> coarbitrary(final Time t, final Gen<B> g) {
  908. return coarbLong.coarbitrary(t.getTime(), g);
  909. }
  910. };
  911. // END java.sql
  912. // BEGIN java.math
  913. public static final Coarbitrary<BigInteger> coarbBigInteger = new Coarbitrary<BigInteger>() {
  914. public <B> Gen<B> coarbitrary(final BigInteger i, final Gen<B> g) {
  915. return variant((i.compareTo(BigInteger.ZERO) >= 0 ?
  916. i.multiply(BigInteger.valueOf(2L)) :
  917. i.multiply(BigInteger.valueOf(-2L).add(BigInteger.ONE))).longValue(), g);
  918. }
  919. };
  920. public static final Coarbitrary<BigDecimal> coarbBigDecimal = new Coarbitrary<BigDecimal>() {
  921. public <B> Gen<B> coarbitrary(final BigDecimal d, final Gen<B> g) {
  922. return variant((d.compareTo(BigDecimal.ZERO) >= 0 ?
  923. d.multiply(BigDecimal.valueOf(2L)) :
  924. d.multiply(BigDecimal.valueOf(-2L).add(BigDecimal.ONE))).longValue(), g);
  925. }
  926. };
  927. // END java.math
  928. /**
  929. * A coarbitrary for product-1 values.
  930. *
  931. * @param ca A coarbitrary for one of the types over which the product-1 is defined.
  932. * @return A coarbitrary for product-1 values.
  933. */
  934. public static <A> Coarbitrary<P1<A>> coarbP1(final Coarbitrary<A> ca) {
  935. return new Coarbitrary<P1<A>>() {
  936. public <B> Gen<B> coarbitrary(final P1<A> p, final Gen<B> g) {
  937. return ca.coarbitrary(p._1(), g);
  938. }
  939. };
  940. }
  941. /**
  942. * A coarbitrary for product-2 values.
  943. *
  944. * @param ca A coarbitrary for one of the types over which the product-2 is defined.
  945. * @param cb A coarbitrary for one of the types over which the product-2 is defined.
  946. * @return A coarbitrary for product-2 values.
  947. */
  948. public static <A, B> Coarbitrary<P2<A, B>> coarbP2(final Coarbitrary<A> ca, final Coarbitrary<B> cb) {
  949. return new Coarbitrary<P2<A, B>>() {
  950. public <X> Gen<X> coarbitrary(final P2<A, B> p, final Gen<X> g) {
  951. return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), g));
  952. }
  953. };
  954. }
  955. /**
  956. * A coarbitrary for product-3 values.
  957. *
  958. * @param ca A coarbitrary for one of the types over which the product-3 is defined.
  959. * @param cb A coarbitrary for one of the types over which the product-3 is defined.
  960. * @param cc A coarbitrary for one of the types over which the product-3 is defined.
  961. * @return A coarbitrary for product-3 values.
  962. */
  963. public static <A, B, C> Coarbitrary<P3<A, B, C>> coarbP3(final Coarbitrary<A> ca, final Coarbitrary<B> cb,
  964. final Coarbitrary<C> cc) {
  965. return new Coarbitrary<P3<A, B, C>>() {
  966. public <X> Gen<X> coarbitrary(final P3<A, B, C> p, final Gen<X> g) {
  967. return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), g)));
  968. }
  969. };
  970. }
  971. /**
  972. * A coarbitrary for product-4 values.
  973. *
  974. * @param ca A coarbitrary for one of the types over which the product-4 is defined.
  975. * @param cb A coarbitrary for one of the types over which the product-4 is defined.
  976. * @param cc A coarbitrary for one of the types over which the product-4 is defined.
  977. * @param cd A coarbitrary for one of the types over which the product-4 is defined.
  978. * @return A coarbitrary for product-4 values.
  979. */
  980. public static <A, B, C, D> Coarbitrary<P4<A, B, C, D>> coarbP4(final Coarbitrary<A> ca, final Coarbitrary<B> cb,
  981. final Coarbitrary<C> cc, final Coarbitrary<D> cd) {
  982. return new Coarbitrary<P4<A, B, C, D>>() {
  983. public <X> Gen<X> coarbitrary(final P4<A, B, C, D> p, final Gen<X> g) {
  984. return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), g))));
  985. }
  986. };
  987. }
  988. /**
  989. * A coarbitrary for product-5 values.
  990. *
  991. * @param ca A coarbitrary for one of the types over which the product-5 is defined.
  992. * @param cb A coarbitrary for one of the types over which the product-5 is defined.
  993. * @param cc A coarbitrary for one of the types over which the product-5 is defined.
  994. * @param cd A coarbitrary for one of the types over which the product-5 is defined.
  995. * @param ce A coarbitrary for one of the types over which the product-5 is defined.
  996. * @return A coarbitrary for product-5 values.
  997. */
  998. public static <A, B, C, D, E> Coarbitrary<P5<A, B, C, D, E>> coarbP5(final Coarbitrary<A> ca, final Coarbitrary<B> cb,
  999. final Coarbitrary<C> cc, final Coarbitrary<D> cd,
  1000. final Coarbitrary<E> ce) {
  1001. return new Coarbitrary<P5<A, B, C, D, E>>() {
  1002. public <X> Gen<X> coarbitrary(final P5<A, B, C, D, E> p, final Gen<X> g) {
  1003. return ca.coarbitrary(p._1(),
  1004. cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), g)))));
  1005. }
  1006. };
  1007. }
  1008. /**
  1009. * A coarbitrary for product-6 values.
  1010. *
  1011. * @param ca A coarbitrary for one of the types over which the product-6 is defined.
  1012. * @param cb A coarbitrary for one of the types over which the product-6 is defined.
  1013. * @param cc A coarbitrary for one of the types over which the product-6 is defined.
  1014. * @param cd A coarbitrary for one of the types over which the product-6 is defined.
  1015. * @param ce A coarbitrary for one of the types over which the product-6 is defined.
  1016. * @param cf A coarbitrary for one of the types over which the product-6 is defined.
  1017. * @return A coarbitrary for product-6 values.
  1018. */
  1019. public static <A, B, C, D, E, F$> Coarbitrary<P6<A, B, C, D, E, F$>> coarbP6(final Coarbitrary<A> ca,
  1020. final Coarbitrary<B> cb,
  1021. final Coarbitrary<C> cc,
  1022. final Coarbitrary<D> cd,
  1023. final Coarbitrary<E> ce,
  1024. final Coarbitrary<F$> cf) {
  1025. return new Coarbitrary<P6<A, B, C, D, E, F$>>() {
  1026. public <X> Gen<X> coarbitrary(final P6<A, B, C, D, E, F$> p, final Gen<X> g) {
  1027. return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(),
  1028. cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), g))))));
  1029. }
  1030. };
  1031. }
  1032. /**
  1033. * A coarbitrary for product-7 values.
  1034. *
  1035. * @param ca A coarbitrary for one of the types over which the product-7 is defined.
  1036. * @param cb A coarbitrary for one of the types over which the product-7 is defined.
  1037. * @param cc A coarbitrary for one of the types over which the product-7 is defined.
  1038. * @param cd A coarbitrary for one of the types over which the product-7 is defined.
  1039. * @param ce A coarbitrary for one of the types over which the product-7 is defined.
  1040. * @param cf A coarbitrary for one of the types over which the product-7 is defined.
  1041. * @param cg A coarbitrary for one of the types over which the product-7 is defined.
  1042. * @return A coarbitrary for product-7 values.
  1043. */
  1044. public static <A, B, C, D, E, F$, G> Coarbitrary<P7<A, B, C, D, E, F$, G>> coarbP7(final Coarbitrary<A> ca,
  1045. final Coarbitrary<B> cb,
  1046. final Coarbitrary<C> cc,
  1047. final Coarbitrary<D> cd,
  1048. final Coarbitrary<E> ce,
  1049. final Coarbitrary<F$> cf,
  1050. final Coarbitrary<G> cg) {
  1051. return new Coarbitrary<P7<A, B, C, D, E, F$, G>>() {
  1052. public <X> Gen<X> coarbitrary(final P7<A, B, C, D, E, F$, G> p, final Gen<X> g) {
  1053. return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(),
  1054. cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), cg.coarbitrary(p._7(), g)))))));
  1055. }
  1056. };
  1057. }
  1058. /**
  1059. * A coarbitrary for product-8 values.
  1060. *
  1061. * @param ca A coarbitrary for one of the types over which the product-8 is defined.
  1062. * @param cb A coarbitrary for one of the types over which the product-8 is defined.
  1063. * @param cc A coarbitrary for one of the types over which the product-8 is defined.
  1064. * @param cd A coarbitrary for one of the types over which the product-8 is defined.
  1065. * @param ce A coarbitrary for one of the types over which the product-8 is defined.
  1066. * @param cf A coarbitrary for one of the types over which the product-8 is defined.
  1067. * @param cg A coarbitrary for one of the types over which the product-8 is defined.
  1068. * @param ch A coarbitrary for one of the types over which the product-8 is defined.
  1069. * @return A coarbitrary for product-8 values.
  1070. */
  1071. public static <A, B, C, D, E, F$, G, H> Coarbitrary<P8<A, B, C, D, E, F$, G, H>> coarbP8(final Coarbitrary<A> ca,
  1072. final Coarbitrary<B> cb,
  1073. final Coarbitrary<C> cc,
  1074. final Coarbitrary<D> cd,
  1075. final Coarbitrary<E> ce,
  1076. final Coarbitrary<F$> cf,
  1077. final Coarbitrary<G> cg,
  1078. final Coarbitrary<H> ch) {
  1079. return new Coarbitrary<P8<A, B, C, D, E, F$, G, H>>() {
  1080. public <X> Gen<X> coarbitrary(final P8<A, B, C, D, E, F$, G, H> p, final Gen<X> g) {
  1081. return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(),
  1082. ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), cg.coarbitrary(p._7(), ch.coarbitrary(p._8(), g))))))));
  1083. }
  1084. };
  1085. }
  1086. }