Skip to content

Commit 320027f

Browse files
committed
Refactored reference tests
1 parent dfb29f0 commit 320027f

13 files changed

Lines changed: 1472 additions & 1415 deletions

spec/reference/barplot_spec.cr

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
require "../support/reference_helpers"
2+
3+
describe "Julia reference output compatibility - barplot" do
4+
describe "barplot" do
5+
it "matches barplot/default" do
6+
p = UnicodePlot.barplot(["bar", "foo"], [23.0, 37.0])
7+
test_ref("barplot/default.txt", p)
8+
end
9+
10+
it "matches barplot/default2 (with barplot! appended)" do
11+
p = UnicodePlot.barplot(["bar", "foo"], [23.0, 37.0])
12+
UnicodePlot.barplot!(p, ["zoom"], [90.0])
13+
test_ref("barplot/default2.txt", p)
14+
end
15+
16+
it "matches barplot/nocolor" do
17+
p = UnicodePlot.barplot(["bar", "foo"], [23.0, 37.0])
18+
test_ref("barplot/nocolor.txt", p)
19+
end
20+
21+
it "matches barplot/ranges" do
22+
p = UnicodePlot.barplot(["2", "3", "4", "5", "6"], [11.0, 12.0, 13.0, 14.0, 15.0])
23+
test_ref("barplot/ranges.txt", p)
24+
end
25+
26+
it "matches barplot/ranges2" do
27+
p = UnicodePlot.barplot(["2", "3", "4", "5", "6"], [11.0, 12.0, 13.0, 14.0, 15.0])
28+
UnicodePlot.barplot!(p, ["9", "10"], [20.0, 21.0])
29+
test_ref("barplot/ranges2.txt", p)
30+
end
31+
32+
it "matches barplot/parameters1" do
33+
p = UnicodePlot.barplot(
34+
["Paris", "New York", "Moskau", "Madrid"],
35+
[2.244, 8.406, 11.92, 3.165],
36+
title: "Relative sizes of cities",
37+
xlabel: "population [in mil]",
38+
color: :blue,
39+
margin: 7,
40+
padding: 3,
41+
)
42+
test_ref("barplot/parameters1.txt", p)
43+
end
44+
45+
it "matches barplot/parameters1_nolabels" do
46+
p = UnicodePlot.barplot(
47+
["Paris", "New York", "Moskau", "Madrid"],
48+
[2.244, 8.406, 11.92, 3.165],
49+
title: "Relative sizes of cities",
50+
xlabel: "population [in mil]",
51+
color: :blue,
52+
margin: 7,
53+
padding: 3,
54+
labels: false,
55+
)
56+
test_ref("barplot/parameters1_nolabels.txt", p)
57+
end
58+
59+
it "matches barplot/parameters2" do
60+
p = UnicodePlot.barplot(
61+
["Paris", "New York", "Moskau", "Madrid"],
62+
[2.244, 8.406, 11.92, 3.165],
63+
title: "Relative sizes of cities",
64+
xlabel: "population [in mil]",
65+
color: :yellow,
66+
border: :solid,
67+
symbols: ['='],
68+
width: 60,
69+
)
70+
test_ref("barplot/parameters2.txt", p)
71+
end
72+
73+
it "matches barplot/edgecase_zeros" do
74+
p = UnicodePlot.barplot(["5", "4", "3", "2", "1"], [0.0, 0.0, 0.0, 0.0, 0.0])
75+
test_ref("barplot/edgecase_zeros.txt", p)
76+
end
77+
78+
it "matches barplot/edgecase_onelarge" do
79+
p = UnicodePlot.barplot(["a", "b", "c", "d"], [1.0, 1.0, 1.0, 1_000_000.0])
80+
test_ref("barplot/edgecase_onelarge.txt", p)
81+
end
82+
83+
it "matches barplot/col1 (8-bit terminal color, ANSI stripped)" do
84+
p = UnicodePlot.barplot(["B", "A"], [2.0, 1.0], color: 9_i32)
85+
test_ref("barplot/col1.txt", p)
86+
end
87+
88+
it "matches barplot/log10" do
89+
p = UnicodePlot.barplot(
90+
["a", "b", "c", "d", "e"],
91+
[0.0, 1.0, 10.0, 100.0, 1_000.0],
92+
title: "Logscale Plot",
93+
xscale: :log10,
94+
)
95+
test_ref("barplot/log10.txt", p)
96+
end
97+
98+
it "matches barplot/log10_label" do
99+
p = UnicodePlot.barplot(
100+
["a", "b", "c", "d", "e"],
101+
[0.0, 1.0, 10.0, 100.0, 1_000.0],
102+
title: "Logscale Plot",
103+
xlabel: "custom label",
104+
xscale: :log10,
105+
)
106+
test_ref("barplot/log10_label.txt", p)
107+
end
108+
109+
it "matches barplot/col2 (RGB tuple color)" do
110+
p = UnicodePlot.barplot(["B", "A"], [2.0, 1.0], color: {200, 50, 0})
111+
test_ref("barplot/col2.txt", p)
112+
end
113+
114+
it "matches barplot/colors (per-bar color vector)" do
115+
p = UnicodePlot.barplot(
116+
["a", "b", "c", "d", "e"],
117+
[20.0, 30.0, 60.0, 50.0, 40.0],
118+
color: [:red, :green, :blue, :yellow, :normal],
119+
)
120+
test_ref("barplot/colors.txt", p)
121+
end
122+
123+
it "matches barplot/maximum_series1" do
124+
p = UnicodePlot.barplot(
125+
["1", "2", "3"],
126+
[1.0, 2.0, 3.0],
127+
color: :blue,
128+
name: "1ˢᵗ series",
129+
maximum: 10.0,
130+
)
131+
test_ref("barplot/maximum_series1.txt", p)
132+
end
133+
134+
it "matches barplot/maximum_series2" do
135+
p = UnicodePlot.barplot(
136+
["1", "2", "3"],
137+
[1.0, 2.0, 3.0],
138+
color: :blue,
139+
name: "1ˢᵗ series",
140+
maximum: 10.0,
141+
)
142+
UnicodePlot.barplot!(p, ["4", "5", "6"], [6.0, 1.0, 10.0], color: :red, name: "2ⁿᵈ series")
143+
test_ref("barplot/maximum_series2.txt", p)
144+
end
145+
end
146+
147+
end

