Check.java: Pyret’s is, for Java

The file that makes Check.is work. Download it and keep it beside your own.

Download Check.java

It goes in the same folder as your own file. In IntelliJ IDEA that is src, beside Stripe.java. Do not edit it.

In main, one line per example, and Check.done() last:

Check.is(stripeWidth(10), 60);
Check.is(flagRow(1), "######......");
Check.done();

A check that fails prints what it got and what it expected. Check.done() prints Looks shipshape when every check passed.

It takes an enum and a record too, and asks .equals of both, which on a record compares the parts:

Check.is(sizeFor(12), Size.SMALL);
Check.is(twice(new Order("bagel", 3, 2)), new Order("bagel", 6, 2));

And two lists of Lst.java, compared element by element:

Check.is(Lst.filter(h -> h > 8, hours), Lst.of(9, 11));

A main that never reaches Check.done() is told so as the program ends, with the count of the checks that did run:

Check.done() never ran: 1 passed, 1 failed before the program ended

A copy downloaded before October 21 has none of this. Download it again, over the old one; nothing you wrote changes.

On OneCompiler: add a file named Check.java and paste the whole of this one into it. Or open the class copy, which already has both files: https://onecompiler.com/java/4544z33u6.