diff options
Diffstat (limited to 'Build/source/utils/asymptote/tests/arith')
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/integer.asy | 15 | ||||
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/pair.asy | 20 | ||||
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/real.asy | 18 | ||||
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/roots.asy | 96 | ||||
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/transform.asy | 25 | ||||
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/triple.asy | 11 |
6 files changed, 185 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/tests/arith/integer.asy b/Build/source/utils/asymptote/tests/arith/integer.asy new file mode 100644 index 00000000000..a402ca58955 --- /dev/null +++ b/Build/source/utils/asymptote/tests/arith/integer.asy @@ -0,0 +1,15 @@ +// Integer arithmetic. +import TestLib; +StartTest("integer addition"); +assert(1+1==2); +EndTest(); +StartTest("integer subtraction"); +assert(2-1==1); +EndTest(); +StartTest("integer multiplication"); +assert(2*2==4); +EndTest(); +StartTest("integer division"); +assert(4/2==2); +EndTest(); + diff --git a/Build/source/utils/asymptote/tests/arith/pair.asy b/Build/source/utils/asymptote/tests/arith/pair.asy new file mode 100644 index 00000000000..c815f28b2fa --- /dev/null +++ b/Build/source/utils/asymptote/tests/arith/pair.asy @@ -0,0 +1,20 @@ +import TestLib; + +StartTest("complex addition"); +assert((1,0)+(0,1)==(1,1)); +EndTest(); +StartTest("complex subtraction"); +assert((1,0)-(0,1)==(1,-1)); +EndTest(); +StartTest("complex multiplication"); +assert((1,2)*(2,1)==(0,5)); +EndTest(); +StartTest("complex division"); +assert((0,5)/(2,1)==(1,2)); +EndTest(); +StartTest("length(pair)"); +assert(length((0.0,1.0)) == 1.0); +EndTest(); +StartTest("conj()"); +assert(conj((0.0,1.0))==(0.0, -1.0)); +EndTest(); diff --git a/Build/source/utils/asymptote/tests/arith/real.asy b/Build/source/utils/asymptote/tests/arith/real.asy new file mode 100644 index 00000000000..1628258cf83 --- /dev/null +++ b/Build/source/utils/asymptote/tests/arith/real.asy @@ -0,0 +1,18 @@ +// Real arithmetic. + +import TestLib; +StartTest("real error"); +assert((1.0-1.0) < realEpsilon); +EndTest(); +StartTest("real addition"); +assert((1.0+1.0) == (2.0)); +EndTest(); +StartTest("real subtraction"); +assert((2.0-1.0) == (1.0)); +EndTest(); +StartTest("real multiplication"); +assert((2.0*2.0) == (4.0)); +EndTest(); +StartTest("real division"); +assert((4.0/2.0) == (2.0)); +EndTest(); diff --git a/Build/source/utils/asymptote/tests/arith/roots.asy b/Build/source/utils/asymptote/tests/arith/roots.asy new file mode 100644 index 00000000000..d3e5d55f367 --- /dev/null +++ b/Build/source/utils/asymptote/tests/arith/roots.asy @@ -0,0 +1,96 @@ +// Roots. + +import TestLib; +real x; +real[] r; + +StartTest("quadratic roots"); + +r=quadraticroots(1,0,-8); +assert(r.length == 2); +r=sort(r); +x=2sqrt(2); +assert(close(r[0],-x)); +assert(close(r[1],x)); + +r=quadraticroots(1,2,1); +assert(r.length == 2); +assert(close(r[0],-1)); +assert(close(r[1],-1)); + +r=quadraticroots(1,0,8); +assert(r.length == 0); + +r=quadraticroots(0,2,3); +assert(r.length == 1); +assert(close(r[0],-3/2)); + +EndTest(); + +StartTest("cubic roots"); + +r=cubicroots(1,0,0,-8); +assert(r.length == 1); +assert(close(r[0],2)); + +real[] r=cubicroots(1,3,3,1); +assert(r.length == 3); +assert(close(r[0],-1)); +assert(close(r[1],-1)); +assert(close(r[2],-1)); + +real[] r=cubicroots(1,-3,3,-1); +assert(r.length == 3); +assert(close(r[0],1)); +assert(close(r[1],1)); +assert(close(r[2],1)); + +r=cubicroots(1,0,0,0); +assert(r.length == 3); +assert(r[0] == 0); +assert(r[1] == 0); +assert(r[2] == 0); + +r=cubicroots(1,0,-15,-4); +assert(r.length == 3); +r=sort(r); +assert(close(r[0],-2-sqrt(3))); +assert(close(r[1],-2+sqrt(3))); +assert(close(r[2],4)); + +r=cubicroots(1,0,-15,4); +assert(r.length == 3); +r=sort(r); +assert(close(r[0],-4)); +assert(close(r[1],2-sqrt(3))); +assert(close(r[2],2+sqrt(3))); + +r=cubicroots(1,0,-15,0); +assert(r.length == 3); +r=sort(r); +x=sqrt(15); +assert(close(r[0],-x)); +assert(r[1] == 0); +assert(close(r[2],x)); + +r=cubicroots(1,1,1,0); +assert(r.length == 1); +assert(r[0] == 0); + +r=cubicroots(1,0,20,-4); +assert(r.length == 1); +x=cbrt(54+6sqrt(6081)); +assert(close(r[0],x/3-20/x)); + +EndTest(); + +StartTest("newton"); + +real f(real x) {return cos(x);} +real dfdx(real x) {return -sin(x);} + +assert(close(newton(f,dfdx,1),pi/2)); +assert(newton(f,dfdx,0) == realMax); +assert(newton(f,dfdx,0,2) == pi/2); + +EndTest(); diff --git a/Build/source/utils/asymptote/tests/arith/transform.asy b/Build/source/utils/asymptote/tests/arith/transform.asy new file mode 100644 index 00000000000..e4e44e387b8 --- /dev/null +++ b/Build/source/utils/asymptote/tests/arith/transform.asy @@ -0,0 +1,25 @@ +import TestLib; +pair x = (1, 2); +StartTest("identity transform"); +assert(identity()*x == x); +EndTest(); +StartTest("shift transform"); +assert(shift((1,1))*x == (2, 3)); +assert(shift(1,1)*x == (2, 3)); +EndTest(); +StartTest("scaling transforms"); +assert(xscale(2)*x == (2, 2)); +assert(yscale(2)*x == (1, 4)); +assert(scale(2)*x == (2, 4)); +EndTest(); +StartTest("slant transform"); +assert(slant(1)*x == (3, 2)); +EndTest(); +StartTest("rotation transform"); +assert(length((rotate(90)*x) - (-2,1)) <= realEpsilon); +assert(rotate(90, x)*x == x); +EndTest(); +StartTest("reflect transform"); +assert(reflect((-1, -1), (1, 1))*x == (2, 1)); +EndTest(); + diff --git a/Build/source/utils/asymptote/tests/arith/triple.asy b/Build/source/utils/asymptote/tests/arith/triple.asy new file mode 100644 index 00000000000..135801b6330 --- /dev/null +++ b/Build/source/utils/asymptote/tests/arith/triple.asy @@ -0,0 +1,11 @@ +import TestLib; +triple t = (1,0,0); +StartTest("polar()"); +assert(polar(t) == (pi / 2.0) ); +EndTest(); +StartTest("azimuth()"); +assert(azimuth(t) < realEpsilon); +EndTest(); +StartTest("unit()"); +assert(length(t-unit(t)) < realEpsilon); +EndTest(); |