spec/reference/boxplot_spec.cr

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require "../support/reference_helpers"
2+
3+
describe "Julia reference output compatibility - boxplot" do
4+
describe "boxplot" do
5+
it "matches boxplot/default" do
6+
p = UnicodePlot.boxplot([1.0, 2.0, 3.0, 4.0, 5.0])
7+
test_ref("boxplot/default.txt", p)
8+
end
9+
10+
it "matches boxplot/default_name" do
11+
p = UnicodePlot.boxplot("series1", [1.0, 2.0, 3.0, 4.0, 5.0])
12+
test_ref("boxplot/default_name.txt", p)
13+
end
14+
15+
it "matches boxplot/scale1 (xlim 0..5)" do
16+
p = UnicodePlot.boxplot([1.0, 2.0, 3.0, 4.0, 5.0], xlim: {0.0, 5.0})
17+
test_ref("boxplot/scale1.txt", p)
18+
end
19+
20+
it "matches boxplot/scale2 (xlim 0..6)" do
21+
p = UnicodePlot.boxplot([1.0, 2.0, 3.0, 4.0, 5.0], xlim: {0.0, 6.0})
22+
test_ref("boxplot/scale2.txt", p)
23+
end
24+
25+
it "matches boxplot/scale3 (xlim 0..10)" do
26+
p = UnicodePlot.boxplot([1.0, 2.0, 3.0, 4.0, 5.0], xlim: {0.0, 10.0})
27+
test_ref("boxplot/scale3.txt", p)
28+
end
29+
30+
it "matches boxplot/scale4 (xlim 0..20)" do
31+
p = UnicodePlot.boxplot([1.0, 2.0, 3.0, 4.0, 5.0], xlim: {0.0, 20.0})
32+
test_ref("boxplot/scale4.txt", p)
33+
end
34+
35+
it "matches boxplot/scale5 (xlim 0..40)" do
36+
p = UnicodePlot.boxplot([1.0, 2.0, 3.0, 4.0, 5.0], xlim: {0.0, 40.0})
37+
test_ref("boxplot/scale5.txt", p)
38+
end
39+
40+
it "matches boxplot/multi1 (two named series)" do
41+
p = UnicodePlot.boxplot(
42+
["one", "two"],
43+
[[1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]],
44+
title: "Multi-series", xlabel: "foo", color: :yellow
45+
)
46+
test_ref("boxplot/multi1.txt", p)
47+
end
48+
49+
it "matches boxplot/multi2 (after boxplot! appends third series)" do
50+
p = UnicodePlot.boxplot(
51+
["one", "two"],
52+
[[1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]],
53+
title: "Multi-series", xlabel: "foo", color: :yellow
54+
)
55+
UnicodePlot.boxplot!(p, "one more", [-1.0, 2.0, 3.0, 4.0, 11.0])
56+
test_ref("boxplot/multi2.txt", p)
57+
end
58+
59+
it "matches boxplot/multi3 (after second boxplot! with name kwarg)" do
60+
p = UnicodePlot.boxplot(
61+
["one", "two"],
62+
[[1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]],
63+
title: "Multi-series", xlabel: "foo", color: :yellow
64+
)
65+
UnicodePlot.boxplot!(p, "one more", [-1.0, 2.0, 3.0, 4.0, 11.0])
66+
UnicodePlot.boxplot!(p, [4.0, 2.0, 2.5, 4.0, 14.0], name: "last one")
67+
test_ref("boxplot/multi3.txt", p)
68+
end
69+
70+
it "matches boxplot/multi4 (unnamed multi-series)" do
71+
p = UnicodePlot.boxplot([[1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]])
72+
test_ref("boxplot/multi4.txt", p)
73+
end
74+
end
75+
76+
end

