aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/expo.adb95
-rw-r--r--tests.gpr2
2 files changed, 97 insertions, 0 deletions
diff --git a/test/expo.adb b/test/expo.adb
new file mode 100644
index 0000000..3b5489a
--- /dev/null
+++ b/test/expo.adb
@@ -0,0 +1,95 @@
+
+
+-- 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 Expo 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 Exp_Test
+ (Base, Exponent : in Natural)
+ is
+ Relation : Goal := Empty_Goal;
+ Power : constant Term := Relation.Fresh;
+ Result : State;
+ begin
+ Math.Exponential (Relation, B (Base) & B (Exponent) & Power);
+ Result := Relation.Run;
+ TIO.Put_Line (P (Base) & "^" & P (Exponent) & " = " & PV (Power.Resolve (Result)));
+ end Exp_Test;
+
+ procedure Repeated_Mult_Test
+ (Base, Exponent : in Natural)
+ is
+ Relation : Goal := Empty_Goal;
+ Power : constant Term := Relation.Fresh;
+ Result : State;
+ begin
+ Math.Repeated_Multiply (Relation, B (Base) & B (Exponent) & Power);
+ Result := Relation.Run;
+ TIO.Put_Line (P (Base) & "^" & P (Exponent) & " = " & PV (Power.Resolve (Result)));
+ end Repeated_Mult_Test;
+
+begin
+
+ TIO.Put_Line ("Exponential");
+ -- Exp_Test (3, 5); -- uncomment this when logarithms properly worked out
+
+ TIO.New_Line;
+
+ TIO.Put_Line ("Repeated Multiply");
+ Repeated_Mult_Test (0, 2);
+ Repeated_Mult_Test (1, 10);
+ Repeated_Mult_Test (3, 4);
+ Repeated_Mult_Test (4, 3);
+ Repeated_Mult_Test (5, 5);
+
+ TIO.New_Line;
+
+ TIO.Put_Line ("Expected Failure");
+ Repeated_Mult_Test (0, 0);
+
+end Expo;
+
+
diff --git a/tests.gpr b/tests.gpr
index 5078508..5b229bc 100644
--- a/tests.gpr
+++ b/tests.gpr
@@ -19,6 +19,7 @@ project Tests is
("ab.adb",
"addsubo.adb",
"divo.adb",
+ "expo.adb",
"fivesix.adb",
"membero.adb",
"multo.adb",
@@ -30,6 +31,7 @@ project Tests is
for Executable ("ab.adb") use "ab";
for Executable ("addsubo.adb") use "addsubo";
for Executable ("divo.adb") use "divo";
+ for Executable ("expo.adb") use "expo";
for Executable ("fivesix.adb") use "fivesix";
for Executable ("membero.adb") use "membero";
for Executable ("multo.adb") use "multo";