Skip to content

Commit 60aa008

Browse files
simplified testing
1 parent 7e5de37 commit 60aa008

File tree

1 file changed

+0
-306
lines changed

1 file changed

+0
-306
lines changed

test/test_cleanfigure.py

Lines changed: 0 additions & 306 deletions
Original file line numberDiff line numberDiff line change
@@ -77,182 +77,6 @@ def test_pruneOutsideBox3D(self):
7777
plt.close("all")
7878

7979

80-
def test_replaceDataWithNaN():
81-
"""test against matlab2tikz implementation.
82-
83-
octave code to generate baseline results.
84-
Note that octave has indexing 1...N, whereas python has indexing 0...N-1.
85-
```octave
86-
x = linspace(1, 100, 20);
87-
y1 = linspace(1, 100, 20);
88-
89-
figure
90-
plot(x, y1)
91-
xlim([20, 80])
92-
ylim([20, 80])
93-
cleanfigure;
94-
```
95-
"""
96-
id_replace = np.array([0, 16])
97-
xData = np.linspace(1, 100, 20)
98-
yData = xData.copy()
99-
data = np.stack([xData, yData], axis=1)
100-
101-
newdata = cleanfigure._replace_data_with_NaN(data, id_replace, False)
102-
assert newdata.shape == data.shape
103-
assert np.any(np.isnan(newdata))
104-
105-
106-
def test_removeData():
107-
"""test against matlab2tikz implementation.
108-
109-
octave code to generate baseline results.
110-
Note that octave has indexing 1...N, whereas python has indexing 0...N-1.
111-
```octave
112-
x = linspace(1, 100, 20);
113-
y1 = linspace(1, 100, 20);
114-
115-
figure
116-
plot(x, y1)
117-
xlim([20, 80])
118-
ylim([20, 80])
119-
cleanfigure;
120-
```
121-
"""
122-
id_remove = np.array([1, 2, 3, 17, 18, 19])
123-
xData = np.linspace(1, 100, 20)
124-
yData = xData.copy()
125-
data = np.stack([xData, yData], axis=1)
126-
127-
newdata = cleanfigure._remove_data(data, id_remove, False)
128-
assert newdata.shape == (14, 2)
129-
130-
131-
def test_removeNaNs():
132-
"""test against matlab2tikz implementation
133-
134-
octave code to generate baseline results. Note that octave has indexing 1...N, whereas python has indexing 0...N-1.
135-
```octave
136-
x = linspace(1, 100, 20);
137-
y1 = linspace(1, 100, 20);
138-
139-
figure
140-
plot(x, y1)
141-
xlim([20, 80])
142-
ylim([20, 80])
143-
cleanfigure;
144-
```
145-
"""
146-
id_replace = np.array([0, 16])
147-
id_remove = np.array([1, 2, 3, 17, 18, 19])
148-
xData = np.linspace(1, 100, 20)
149-
yData = xData.copy()
150-
data = cleanfigure._stack_data_2D(xData, yData)
151-
152-
data = cleanfigure._replace_data_with_NaN(data, id_replace, False)
153-
data = cleanfigure._remove_data(data, id_remove, False)
154-
data = cleanfigure._remove_NaNs(data)
155-
assert not np.any(np.isnan(data))
156-
assert data.shape == (12, 2)
157-
158-
159-
def test_isInBox():
160-
"""octave code to generate baseline results
161-
162-
```octave
163-
x = 1:10;
164-
y = 1:10;
165-
data = [x', y'];
166-
xlim = [3, 7];
167-
ylim = [3, 7];
168-
mask = isInBox(data, xlim, ylim)
169-
```
170-
"""
171-
x = np.linspace(1, 100, 20)
172-
y = np.linspace(1, 100, 20)
173-
data = np.stack([x, y], axis=1)
174-
xLim = np.array([20, 80])
175-
yLim = np.array([20, 80])
176-
tol = 1.0e-10
177-
relaxedXLim = xLim + np.array([-tol, tol])
178-
relaxedYLim = yLim + np.array([-tol, tol])
179-
mask = cleanfigure._isInBox(data, relaxedXLim, relaxedYLim)
180-
assert int(np.sum(mask)) == 12
181-
182-
183-
def test_getVisualLimits():
184-
"""octave code
185-
```octave
186-
addpath ("../matlab2tikz/src")
187-
188-
x = linspace(1, 100, 20);
189-
y1 = linspace(1, 100, 20);
190-
191-
figure
192-
plot(x, y1)
193-
xlim([20, 80])
194-
ylim([20, 80])
195-
set(gcf,'Units','Inches');
196-
set(gcf,'Position',[2.5 2.5 5 5])
197-
cleanfigure;
198-
```
199-
"""
200-
x = np.linspace(1, 100, 20)
201-
y = np.linspace(1, 100, 20)
202-
203-
with plt.rc_context(rc=RC_PARAMS):
204-
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
205-
(l,) = ax.plot(x, y)
206-
ax.set_xlim([20, 80])
207-
ax.set_ylim([20, 80])
208-
xLim, yLim = cleanfigure._get_visual_limits(fig, ax)
209-
assert np.allclose(xLim, np.array([20, 80]))
210-
assert np.allclose(yLim, np.array([20, 80]))
211-
plt.close("all")
212-
213-
214-
def test_opheimSimplify():
215-
"""test path simplification
216-
217-
octave code
218-
```octave
219-
addpath ("../matlab2tikz/src")
220-
221-
x = linspace(1, 100, 20);
222-
y1 = linspace(1, 100, 20);
223-
224-
figure
225-
plot(x, y1)
226-
xlim([20, 80])
227-
ylim([20, 80])
228-
set(gcf,'Units','Inches');
229-
set(gcf,'Position',[2.5 2.5 5 5])
230-
cleanfigure;
231-
```
232-
"""
233-
x = np.array(
234-
[
235-
21.842106,
236-
27.052631,
237-
32.263157,
238-
37.473682,
239-
42.68421,
240-
47.894737,
241-
53.105263,
242-
58.31579,
243-
63.526318,
244-
68.73684,
245-
73.947365,
246-
79.1579,
247-
]
248-
)
249-
y = x.copy()
250-
tol = 0.02
251-
mask = cleanfigure._opheim_simplify(x, y, tol)
252-
assert mask.shape == (12,)
253-
assert np.allclose(mask * 1, np.array([1] + [0] * 10 + [1]))
254-
255-
25680
@pytest.mark.parametrize(
25781
"function, result", [("plot", False), ("step", True)],
25882
)
@@ -797,136 +621,6 @@ def test_subplot(self):
797621
plt.close("all")
798622

