diff options
Diffstat (limited to 'Master/texmf-dist/source/generic/pgf/testsuite/mathtest/pgfmathtestsuite.tex')
-rw-r--r-- | Master/texmf-dist/source/generic/pgf/testsuite/mathtest/pgfmathtestsuite.tex | 212 |
1 files changed, 151 insertions, 61 deletions
diff --git a/Master/texmf-dist/source/generic/pgf/testsuite/mathtest/pgfmathtestsuite.tex b/Master/texmf-dist/source/generic/pgf/testsuite/mathtest/pgfmathtestsuite.tex index 0497f0d095b..ecae8941fe1 100644 --- a/Master/texmf-dist/source/generic/pgf/testsuite/mathtest/pgfmathtestsuite.tex +++ b/Master/texmf-dist/source/generic/pgf/testsuite/mathtest/pgfmathtestsuite.tex @@ -1,3 +1,10 @@ +% FIXME: this class is MESSY. +% +% rewrite with proper assertions ... it goes back to a time where I +% merely wanted to inspect the results! +% +% --> see 'assertEquals' in this file +% \documentclass[a4paper]{article} \usepackage[intlimits]{amsmath} @@ -23,6 +30,8 @@ } \makeatother +\pgfmathfloatcreate{1}{5.0}{-4} +\let\THRESH=\pgfmathresult \parindent=0pt @@ -1108,67 +1117,148 @@ } { -\testsection{Testing the FPU library (and math parser)} -\pgfkeys{/pgf/fpu} -% #1 : expression -% #2 : the reference -\def\pgfmathfloattest#1#2{% - \pgfmathfloatparsenumber{#2}% - \let\reference=\pgfmathresult - \message{parsing expression #1...}% - \pgfmathparse{#1}% - \let\argumenta=\pgfmathresult - \let\resultfloat=\pgfmathresult - \pgfmathfloattosci\pgfmathresult - \let\result=\pgfmathresult - \pgfmathfloatrelerror\resultfloat\reference - \pgfmathfloattosci\pgfmathresult - \[ #1 = \result \quad[= \resultfloat] \quad (\text{error/r to }#2 = \pgfmathresult)\] -}% -%\tracingmacros=2\tracingcommands=2 + % #1 : expression + % #2 : the reference + \def\assertEquals#1#2{% + \pgfmathfloatparsenumber{#2}% + \let\reference=\pgfmathresult + \message{parsing expression #1...}% + \pgfmathparse{#1}% + \pgfmathfloatparsenumber{\pgfmathresult}% + \let\argumenta=\pgfmathresult + \let\resultfloat=\pgfmathresult + \pgfmathfloattosci\pgfmathresult + \let\result=\pgfmathresult + \pgfmathfloatrelerror\resultfloat\reference + \let\actualerror=\pgfmathresult + \pgfmathfloatgreaterthan{\pgfmathresult}{\THRESH}% + \ifpgfmathfloatcomparison + \begingroup + \pgfkeys{/pgf/fpu=false}% + \pgfmathparse{#1}% + \global\let\actualBasic=\pgfmathresult + \endgroup + \PackageError{pgf-fpu}{Got error: expected #1=#2, but was \result\space (error \actualerror; basic level returns \actualBasic)}{}% + \fi + \pgfmathfloattosci\actualerror + \[ #1 = \result \quad[= \resultfloat] \quad (\text{error/r to }#2 = \pgfmathresult)\] + }% + \def\mathparserTestCases{% + \assertEquals{1+1}{2} + \assertEquals{1234567*4}{4938268} + \assertEquals{exp(200)}{7.22597376812575e+86} + \assertEquals{rad(360)}{6.28318530717959} + \assertEquals{rad(180)}{3.14159265358979} + \assertEquals{deg(2*pi)}{360} + \assertEquals{deg(pi)}{180} + \assertEquals{ln(1)}{0} + \assertEquals{round(1.5)}{2} + \assertEquals{round(-1.5)}{-2} + \assertEquals{- (1.5)}{-1.5} + \assertEquals{(1e4 - 1e3) * 1e5}{900000000.0} + \assertEquals{4^2}{16} + \assertEquals{4^3}{64} + \assertEquals{4^-3}{0.015625} + \assertEquals{4^-6}{0.000244140625} + \assertEquals{111^4}{151807041} + \assertEquals{8^10}{1073741824} + \assertEquals{3^1.5}{5.19615242270663} + \assertEquals{16^5.5}{4194304} + \assertEquals{15^-0.25}{0.508132748154615} + \assertEquals{sec(45)}{1.4142136e+00} + \assertEquals{cot(30)}{1.7320508e+00} + \assertEquals{asin(7.0710678e-01)}{45} + \assertEquals{acos(8.6602540e-01)}{30} + \assertEquals{atan(5.7735027e-01)}{30} + \assertEquals{atan(16000)}{89.9964} + \assertEquals{atan(1e6)}{8.9999943e+01} + \assertEquals{atan(-1e6)}{-8.9999943e+01} + \assertEquals{-12^2}{-144}% + \assertEquals{0-12^2}{-144}% + \assertEquals{-(12)^2}{-144}% + \assertEquals{exp(-12^2)}{2.8946e-63}% + \assertEquals{round(98.8)}{99}% + \assertEquals{-pi}{-3.14159265358979}% + \assertEquals{2*(-pi)}{-6.28318530717959}% + \assertEquals{2*(-3)}{-6}% + \assertEquals{veclen(1,1)}{1.414213562373095}% + \assertEquals{veclen(1e5,6e5)}{6.082762530298220e+05}% + \assertEquals{cosh(5)}{74.20994852478784}% + \assertEquals{sinh(0.6)}{0.636653582148241}% + \assertEquals{tanh(0.6)}{0.537049566998035}% + + {\pgfkeys{/pgf/trig format=rad} + \assertEquals{atan2(4,5)}{0.674740942223553}% + \assertEquals{atan2(-4,5)}{-0.674740942223553}% + \assertEquals{atan2(4,-5)}{2.46685171136624}% + \assertEquals{atan2(-4,-5)}{-2.46685171136624}% + % + \assertEquals{atan2(5,4)}{0.89605538457134}% + \assertEquals{atan2(-5,4)}{-0.89605538457134}% + \assertEquals{atan2(5,-4)}{2.24553726901845}% + \assertEquals{atan2(-5,-4)}{-2.24553726901845}% + % + \assertEquals{atan2(4e-5,5)}{0}% + \assertEquals{atan2(4e-5,-5)}{3.1415126535899}% + } + % \assertEquals{ceil(1.5)}{2} + } + + + { + \testsection{Testing the FPU library (and math parser)} + \pgfkeys{/pgf/fpu} + %\tracingmacros=2\tracingcommands=2 + \mathparserTestCases + } + + { + \def\mathparserTestCases{% + \assertEquals{sin(90)}{1.0}% + \assertEquals{cos(90)}{0.0}% + \assertEquals{tan(45)}{1.0}% + \assertEquals{sec(45)}{1.41429}% + \assertEquals{cosec(30)}{2.0}% + \assertEquals{cot(15)}{3.73215}% + \assertEquals{asin(0.7071)}{44.99945}% + \assertEquals{acos(0.5)}{60}% + \assertEquals{atan(1)}{45}% + \assertEquals{atan(16001)}{90}% + \assertEquals{atan(-16001)}{-90}% + %\assertEquals{atan2(-4,3)}{-53.13011}% + }% + \testsection{Testing trig format=deg, basic layer (selected examples)} + %\tracingmacros=2\tracingcommands=2 + \mathparserTestCases + + \testsection{Testing trig format=deg, FPU (selected examples)} + \pgfkeys{/pgf/fpu} + \mathparserTestCases + } - \pgfmathfloattest{1+1}{2} - \pgfmathfloattest{1234567*4}{4938268} - \pgfmathfloattest{exp(200)}{7.22597376812575e+86} - \pgfmathfloattest{rad(360)}{6.28318530717959} - \pgfmathfloattest{rad(180)}{3.14159265358979} - \pgfmathfloattest{deg(2*pi)}{360} - \pgfmathfloattest{deg(pi)}{180} - \pgfmathfloattest{ln(1)}{0} - \pgfmathfloattest{round(1.5)}{2} - \pgfmathfloattest{round(-1.5)}{-2} - \pgfmathfloattest{- (1.5)}{-1.5} - \pgfmathfloattest{(1e4 - 1e3) * 1e5}{900000000.0} - \pgfmathfloattest{4^2}{16} - \pgfmathfloattest{4^3}{64} - \pgfmathfloattest{4^-3}{0.015625} - \pgfmathfloattest{4^-6}{0.000244140625} - \pgfmathfloattest{111^4}{151807041} - \pgfmathfloattest{8^10}{1073741824} - \pgfmathfloattest{3^1.5}{5.19615242270663} - \pgfmathfloattest{16^5.5}{4194304} - \pgfmathfloattest{15^-0.25}{0.508132748154615} - \pgfmathfloattest{sec(45)}{1.4142136e+00} - \pgfmathfloattest{cot(30)}{1.7320508e+00} - \pgfmathfloattest{asin(7.0710678e-01)}{45} - \pgfmathfloattest{acos(8.6602540e-01)}{30} - \pgfmathfloattest{atan(5.7735027e-01)}{30} - \pgfmathfloattest{atan(16000)}{89.9964} - \pgfmathfloattest{atan(1e6)}{8.9999943e+01} - \pgfmathfloattest{atan(-1e6)}{-8.9999943e+01} - \pgfmathfloattest{-12^2}{-144}% - \pgfmathfloattest{0-12^2}{-144}% - \pgfmathfloattest{-(12)^2}{-144}% - \pgfmathfloattest{exp(-12^2)}{2.8946e-63}% - \pgfmathfloattest{round(98.8)}{99}% - \pgfmathfloattest{-pi}{-3.14159265358979}% - \pgfmathfloattest{2*(-pi)}{-6.28318530717959}% - \pgfmathfloattest{2*(-3)}{-6}% - \pgfmathfloattest{veclen(1,1)}{1.414213562373095}% - \pgfmathfloattest{veclen(1e5,6e5)}{6.082762530298220e+05}% - \pgfmathfloattest{cosh(5)}{74.20994852478784}% - \pgfmathfloattest{sinh(0.6)}{0.636653582148241}% - \pgfmathfloattest{tanh(0.6)}{0.537049566998035}% -% \pgfmathfloattest{ceil(1.5)}{2} + { + \pgfkeys{/pgf/trig format=rad} + \def\mathparserTestCases{% + \assertEquals{sin(pi/2)}{1.0}% + \assertEquals{cos(pi/2)}{0.0}% + \assertEquals{tan(pi/4)}{1.0}% + \assertEquals{sec(pi/4)}{1.41429}% + \assertEquals{cosec(rad(30))}{2.0}% + \assertEquals{cot(rad(15))}{3.73215}% + \assertEquals{asin(0.7071)}{0.785388564086562}% 44.99945}% + \assertEquals{acos(0.5)}{1.0471975511966}% + \assertEquals{atan(1)}{0.785398163397448}%45}% + \assertEquals{atan(16001)}{1.570796326794}% + \assertEquals{atan(-16001)}{-1.570796326794}% + %\assertEquals{atan2(-4,3)}{-53.13011}% + }% + \testsection{Testing trig format=rad, basic layer (selected examples)} + %\tracingmacros=2\tracingcommands=2 + \mathparserTestCases + + \testsection{Testing trig format=rad, FPU (selected examples)} + \pgfkeys{/pgf/fpu} + \mathparserTestCases + } } \end{document} |