Re: Regression Testing of Graphics: some questions

*To*: mathgroup at smc.vnet.net*Subject*: [mg128112] Re: Regression Testing of Graphics: some questions*From*: "Nasser M. Abbasi" <nma at 12000.org>*Date*: Mon, 17 Sep 2012 00:19:28 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net*References*: <k33upt$quq$1@smc.vnet.net>*Reply-to*: nma at 12000.org

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