spec/reference/contourplot_spec.cr

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
require "../support/reference_helpers"
2+
3+
describe "Julia reference output compatibility - contourplot" do
4+
describe "contourplot" do
5+
# NOTE: Contour parity work is intentionally paused for the failing reference cases below.
6+
#
7+
# Investigation summary (Crystal vs Julia):
8+
# - Failing snapshots are limited to: padding_0..3 and consistency.
9+
# - Extracted contour geometry is effectively equivalent:
10+
# - per-level vertex counts match,
11+
# - point sets match,
12+
# - undirected segment sets match.
13+
# - Despite that, rendered text differs reproducibly in these cases.
14+
# - This strongly suggests the remaining mismatch is in rasterization / line drawing
15+
# order sensitivity (Canvas/lines!), not in contour topology extraction itself.
16+
#
17+
# Experiments attempted (no resolution):
18+
# - changed contour cell traversal order,
19+
# - changed level comparison (> vs >=),
20+
# - normalized polyline segment direction at draw time,
21+
# - verified ambiguous marching-squares cases still pass contour unit specs.
22+
#
23+
# Keep these 5 specs pending until Canvas parity work is resumed.
24+
pending "matches contourplot/padding_0 (Known parity gap: contour geometry matches Julia, rendered raster output still differs)" do
25+
x = range_by_step(-1.0, 1.0, 0.1)
26+
y = x
27+
z = y.map { |yv| x.map { |xv| 1.0e4 * Math.sqrt(xv**2 + yv**2) } }
28+
p = UnicodePlot.contourplot(x, y, z, labels: false, margin: 0, padding: 0)
29+
test_ref("contourplot/padding_0.txt", p)
30+
end
31+
32+
pending "matches contourplot/padding_1 (Known parity gap: contour geometry matches Julia, rendered raster output still differs)" do
33+
x = range_by_step(-1.0, 1.0, 0.1)
34+
y = x
35+
z = y.map { |yv| x.map { |xv| 1.0e4 * Math.sqrt(xv**2 + yv**2) } }
36+
p = UnicodePlot.contourplot(x, y, z, labels: false, margin: 0, padding: 1)
37+
test_ref("contourplot/padding_1.txt", p)
38+
end
39+
40+
pending "matches contourplot/padding_2 (Known parity gap: contour geometry matches Julia, rendered raster output still differs)" do
41+
x = range_by_step(-1.0, 1.0, 0.1)
42+
y = x
43+
z = y.map { |yv| x.map { |xv| 1.0e4 * Math.sqrt(xv**2 + yv**2) } }
44+
p = UnicodePlot.contourplot(x, y, z, labels: false, margin: 0, padding: 2)
45+
test_ref("contourplot/padding_2.txt", p)
46+
end
47+
48+
pending "matches contourplot/padding_3 (Known parity gap: contour geometry matches Julia, rendered raster output still differs)" do
49+
x = range_by_step(-1.0, 1.0, 0.1)
50+
y = x
51+
z = y.map { |yv| x.map { |xv| 1.0e4 * Math.sqrt(xv**2 + yv**2) } }
52+
p = UnicodePlot.contourplot(x, y, z, labels: false, margin: 0, padding: 3)
53+
test_ref("contourplot/padding_3.txt", p)
54+
end
55+
56+
it "matches contourplot/gauss_cividis" do
57+
x, y, z = gaussian_2d
58+
p = UnicodePlot.contourplot(x, y, z, colormap: :cividis)
59+
test_ref("contourplot/gauss_cividis.txt", p)
60+
end
61+
62+
it "matches contourplot/gauss_5levels" do
63+
x, y, z = gaussian_2d
64+
p = UnicodePlot.contourplot(x, y, z, levels: 5)
65+
test_ref("contourplot/gauss_5levels.txt", p)
66+
end
67+
68+
it "matches contourplot/gauss_nested" do
69+
x1, y1, z1 = gaussian_2d
70+
p = UnicodePlot.contourplot(x1, y1, z1, levels: 2)
71+
72+
x2, y2, z2 = gaussian_2d(sigma_x: 0.5, sigma_y: 0.25)
73+
UnicodePlot.contourplot!(p, x2, y2, z2, levels: 1, colormap: :magma)
74+
test_ref("contourplot/gauss_nested.txt", p)
75+
end
76+
77+
it "matches contourplot/function_contour" do
78+
x = range_by_step(-3.0, 3.0, 0.01)
79+
y = range_by_step(-3.0, 4.0, 0.01)
80+
z = y.map do |yv|
81+
x.map do |xv|
82+
t1 = Math.exp(-(xv**2) - (yv**2))
83+
t2 = Math.exp(-((xv - 1.0)**2) - 2.0 * ((yv - 2.0)**2))
84+
(t1 + t2)**2
85+
end
86+
end
87+
p = UnicodePlot.contourplot(x, y, z)
88+
test_ref("contourplot/function_contour.txt", p)
89+
end
90+
91+
pending "matches contourplot/consistency (Known parity gap: contour geometry matches Julia, rendered raster output still differs)" do
92+
x = range_by_step(-2.0, 2.0, 0.2)
93+
y = range_by_step(-3.0, 1.0, 0.2)
94+
z = y.map { |yv| x.map { |xv| 10.0 * xv * Math.exp(-(xv**2) - (yv**2)) } }
95+
p = UnicodePlot.contourplot(x, y, z, levels: 10)
96+
test_ref("contourplot/consistency.txt", p)
97+
end
98+
end
99+
end

