Model
class in io.proptastic
class ModelA model the code follows, from lean(…) or command(…): a process that says, for
each try’s values, what the code should answer, and which of the model’s outcomes that is. It
speaks one JSON line per line: first {"model": "Trading.reserve", "outcomes": [{"name": "approved", "about": "…"}, …], "proved": ["reserve_keeps_within"], "version": "0.1.0"}, then,
for each line of values in, {"outcome": "approved", "answer": …} out. version is
optional: without it, a Lean model’s is its Lake package’s, or a hash of its sources.
Methods
outcome
static Model.Outcome outcome(String name, String about)One of a model’s outcomes, and what it means.
answer
static Model.Answer answer(String outcome, @Nullable Object value)A model’s answer to one try: its outcome, and what the code should answer.
serve
static void serve(String name, List<Model.Outcome> outcomes, Function<List<@Nullable Object>, Model.Answer> answer)Serves a model written in Java, from its main: says its name and outcomes, then answers
each try’s values, read from standard input as JSON (whole numbers as Long, past 64
bits BigInteger; records and maps as Maps; lists, sets and arrays as Lists), until the property is done. A test follows it with java(TheModel.class):
public static void main(String[] arguments) {
Model.serve("LeapYear", List.of(outcome("leap", "…"), outcome("common", "…")), values -> {
long year = (Long) values.get(0);
boolean leap = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
return answer(leap ? "leap" : "common", leap);
});
}
An answer that throws is said as the model’s error, which fails the property.