I'm a strong proponent of unit tests and as such I'm using the MUnit framework from Wolfram Workbench on a regular basis. Many of the codes I'm working on also
use TraditionalForm
formatting in order to make objects look nicer in the Mathematica notebooks. Some of the formatting,, rules are pretty complicated which means that it would be nice to have unit tests for them as well.
However, I don't see a simple way to implement unit tests to check the TraditionalForm output of particular expression. For example, let us look at
MyObject/:MakeBoxes[MyObject[x_,y_],TraditionalForm]:=
If[x===y,SuperscriptBox["\[Alpha]",1],SuperscriptBox["\[Alpha]",2]]
Now I would like to write two tests like (pseudocode):
Representation[MyObject[1,1]] === SuperscriptBox[\[Alpha],1]
Representation[MyObject[1,2]] === SuperscriptBox[\[Alpha],2]
The best thing I was able to come up with is
TraditionalForm[MyObject[1,1]] === TraditionalForm[SuperscriptBox[\[Alpha],1]//DisplayForm]
TraditionalForm[MyObject[1,2]] === TraditionalForm[SuperscriptBox[\[Alpha],2]//DisplayForm]
Which however still doesn't return True
. When I run Mathematica kernel without the frontend I see that
both
TraditionalForm[MyObject[1,1]]
and
TraditionalForm[SuperscriptBox[\[Alpha],1]//DisplayForm]
evaluate to
//TraditionalForm= α^1
but for some reason Mathematica doesn't consider them to be equal.
Is there some handy function to output the TraditionalForm
of MyObject[1,1]
and MyObject[1,2]
in
terms of SuperscriptBox
and \[Alpha]
?
Or may be there is some standard way to write unit tests for the TraditionalForm
representation that I'm completely missing?