diff options
author | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
commit | bab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch) | |
tree | 10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/tests/arith/roots.asy | |
parent | 8643d90372e9c31e0f461c15c596b60a545bd7d3 (diff) |
asymptote 1.72 sources (not integrated into build yet)
git-svn-id: svn://tug.org/texlive/trunk@13110 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/tests/arith/roots.asy')
-rw-r--r-- | Build/source/utils/asymptote/tests/arith/roots.asy | 96 |
1 files changed, 96 insertions, 0 deletions
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(); |