diff options
| author | Jedidiah Barber <contact@jedbarber.id.au> | 2026-01-02 11:09:14 +1300 |
|---|---|---|
| committer | Jedidiah Barber <contact@jedbarber.id.au> | 2026-01-02 11:09:14 +1300 |
| commit | 0b7c1346c0798d00c22cc6eaf5f8b24e5822fb5f (patch) | |
| tree | 438180ddfb9283e77c7c15dae549d3a31691363e | |
| parent | 8210373fe4e6560475e55c599dd22df28f48785d (diff) | |
Division test program
| -rw-r--r-- | test/divo.adb | 82 | ||||
| -rw-r--r-- | tests.gpr | 2 |
2 files changed, 84 insertions, 0 deletions
diff --git a/test/divo.adb b/test/divo.adb new file mode 100644 index 0000000..0d6dae8 --- /dev/null +++ b/test/divo.adb @@ -0,0 +1,82 @@ + + +-- Programmed by Jedidiah Barber +-- Licensed under the Sunset License v1.0 + +-- See license.txt for further details + + +with + + Ada.Text_IO, + Kompsos.Math, + Kompsos.Pretty_Print; + + +procedure Divo is + + package TIO renames Ada.Text_IO; + + + package InKomp is new Kompsos (Integer); + use InKomp; + + package Math is new InKomp.Math (0, 1); + + package Printer is new InKomp.Pretty_Print (Integer'Image); + + + function B + (Item : in Integer) + return Term + renames Math.Build; + + function P + (Item : in Integer) + return String + renames Printer.Image; + + function PV + (Item : in Term) + return String is + begin + return P (Math.Value (Item)); + exception + when others => + return Printer.Image (Item); + end PV; + + + procedure Test + (Dividend, Divisor : in Integer) + is + Relation : Goal := Empty_Goal; + Quotient : constant Term := Relation.Fresh; + Remainder : constant Term := Relation.Fresh; + Result : State; + begin + Math.Divide (Relation, B (Dividend) & B (Divisor) & Quotient & Remainder); + Result := Relation.Run; + TIO.Put_Line (P (Dividend) & " / " & P (Divisor) & + " = " & PV (Quotient.Resolve (Result)) & + " r " & PV (Remainder.Resolve (Result))); + end Test; + +begin + + Test (0, 2); + Test (1, 1); + Test (2, 3); + Test (2, 1); + Test (1, 5); + Test (3, 2); + Test (6, 7); + Test (6, 3); + Test (4, 6); + Test (3, 1); + Test (5, 6); + Test (19, 7); -- currently fails, not sure why, error in miniKanren? + +end Divo; + + @@ -17,6 +17,7 @@ project Tests is for Main use ("ab.adb", + "divo.adb", "fivesix.adb", "membero.adb", "pprint.adb", @@ -25,6 +26,7 @@ project Tests is package Builder is for Executable ("ab.adb") use "ab"; + for Executable ("divo.adb") use "divo"; for Executable ("fivesix.adb") use "fivesix"; for Executable ("membero.adb") use "membero"; for Executable ("pprint.adb") use "pprint"; |
