Skip to content

Commit bc78b18

Browse files
committed
Test with and without options
1 parent eeb3a84 commit bc78b18

39 files changed

+61794
-33
lines changed

test/builtin/drawing/test_plot_detail.py

Lines changed: 84 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,67 +58,118 @@
5858
import mathics.builtin.drawing.plot as plot
5959
from mathics.core.util import print_expression_tree
6060

61-
both = [
62-
("test-plot3d", "Plot3D[x y, {x,0,1}, {y,0,1}]"),
63-
]
64-
61+
# non-vectorized available, vectorized not available,
6562
classic = [
66-
("test-plot", "Plot[x, {x,0,1}]"),
63+
("barchart", "BarChart[{3,5,2,7}]"),
64+
("discreteplot", "DiscretePlot[n^2,{n,1,10}]"),
65+
("histogram", "Histogram[{1,1,1,5,5,7,8,8,8}]"),
66+
("listlineplot", "ListLinePlot[{1,4,2,5,3}]"),
67+
("listplot", "ListPlot[{1,4,2,5,3}]"),
68+
("liststepplot", "ListStepPlot[{1,4,2,5,3}]"),
69+
#("manipulate", "Manipulate[Plot[a x,{x,0,1}],{a,0,5}]"),
70+
("numberlineplot", "NumberLinePlot[{1,3,4}]"),
71+
("parametricplot", "ParametricPlot[{Cos[t],Sin[t]},{t,0,2 Pi}]"),
72+
("piechart", "PieChart[{3,2,5}]"),
73+
("plot", "Plot[Sin[x], {x, 0, 2 Pi}]"),
74+
("polarplot", "PolarPlot[1+0.5 Cos[3 θ],{θ,0,2 Pi}]"),
6775
]
6876

77+
# vectorized available, non-vectorized not available
6978
vectorized = [
70-
("test-density", "DensityPlot[x y, {x,0,1}, {y,0,1}]"),
79+
("complexplot", "ComplexPlot[Exp[I z],{z,-2-2 I,2+2 I}]"),
80+
("complexplot3d", "ComplexPlot3D[Exp[I z],{z,-2-2 I,2+2 I}]"),
81+
("contourplot-1", "ContourPlot[x^2-y^2,{x,-2,2},{y,-2,2}]"),
82+
("contourplot-2", "ContourPlot[x^2+y^2==1,{x,-2,2},{y,-2,2}]"),
7183
]
7284

85+
# both vectorized and non-vectorized available
86+
both = [
87+
("densityplot", "DensityPlot[Sin[x y],{x,-2,2},{y,-2,2}]"),
88+
("plot3d", "Plot3D[Sin[x y],{x,-2,2},{y,-2,2}]"),
89+
]
7390

74-
def ref_dir():
75-
dir, _ = os.path.splitext(__file__)
76-
return dir + "_ref"
91+
# common plotting options to test with and without
92+
opts = """
93+
AspectRatio -> 2,
94+
Axes -> False,
95+
BoxRatios -> {1, 2, 3},
96+
Frame -> False,
97+
Mesh -> Full,
98+
PlotPoints -> 10
99+
"""
77100

101+
# compute reference dir, which is this file minus .py plus _ref
102+
path, _ = os.path.splitext(__file__)
103+
ref_dir = path + "_ref"
104+
print(f"ref_dir {ref_dir}")
78105

79-
def one_test(name, str_expr, act_dir="/tmp"):
80-
print(f"=== running {name} {str_expr}")
81106

82-
# evaluate the expression to be tested
83-
expr = session.parse(str_expr)
84-
act_expr = expr.evaluate(session.evaluation)
107+
def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
85108

86-
# write the results to act_fn in act_dir
87-
act_fn = os.path.join(act_dir, f"{name}.txt")
88-
with open(act_fn, "w") as act_f:
89-
print_expression_tree(act_expr, file=act_f)
109+
# update name and set use_vectorized_plot depending on
110+
# whether vectorized test
111+
if vec:
112+
name += "-vec"
113+
plot.use_vectorized_plot = vec
114+
else:
115+
name += "-cls"
90116

