(Context ctx)
| 1319 | // / Create an enumeration data type. |
| 1320 | |
| 1321 | public <T extends Sort> void enumExampleTyped(Context ctx) throws TestFailedException |
| 1322 | { |
| 1323 | System.out.println("EnumExample"); |
| 1324 | Log.append("EnumExample"); |
| 1325 | |
| 1326 | Symbol name = ctx.mkSymbol("fruit"); |
| 1327 | |
| 1328 | EnumSort<T> fruit = ctx.mkEnumSort(name, ctx.mkSymbol("apple"), |
| 1329 | ctx.mkSymbol("banana"), ctx.mkSymbol("orange")); |
| 1330 | |
| 1331 | // helper function for consistent typing: https://docs.oracle.com/javase/tutorial/java/generics/capture.html |
| 1332 | System.out.println((fruit.getConsts()[0])); |
| 1333 | System.out.println((fruit.getConsts()[1])); |
| 1334 | System.out.println((fruit.getConsts()[2])); |
| 1335 | |
| 1336 | System.out.println((fruit.getTesterDecls()[0])); |
| 1337 | System.out.println((fruit.getTesterDecls()[1])); |
| 1338 | System.out.println((fruit.getTesterDecls()[2])); |
| 1339 | |
| 1340 | Expr<EnumSort<T>> apple = fruit.getConsts()[0]; |
| 1341 | Expr<EnumSort<T>> banana = fruit.getConsts()[1]; |
| 1342 | Expr<EnumSort<T>> orange = fruit.getConsts()[2]; |
| 1343 | |
| 1344 | /* Apples are different from oranges */ |
| 1345 | prove(ctx, ctx.mkNot(ctx.mkEq(apple, orange)), false); |
| 1346 | |
| 1347 | /* Apples pass the apple test */ |
| 1348 | prove(ctx, ctx.mkApp(fruit.getTesterDecls()[0], apple), |
| 1349 | false); |
| 1350 | |
| 1351 | /* Oranges fail the apple test */ |
| 1352 | disprove(ctx, ctx.mkApp(fruit.getTesterDecls()[0], orange), false); |
| 1353 | prove(ctx, ctx.mkNot(ctx.mkApp(fruit.getTesterDecls()[0], orange)), false); |
| 1354 | |
| 1355 | Expr<EnumSort<T>> fruity = ctx.mkConst("fruity", fruit); |
| 1356 | |
| 1357 | /* If something is fruity, then it is an apple, banana, or orange */ |
| 1358 | |
| 1359 | prove(ctx, ctx.mkOr(ctx.mkEq(fruity, apple), ctx.mkEq(fruity, banana), ctx.mkEq(fruity, orange)), false); |
| 1360 | } |
| 1361 | |
| 1362 | // while you can do this untyped, it's safer to have a helper function -- this will prevent you from |
| 1363 | // mixing up your enum types |
no test coverage detected