Skip to content

Commit

Permalink
Break test program into multiple separate programs.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentSeidel committed May 16, 2024
1 parent 12c3832 commit 826a19b
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ lib/*

# Ada Library Information
*.ali

# Test binaries
test_ode
test_integ
test_stats
Binary file removed test/test
Binary file not shown.
43 changes: 43 additions & 0 deletions test/test_integ.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with BBS.Numerical;
with BBS.Numerical.integration_real;

procedure test_integ is
subtype real is Float;
package integ is new BBS.Numerical.integration_real(real);
package float_io is new Ada.Text_IO.Float_IO(real);
package elem is new Ada.Numerics.Generic_Elementary_Functions(real);

function f1(x : real) return real is
begin
return (100.0/(x*x))*elem.sin(10.0/x);
end;

function f2(t, y : real) return real is
begin
return -y + t + 1.0;
end;

y : real;
tol : real;
begin
Ada.Text_IO.Put_Line("Testing some of the numerical routines.");
--
Ada.Text_IO.Put_Line("Testing integration:");
y := integ.trapezoid(f1'Access, 1.0, 3.0, 10);
Ada.Text_IO.Put(" Trapazoid rule gives ");
float_io.Put(y, 2, 3, 0);
Ada.Text_IO.New_Line;
y := integ.simpson(f1'Access, 1.0, 3.0, 10);
Ada.Text_IO.Put(" Simpson rule gives ");
float_io.Put(y, 2, 6, 0);
Ada.Text_IO.New_Line;
tol := 1.0e-6;
y := integ.adapt_simpson(f1'Access, 1.0, 3.0, tol, 8);
Ada.Text_IO.Put(" Adaptive Simpson gives ");
float_io.Put(y, 2, 6, 0);
Ada.Text_IO.Put(" with estimated tolerance ");
float_io.Put(tol, 2, 6, 0);
Ada.Text_IO.New_Line;
end test_integ;
15 changes: 15 additions & 0 deletions test/test_integ.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
with "../BBS_Numerical.gpr";

project test_integ is
for languages use ("Ada");
for Source_Dirs use (".");
for Object_Dir use "../obj";
for Main use ("test_integ.adb");
for Exec_Dir use ".";
package builder is
for switches ("Ada") use ("-s");
end builder;
package compiler is
for switches ("Ada") use ("-g", "-gnateE", "-gnata");
end compiler;
end test_integ;
47 changes: 2 additions & 45 deletions test/test.adb → test/test_ode.adb
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with BBS.Numerical;
with BBS.Numerical.complex_real;
with BBS.Numerical.integration_real;
with BBS.Numerical.ode_real;
with BBS.Numerical.regression;
with BBS.Numerical.roots_real;
with BBS.Numerical.Statistics;

procedure test is
procedure test_ode is
subtype real is Float;
package linreg is new BBS.Numerical.regression(real);
package integ is new BBS.Numerical.integration_real(real);
package ode is new BBS.Numerical.ode_real(real);
package float_io is new Ada.Text_IO.Float_IO(real);
package elem is new Ada.Numerics.Generic_Elementary_Functions(real);
Expand Down Expand Up @@ -39,14 +32,6 @@ procedure test is
return -2.4*y(1) + 1.6*y(2) + 3.6;
end;

data : linreg.data_array :=
((x => 1.0, y => 1.0),
(x => 2.0, y => 1.0),
(x => 3.0, y => 2.0),
(x => 4.0, y => 2.0),
(x => 5.0, y => 4.0));
res : linreg.simple_linreg_result;
y : real;
yr : real;
yrkf : real;
ye : real;
Expand All @@ -63,34 +48,6 @@ procedure test is
func : constant ode.functs(1 .. 2) := (f1sys'Access, f2sys'Access);
begin
Ada.Text_IO.Put_Line("Testing some of the numerical routines.");
res := linreg.simple_linear(data);
Ada.Text_IO.Put_Line("Linear regression result:");
Ada.Text_IO.Put(" a = ");
float_io.Put(res.a, 2, 3, 0);
Ada.Text_IO.Put(", b = ");
float_io.Put(res.b, 2, 3, 0);
Ada.Text_IO.Put(", SSe = ");
float_io.Put(res.SSe, 2, 3, 0);
Ada.Text_IO.Put(", variance = ");
float_io.Put(res.variance, 2, 3, 0);
Ada.Text_IO.New_Line;
--
Ada.Text_IO.Put_Line("Testing integration:");
y := integ.trapezoid(f1'Access, 1.0, 3.0, 10);
Ada.Text_IO.Put(" Trapazoid rule gives ");
float_io.Put(y, 2, 3, 0);
Ada.Text_IO.New_Line;
y := integ.simpson(f1'Access, 1.0, 3.0, 10);
Ada.Text_IO.Put(" Simpson rule gives ");
float_io.Put(y, 2, 6, 0);
Ada.Text_IO.New_Line;
tol := 1.0e-6;
y := integ.adapt_simpson(f1'Access, 1.0, 3.0, tol, 8);
Ada.Text_IO.Put(" Adaptive Simpson gives ");
float_io.Put(y, 2, 6, 0);
Ada.Text_IO.Put(" with estimated tolerance ");
float_io.Put(tol, 2, 6, 0);
Ada.Text_IO.New_Line;
--
Ada.Text_IO.Put_Line("Testing Differential Equations");
Ada.Text_IO.Put_Line(" Time Euler's 4th Order RK RKF Adams-Bashforth-Moulton");
Expand Down Expand Up @@ -168,4 +125,4 @@ begin
float_io.Put(ysys(2), 2, 6, 0);
Ada.Text_IO.New_Line;
end loop;
end test;
end test_ode;
6 changes: 3 additions & 3 deletions test/test.gpr → test/test_ode.gpr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
with "../BBS_Numerical.gpr";

project test is
project test_ode is
for languages use ("Ada");
for Source_Dirs use (".");
for Object_Dir use "../obj";
for Main use ("test.adb");
for Main use ("test_ode.adb");
for Exec_Dir use ".";
package builder is
for switches ("Ada") use ("-s");
end builder;
package compiler is
for switches ("Ada") use ("-g", "-gnateE", "-gnata");
end compiler;
end test;
end test_ode;
33 changes: 33 additions & 0 deletions test/test_stats.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with BBS.Numerical;
with BBS.Numerical.regression;
with BBS.Numerical.Statistics;

procedure test_stats is
subtype real is Float;
package linreg is new BBS.Numerical.regression(real);
package float_io is new Ada.Text_IO.Float_IO(real);
package elem is new Ada.Numerics.Generic_Elementary_Functions(real);

data : linreg.data_array :=
((x => 1.0, y => 1.0),
(x => 2.0, y => 1.0),
(x => 3.0, y => 2.0),
(x => 4.0, y => 2.0),
(x => 5.0, y => 4.0));
res : linreg.simple_linreg_result;
begin
Ada.Text_IO.Put_Line("Testing some of the numerical routines.");
res := linreg.simple_linear(data);
Ada.Text_IO.Put_Line("Linear regression result:");
Ada.Text_IO.Put(" a = ");
float_io.Put(res.a, 2, 3, 0);
Ada.Text_IO.Put(", b = ");
float_io.Put(res.b, 2, 3, 0);
Ada.Text_IO.Put(", SSe = ");
float_io.Put(res.SSe, 2, 3, 0);
Ada.Text_IO.Put(", variance = ");
float_io.Put(res.variance, 2, 3, 0);
Ada.Text_IO.New_Line;
end test_stats;
15 changes: 15 additions & 0 deletions test/test_stats.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
with "../BBS_Numerical.gpr";

project test_stats is
for languages use ("Ada");
for Source_Dirs use (".");
for Object_Dir use "../obj";
for Main use ("test_stats.adb");
for Exec_Dir use ".";
package builder is
for switches ("Ada") use ("-s");
end builder;
package compiler is
for switches ("Ada") use ("-g", "-gnateE", "-gnata");
end compiler;
end test_stats;

0 comments on commit 826a19b

Please sign in to comment.