91-
# use diff to compare the actual result in act_fn to reference result in ref_fn
92-
ref_fn = os.path.join(ref_dir(), f"{name}.txt")
93-
result = subprocess.run(["diff", "-u", ref_fn, act_fn], capture_output=False)
94-
assert result.returncode == 0, "reference and actual output differ"
95-
os.remove(act_fn)
117+
# update name and splice in options depending on
118+
# whether default or with-options test
119+
if opt:
120+
name += "-opt"
121+
str_expr = f"{str_expr[:-1]}, {opts}]"
122+
else:
123+
name += "-def"
124+
125+
print(f"=== running {name} {str_expr}")
96126

97-
def test_all(act_dir="/tmp"):
98-
# run vectorized tests
99127
try:
100-
plot.use_vectorized_plot = True
101-
for name, str_expr in vectorized + both:
102-
one_test(name + "-vectorized", str_expr, act_dir)
128+
# evaluate the expression to be tested
129+
expr = session.parse(str_expr)
130+
act_expr = expr.evaluate(session.evaluation)
131+
132+
# write the results to act_fn in act_dir
133+
act_fn = os.path.join(act_dir, f"{name}.txt")
134+
with open(act_fn, "w") as act_f:
135+
print_expression_tree(act_expr, file=act_f)
136+
137+
# use diff to compare the actual result in act_fn to reference result in ref_fn
138+
ref_fn = os.path.join(ref_dir, f"{name}.txt")
139+
result = subprocess.run(["diff", "-U", "5", ref_fn, act_fn], capture_output=False)
140+
assert result.returncode == 0, "reference and actual result differ"
141+
if act_fn != ref_fn:
142+
os.remove(act_fn)
143+
103144
finally:
104145
plot.use_vectorized_plot = False
105146

106-
# run classic tests
107-
for name, str_expr in classic + both:
108-
one_test(name, str_expr, act_dir)
147+
148+
def test_all(act_dir="/tmp", opt=None):
149+
150+
# run twice, once without and once with options
151+
for opt in [False, True]:
152+
153+
# run classic tests
154+
for name, str_expr in classic + both:
155+
one_test(name, str_expr, False, opt, act_dir)
156+
157+
# run vectorized tests
158+
for name, str_expr in vectorized + both:
159+
one_test(name, str_expr, True, opt, act_dir)
109160

110161

111162
if __name__ == "__main__":
112163
# reference files can be generated by pointing saved actual
113164
# output at reference dir instead of /tmp
114165
def make_ref_files():
115-
test_all(ref_dir())
166+
test_all(ref_dir)
116167

117168
def run_tests():
118169
try:
119170
test_all()
120171
except AssertionError:
121172
print("FAIL")
122173