spec/reference/densityplot_spec.cr

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require "../support/reference_helpers"
2+
3+
describe "Julia reference output compatibility - densityplot" do
4+
describe "densityplot" do
5+
it "matches densityplot/densityplot" do
6+
x = DENSITYPLOT_X
7+
y = DENSITYPLOT_Y
8+
p = UnicodePlot.densityplot(x, y)
9+
UnicodePlot.densityplot!(p, x.map { |v| v + 2.0 }, y.map { |v| v + 2.0 })
10+
test_ref("densityplot/densityplot.txt", p)
11+
end
12+
13+
it "matches densityplot/densityplot_parameters" do
14+
x = DENSITYPLOT_X
15+
y = DENSITYPLOT_Y
16+
p = UnicodePlot.densityplot(x, y, name: "foo", color: :red, title: "Title", xlabel: "x")
17+
UnicodePlot.densityplot!(p, x.map { |v| v + 2.0 }, y.map { |v| v + 2.0 }, name: "bar")
18+
test_ref("densityplot/densityplot_parameters.txt", p)
19+
end
20+
21+
it "matches densityplot/densityplot_dscale_identity" do
22+
x = densityplot_fixture_xprime(DENSITYPLOT_X)
23+
p = UnicodePlot.densityplot(x, DENSITYPLOT_Y, dscale: :identity)
24+
test_ref("densityplot/densityplot_dscale_identity.txt", p)
25+
end
26+
27+
it "matches densityplot/densityplot_dscale_sqrt" do
28+
x = densityplot_fixture_xprime(DENSITYPLOT_X)
29+
p = UnicodePlot.densityplot(x, DENSITYPLOT_Y, dscale: :sqrt)
30+
test_ref("densityplot/densityplot_dscale_sqrt.txt", p)
31+
end
32+
33+
it "matches densityplot/densityplot_dscale_log" do
34+
x = densityplot_fixture_xprime(DENSITYPLOT_X)
35+
p = UnicodePlot.densityplot(x, DENSITYPLOT_Y, dscale: ->(v : Float64) { Math.log(1.0 + v) })
36+
test_ref("densityplot/densityplot_dscale_log.txt", p)
37+
end
38+
39+
it "matches densityplot/densityplot_dscale_custom" do
40+
x = densityplot_fixture_xprime(DENSITYPLOT_X)
41+
p = UnicodePlot.densityplot(x, DENSITYPLOT_Y, dscale: ->(v : Float64) { v / (v + 1.0) })
42+
test_ref("densityplot/densityplot_dscale_custom.txt", p)
43+
end
44+
end
45+
46+
end

0 commit comments

Comments
 (0)