Skip to content

Commit

Permalink
new \pgfmathparse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xworld21 committed Jan 11, 2025
1 parent cd372e5 commit 55f2867
Show file tree
Hide file tree
Showing 4 changed files with 564 additions and 0 deletions.
10 changes: 10 additions & 0 deletions t/661_pgfmathparse.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- CPERL -*-
#**********************************************************************
# Test cases for LaTeXML
#**********************************************************************
use LaTeXML::Util::Test;

latexml_tests("t/pgfmathparse",
requires=>{
pgfmathparse=>{
packages=>'pgf.sty'} });
Binary file added t/pgfmathparse/pgffunctions.pdf
Binary file not shown.
152 changes: 152 additions & 0 deletions t/pgfmathparse/pgffunctions.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
\documentclass{article}
\usepackage{pgf}
\makeatletter
\def\test{\begingroup\pgfmath@catcodes\test@}
\def\test@#1{\texttt{#1 = \pgfmathprint{#1}}\endgroup\par}
\makeatother
\begin{document}

\section{94.1.1 Commands}
\test{2pt+3.5pt}
\test{sin(.5*pi r)*60}
\test{1.234e+4}
\test{010}
\test{0xA}
\test{0XB}
\test{0b10}
\test{0B101}
% partially implemented: quotes

\section{92.2 Operators}
\test{1+2}
\test{1-2}
\test{-2}
\test{1*2}
\test{1/2}
% correct, but generates 'Script ^ can only appear in math mode' error
%\test{2^3}
\test{4!}
\test{1r}
\test{pi r}
\test{1 ? 2 : 3}
\test{2 == 2}
\test{2 == 1}
\test{(1+2)*3}
\test{sin(30*10)}
\test{mod(72,3)}
\test{sin 30}
\test{sin(30)}
\test{sin 30*10}
\test{sin(30)*10}
% unimplemented: array operator {X}
% unimplemented: array access operator [X]
% unimplemented: quote operator "X"

\section{92.3 Functions}

\subsection{92.3.1 Basic arithmetic functions}
\test{add(75,6)}
\test{subtract(75,6)}
\test{neg(50)}
\test{multiply(75,6)}
\test{divide(75,6)}
\test{div(75,9)}
\test{factorial(5)}
\test{sqrt(10)}
\test{sqrt(8765.432)}
\test{pow(2,7)}
% FAILS \test{(e^2 - e^-2)/2}
\test{exp(1)}
\test{exp(2.34)}
\test{ln(10)}
\test{ln(exp(5))}
\test{log10(100)}
\test{log2(128)}
\test{abs(-5)}
\test{-abs(4*-3)}
\test{mod(20,6)}
\test{mod(-100,30)}
\test{Mod(-100,30)}
\test{sign(-5)}
\test{sign(0)}
\test{sign(5)}

\subsection{94.3.2 Rounding functions}
\test{round(32.5/17)}
\test{round(398/12)}
\test{floor(32.5/17)}
\test{floor(398/12)}
\test{floor(-398/12)}
\test{ceil(32.5/17)}
\test{ceil(398/12)}
\test{ceil(-398/12)}
\test{int(32.5/17)}
\test{frac(32.5/17)}
\test{int(-32.5/17)} % added in LaTeXML to check behavior on negative numbers
\test{frac(-32.5/17)} % added in LaTeXML to check behavior on negative numbers
\test{real(4)}

\subsection{94.3.3 Integer arithmetic functions}
% FAILS \test{gcd(42,56)}
\test{isodd(2)}
\test{isodd(3)}
\test{iseven(2)}
\test{iseven(3)}
\test{isprime(1)}
\test{isprime(2)}
\test{isprime(31)}
\test{isprime(64)}

\subsection{94.3.4 Trigonometric functions}
\test{pi}
\test{pi r}
\test{rad(90)}
\test{deg(3*pi/2)}
\test{sin(60)}
% WRONG \test{sin(pi/3 r)}
\test{cos(60)}
% WRONG \test{cos(pi/3 r)}
\test{tan(45)}
% WRONG \test{tan(2*pi/8 r)}
\test{sec(45)}
\test{cosec(30)}
\test{cot(15)}

\subsection{94.3.5 Comparison and logical functions}
\test{equal(20,20)}
\test{greater(20,25)}
\test{less(20,25)}
\test{notequal(20,25)}
\test{notgreater(20,25)}
\test{notless(20,25)}
\test{and(5>4,6>7)}
\test{or(5>4,6>7)}
\test{not(true)}
% unimplemented: quote operators
% \test{ifthenelse(5==4,"yes","no")}
% \test{true ? "yes" : "no"}
% \test{false ? "yes" : "no"}

\subsection{94.3.6 Pseudo-random functions}
% unimplemented: determinism (yet)

\subsection{94.3.7 Base conversion functions}
\test{hex(65535)}
\test{Hex(65535)}
\test{oct(63)}
% perl thinks this is a number and yields an overflow error
% FAILS \test{bin(185)}

\subsection{94.3.8 Miscellaneous functions}
\test{min(3,4,-2,250,-8,100)}
\test{max(3,4,-2,250,-8,100)}
\test{veclen(12,5)}
% unimplemented: arrays
\test{sinh(0.5)}
\test{cosh(0.5)}
\test{tanh(0.5)}
\test{width("Some Lovely Text")}
\test{height("Some Lovely Text")}
\test{depth("Some Lovely Text")}

\end{document}
Loading

0 comments on commit 55f2867

Please sign in to comment.