799623

800-
def test_segmentVisible():
801-
"""test against matlab2tikz implementation
802-
803-
octave code to generate baseline results. Note that octave has indexing 1...N, whereas python has indexing 0...N-1.
804-
```octave
805-
x = linspace(1, 100, 20);
806-
y1 = linspace(1, 100, 20);
807-
808-
figure
809-
plot(x, y1)
810-
xlim([20, 80])
811-
ylim([20, 80])
812-
cleanfigure;
813-
```
814-
"""
815-
816-
y = np.linspace(1, 100, 20)
817-
x = y.copy()
818-
data = np.stack([x, y], axis=1)
819-
dataIsInBox = np.array([0] * 4 + [1] * 12 + [0] * 4) == 1
820-
xLim = np.array([20, 80])
821-
yLim = np.array([20, 80])
822-
mask = cleanfigure._segment_visible(data, dataIsInBox, xLim, yLim)
823-
assert np.allclose(mask * 1, np.array([0] * 3 + [1] * 13 + [0] * 3))
824-
825-
826-
def test_crossLines():
827-
"""test against matplotlib2tikz implementation"""
828-
y = np.linspace(1, 100, 20)
829-
x = y.copy()
830-
data = np.stack([x, y], axis=1)
831-
X1 = data[:-1, :]
832-
X2 = data[1:, :]
833-
X3 = np.array([80, 20])
834-
X4 = np.array([80, 80])
835-
Lambda = cleanfigure._cross_lines(X1, X2, X3, X4)
836-
837-
expected_result = np.array(
838-
[
839-
[15.16162, 1.00000],
840-
[14.16162, 1.00000],
841-
[13.16162, 1.00000],
842-
[12.16162, 1.00000],
843-
[11.16162, 1.00000],
844-
[10.16162, 1.00000],
845-
[9.16162, 1.00000],
846-
[8.16162, 1.00000],
847-
[7.16162, 1.00000],
848-
[6.16162, 1.00000],
849-
[5.16162, 1.00000],
850-
[4.16162, 1.00000],
851-
[3.16162, 1.00000],
852-
[2.16162, 1.00000],
853-
[1.16162, 1.00000],
854-
[0.16162, 1.00000],
855-
[-0.83838, 1.00000],
856-
[-1.83838, 1.00000],
857-
[-2.83838, 1.00000],
858-
]
859-
)
860-
assert np.allclose(Lambda, expected_result, rtol=1.0e-4)
861-
862-
863-
def test_segmentsIntersect():
864-
"""test against matplotlib2tikz implementation"""
865-
y = np.linspace(1, 100, 20)
866-
x = y.copy()
867-
data = np.stack([x, y], axis=1)
868-
X1 = data[:-1, :]
869-
X2 = data[1:, :]
870-
X3 = np.array([80, 20])
871-
X4 = np.array([80, 80])
872-
mask = cleanfigure._segments_intersect(X1, X2, X3, X4)
873-
assert np.allclose(mask * 1, np.zeros_like(mask))
874-
875-
876-
def test_pixelate():
877-
xToPix = 49.952
878-
yToPix = 49.952
879-
xData = np.array(
880-
[
881-
21.842,
882-
27.053,
883-
32.263,
884-
37.474,
885-
42.684,
886-
47.895,
887-
53.105,
888-
58.316,
889-
63.526,
890-
68.737,
891-
73.947,
892-
79.158,
893-
]
894-
)
895-
yData = xData.copy()
896-
mask = cleanfigure._pixelate(xData, yData, xToPix, yToPix)
897-
assert mask.shape == (12,)
898-
assert np.all(mask)
899-
900-
901-
def test_corners3D():
902-
xlim = ylim = zlim = np.array([-5, 5])
903-
corners = cleanfigure._corners3D(xlim, ylim, zlim)
904-
905-
assert corners.shape == (8, 3)
906-
assert np.sum(corners) == 0
907-
908-
909-
def test_corners2D():
910-
xLim = np.array([20, 80])
911-
yLim = np.array([20, 80])
912-
corners = cleanfigure._corners2D(xLim, yLim)
913-
914-
import itertools
915-
916-
expected_output = tuple(np.array(t) for t in itertools.product([20, 80], [20, 80]))
917-
assert np.allclose(corners, expected_output)
918-
919-
920-
def test_getHeightWidthInPixels():
921-
with plt.rc_context(rc=RC_PARAMS):
922-
fig, axes = plt.subplots(1, 1, figsize=(5, 5))
923-
w, h = cleanfigure._get_width_height_in_pixels(fig, [600, 400])
924-
assert w == 600 and h == 400
925-
w, h = cleanfigure._get_width_height_in_pixels(fig, 600)
926-
assert w == h
927-
plt.close("all")
928-
929-
930624
def test_memory():
931625
import matplotlib.pyplot as plt
932626
import numpy as np

0 commit comments

Comments
 (0)