diff options
| author | Jedidiah Barber <contact@jedbarber.id.au> | 2026-01-02 18:44:26 +1300 |
|---|---|---|
| committer | Jedidiah Barber <contact@jedbarber.id.au> | 2026-01-02 18:44:26 +1300 |
| commit | 0ef8a6aabfafdfacf3798fe05bad984fb3e85e52 (patch) | |
| tree | 798e210acd61b89e39497e14b03f36e70039409c | |
| parent | 0b7c1346c0798d00c22cc6eaf5f8b24e5822fb5f (diff) | |
Addition/subtraction test program, bugfix in Add
| -rw-r--r-- | src/kompsos-math.adb | 2 | ||||
| -rw-r--r-- | test/addsubo.adb | 99 | ||||
| -rw-r--r-- | test/divo.adb | 7 | ||||
| -rw-r--r-- | tests.gpr | 2 |
4 files changed, 106 insertions, 4 deletions
diff --git a/src/kompsos-math.adb b/src/kompsos-math.adb index d910fef..d46fe5d 100644 --- a/src/kompsos-math.adb +++ b/src/kompsos-math.adb @@ -510,7 +510,7 @@ package body Kompsos.Math is A_Var : constant Term := Outputs (5).Fresh; C_Var : constant Term := Outputs (5).Fresh; begin - Outputs (5).Unify (T (A_Var, C_Var), Sum_Term); + Outputs (5).Unify (T (A_Var, T (C_Var, Empty_Term)), Sum_Term); Full_Adder (Outputs (5), Cin_Term & T (One_Element) & T (One_Element) & A_Var & C_Var); end; diff --git a/test/addsubo.adb b/test/addsubo.adb new file mode 100644 index 0000000..1033ea1 --- /dev/null +++ b/test/addsubo.adb @@ -0,0 +1,99 @@ + + +-- 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 Addsubo 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 Natural) + 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 Add_Test + (Addend1, Addend2 : in Natural) + is + Relation : Goal := Empty_Goal; + Sum : constant Term := Relation.Fresh; + Result : State; + begin + Math.Add (Relation, B (Addend1) & B (Addend2) & Sum); + Result := Relation.Run; + TIO.Put_Line (P (Addend1) & " + " & P (Addend2) & " = " & PV (Sum.Resolve (Result))); + end Add_Test; + + procedure Sub_Test + (Minuend, Subtrahend : in Natural) + is + Relation : Goal := Empty_Goal; + Diff : constant Term := Relation.Fresh; + Result : State; + begin + Math.Subtract (Relation, B (Minuend) & B (Subtrahend) & Diff); + Result := Relation.Run; + TIO.Put_Line (P (Minuend) & " - " & P (Subtrahend) & " = " & PV (Diff.Resolve (Result))); + end Sub_Test; + +begin + + TIO.Put_Line ("Addition"); + Add_Test (5, 0); + Add_Test (0, 5); + Add_Test (1, 4); + Add_Test (4, 1); + Add_Test (3, 2); + Add_Test (2, 3); + Add_Test (17, 13); + + TIO.New_Line; + + TIO.Put_Line ("Subtraction"); + Sub_Test (25, 17); + Sub_Test (5, 4); + Sub_Test (7, 7); + + TIO.New_Line; + + TIO.Put_Line ("Expected Failure"); + Sub_Test (0, 1); -- Should fail with nothing ending up bound to the variable term + +end Addsubo; + + diff --git a/test/divo.adb b/test/divo.adb index 0d6dae8..eabc32c 100644 --- a/test/divo.adb +++ b/test/divo.adb @@ -27,7 +27,7 @@ procedure Divo is function B - (Item : in Integer) + (Item : in Natural) return Term renames Math.Build; @@ -48,7 +48,7 @@ procedure Divo is procedure Test - (Dividend, Divisor : in Integer) + (Dividend, Divisor : in Natural) is Relation : Goal := Empty_Goal; Quotient : constant Term := Relation.Fresh; @@ -64,6 +64,7 @@ procedure Divo is begin + TIO.Put_Line ("Division"); Test (0, 2); Test (1, 1); Test (2, 3); @@ -75,7 +76,7 @@ begin Test (4, 6); Test (3, 1); Test (5, 6); - Test (19, 7); -- currently fails, not sure why, error in miniKanren? + Test (19, 7); end Divo; @@ -17,6 +17,7 @@ project Tests is for Main use ("ab.adb", + "addsubo.adb", "divo.adb", "fivesix.adb", "membero.adb", @@ -26,6 +27,7 @@ project Tests is package Builder is for Executable ("ab.adb") use "ab"; + for Executable ("addsubo.adb") use "addsubo"; for Executable ("divo.adb") use "divo"; for Executable ("fivesix.adb") use "fivesix"; for Executable ("membero.adb") use "membero"; |
