Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11768 > unrolled thread

Regression Testing of Graphics: some questions

Started byJames Stein <mathgroup@stein.org>
First post2012-09-16 07:23 +0000
Last post2012-09-17 04:27 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Regression Testing of Graphics: some questions James Stein <mathgroup@stein.org> - 2012-09-16 07:23 +0000
    Re: Regression Testing of Graphics: some questions "Nasser M. Abbasi" <nma@12000.org> - 2012-09-17 04:27 +0000

#11768 — Regression Testing of Graphics: some questions

FromJames Stein <mathgroup@stein.org>
Date2012-09-16 07:23 +0000
SubjectRegression Testing of Graphics: some questions
Message-ID<k33upt$quq$1@smc.vnet.net>
To my surprise, if you copy a Graphic  from a notebook and paste it
elsewhere in the notebook, the Graphic objects are not the same (even
though their visual appearance is identical.

I discovered this irritation attempting regression testing. Here's an
example: assume you have a function 'test' that takes two arguments:
     test [ expression_, expectedResult _]
An overly simple implementation might be this:
    SetAttributes [ test, HoldAll ] ;
    test [ expr_, ansr_ ] := expr === ansr;
Now suppose you wish to verify that some routine, say  'graf', is still
giving the same result it it did previously. Here is an example:

    graf := ListPlot [ { 1, 2, 2, 3 }, ImageSize->Tiny ];
    test [ graf , previousResult ] // Print;

What should 'previousResult' be? You might consider copying the graphic
produced by 'graf' earlier, which was correct, and paste it into 'test' as
the second argument. Unfortunately, the action of copy & paste changes the
internal structure of Graphic [ a1, a2, ... ] so the regression test will
always fail.

Questions:
(1) Is there a good reason for this? (The unwashed are curious.)
(2) Is this a bug (or 'feature') that could be fixed?
(3) Is there a way to prevent it?
(4) Is there an algorithm to do one of
  (a) convert an original Graphic to its pasted form.
  (b) convert a pasted Graphic to its original form.
  (c) convert any Graphic to a canonical form, such that any two Graphic
objects that produce identical displays will have identical canonical forms.

For the truly curious, here are the differences in for a rather simple
ListPlot I made. Let OG be the original, and CG be the pasted copy of OG.

OG had Length 2; CG had Length 8.

OG [[ 1 ]] was { { { }, {Hue[0.67, 0.6, 0.6], Point[{{1., 1.}, {2., 2.},
{3., 2.}, {4., 3.}}]}, { } } }
CG [[ 1 ]] was {   { }, {Hue[0.67, 0.6, 0.6], Point[{{1., 1.}, {2., 2.},
{3., 2.}, {4., 3.}}]}, { }   }

OG [ [ 2 ] ] was List of seven rules,

OG [ [ 2 through 8 ] ] were the same seven rules.

It would be simple to convert one of these trees to the other, but it would
be rash to generalize the nature of the needed conversion without extensive
investigations. Perhaps a  Wolfram wizzard can throw light on these
questions, or someone can propose a different kind of regression testing to
skirt the issue?

[toc] | [next] | [standalone]


#11778

From"Nasser M. Abbasi" <nma@12000.org>
Date2012-09-17 04:27 +0000
Message-ID<k368rp$203$1@smc.vnet.net>
In reply to#11768
On 9/16/2012 2:23 AM, James Stein wrote:


> assume you have a function 'test' that takes two arguments:
>       test [ expression_, expectedResult _]
> An overly simple implementation might be this:
>      SetAttributes [ test, HoldAll ] ;
>      test [ expr_, ansr_ ] := expr === ansr;
> Now suppose you wish to verify that some routine, say  'graf', is still
> giving the same result it it did previously. Here is an example:
>
>      graf := ListPlot [ { 1, 2, 2, 3 }, ImageSize->Tiny ];
>      test [ graf , previousResult ] // Print;
>
> What should 'previousResult' be? You might consider copying the graphic
> produced by 'graf' earlier, which was correct, and paste it into 'test' as
> the second argument. Unfortunately, the action of copy & paste changes the
> internal structure of Graphic [ a1, a2, ... ] so the regression test will
> always fail.
>
> Questions:
> (1) Is there a good reason for this? (The unwashed are curious.)

I played a little with this. What I found is that when you copy then
paste an image using the mouse, and then look at the FullForm of the
copied image, (the FullForm is the true data for all expression in
Mathematica)then the FullForm is not exactly the same. This is why
the test you have above using === failed.

For an example, using your  graf plot

  graf = ListPlot [ { 1, 2, 2, 3 }, ImageSize->Tiny ]

The FullForm starts with this line

       Graphics[List[List[List[], List[Hue[0.67, 0.6, 0.6]

But the copy/pasted image FullForm starts with this line

       Graphics[List[List[], List[Hue[0.67, 0.6, 0.6]

Even though they look at the same on the screen (obviously), the
FullForm is not the same.   One has an extra List wrapper as you
can see.

The button line, you can't assume that a copy/pasted image
will remain the same in the sense of its FullForm remain the same
as this case shows.  There might be a way to copy/paste an image
so that the copy will have the same FullForm. may be a Mathematica
expert knows how to do that.

btw, for doing diffs' between notebooks or cells, I use this free web
site http://www.diffchecker.com/

I use it all the time to diff my notebooks to see what changes I made.
(I think the notebook itself should have something like this build into it).

Just copy paste the Mathematica code (right click the cell,
copy (can also do copyAs Text, but normal Copy will show also the RowBoxes
and all the internal detailed), then paste right into the above
web page little left window) and do the same for the other cell or
notebook and paste into the right winodw and then click 'see the difference'
button. This web site will show you the differences using colors
and line numbers also.

Here is a screen shot showing the differences between your graf
and its copy/pasted version

http://12000.org/tmp/sept_16_2012/diff.png

--Nasser

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web