123-
# make_ref_files()
174+
#make_ref_files()
124175
run_tests()
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
System`Graphics
2+
System`List
3+
System`EdgeForm
4+
System`RGBColor
5+
System`Integer 0
6+
System`Integer 0
7+
System`Integer 0
8+
System`Style
9+
System`Rectangle
10+
System`List
11+
System`Real 0.15999999999999998
12+
System`Integer 0
13+
System`List
14+
System`Real 1.06
15+
System`Real 3.0
16+
System`RGBColor
17+
System`Real 0.4470588235294118
18+
System`Real 0.792156862745098
19+
System`Real 0.8666666666666667
20+
System`Style
21+
System`Rectangle
22+
System`List
23+
System`Real 1.12
24+
System`Integer 0
25+
System`List
26+
System`Real 2.02
27+
System`Real 5.0
28+
System`RGBColor
29+
System`Real 0.4470588235294118
30+
System`Real 0.792156862745098
31+
System`Real 0.8666666666666667
32+
System`Style
33+
System`Rectangle
34+
System`List
35+
System`Real 2.08
36+
System`Integer 0
37+
System`List
38+
System`Real 2.98
39+
System`Real 2.0
40+
System`RGBColor
41+
System`Real 0.4470588235294118
42+
System`Real 0.792156862745098
43+
System`Real 0.8666666666666667
44+
System`Style
45+
System`Rectangle
46+
System`List
47+
System`Real 3.04
48+
System`Integer 0
49+
System`List
50+
System`Real 3.94
51+
System`Real 7.0
52+
System`RGBColor
53+
System`Real 0.4470588235294118
54+
System`Real 0.792156862745098
55+
System`Real 0.8666666666666667
56+
System`Line
57+
System`List
58+
System`List
59+
System`Integer 0
60+
System`Integer 0
61+
System`List
62+
System`Real 3.94
63+
System`Integer 0
64+
System`FaceForm
65+
System`RGBColor
66+
System`Integer 0
67+
System`Integer 0
68+
System`Integer 0
69+
System`Line
70+
System`List
71+
System`List
72+
System`Real 0.15999999999999998
73+
System`Integer 0
74+
System`List
75+
System`Real 0.15999999999999998
76+
System`Real -0.2
77+
System`Line
78+
System`List
79+
System`List
80+
System`Real 3.94
81+
System`Integer 0
82+
System`List
83+
System`Real 3.94
84+
System`Real -0.2
85+
System`Rule
86+
System`AlignmentPoint
87+
System`Center
88+
System`Rule
89+
System`AspectRatio
90+
System`Power
91+
System`GoldenRatio
92+
System`Integer -1
93+
System`Rule
94+
System`Axes
95+
System`List
96+
System`False
97+
System`True
98+
System`Rule
99+
System`AxesLabel
100+
System`None
101+
System`Rule
102+
System`AxesOrigin
103+
System`Automatic
104+
System`Rule
105+
System`AxesStyle
106+
System`List
107+
System`Rule
108+
System`Background
109+
System`Automatic
110+
System`Rule
111+
System`BaseStyle
112+
System`List
113+
System`Rule
114+
System`BaselinePosition
115+
System`Automatic
116+
System`Rule
117+
System`ChartLabels
118+
System`None
119+
System`Rule
120+
System`ChartLegends
121+
System`None
122+
System`Rule
123+
System`ChartStyle
124+
System`Automatic
125+
System`Rule
126+
System`ContentSelectable
127+
System`Automatic
128+
System`Rule
129+
System`CoordinatesToolOptions
130+
System`Automatic
131+
System`Rule
132+
System`Epilog
133+
System`List
134+
System`Rule
135+
System`FormatType
136+
System`TraditionalForm
137+
System`Rule
138+
System`Frame
139+
System`False
140+
System`Rule
141+
System`FrameLabel
142+
System`None
143+
System`Rule
144+
System`FrameStyle
145+
System`List
146+
System`Rule
147+
System`FrameTicks
148+
System`Automatic
149+
System`Rule
150+
System`FrameTicksStyle
151+
System`List
152+
System`Rule
153+
System`GridLines
154+
System`None
155+
System`Rule
156+
System`GridLinesStyle
157+
System`List
158+
System`Rule
159+
System`ImageMargins
160+
System`Real 0.0
161+
System`Rule
162+
System`ImagePadding
163+
System`All
164+
System`Rule
165+
System`ImageSize
166+
System`Automatic
167+
System`Rule
168+
System`LabelStyle
169+
System`List
170+
System`Rule
171+
System`Mesh
172+
System`None
173+
System`Rule
174+
System`Method
175+
System`Automatic
176+
System`Rule
177+
System`PlotLabel
178+
System`None
179+
System`Rule
180+
System`PlotRange
181+
System`List
182+
System`List
183+
System`Real -0.1
184+
System`Real 3.94
185+
System`List
186+
System`Integer 0
187+
System`Real 7.0
188+
System`Rule
189+
System`PlotRangeClipping
190+
System`False
191+
System`Rule
192+
System`PlotRangePadding
193+
System`Automatic
194+
System`Rule
195+
System`PlotRegion
196+
System`Automatic
197+
System`Rule
198+
System`PreserveImageOptions
199+
System`Automatic
200+
System`Rule
201+
System`Prolog
202+
System`List
203+
System`Rule
204+
System`RotateLabel
205+
System`True
206+
System`Rule
207+
System`Ticks
208+
System`Automatic
209+
System`Rule
210+
System`TicksStyle
211+
System`List

0 commit comments

Comments
 (0)