Skip to content

Commit f260201

Browse files
karwaKarthikRIyer
authored andcommitted
Verify that test output files actually match the reference files (#59)
* Verify that images produced by tests exactly match their reference files. There are only 3 failures, which is rather good. - 2 Histogram step graphs. The reference images likely predate the recent bug-fix and need updating. - Nested subplots. The scale on the Y axis appears to have increased. Investigating. * Verified that histogram failures are due to recent bug fix: - SVG output is correct. - Difference is only in the stacked histogram, which has become a bit shorter since it's no longer accumulating state from previous renders. * Manually confirmed that function plot failure on CoreGraphics is due to addition of "clampY" parameter by reverting to the old algorithm and having it pass. 19b308b updated the reference for the other images, but missed CG. Updating that image now. * Verified that subplot test failure was due to randomness in the dataset. Replaced it with a repeatable pattern. * Improved the base64 encoding test. Actually, to the extent that we seem to have found a massive bug (which hasn't been fixed, so this test now XFAILs). We know from the original BarChart test that the AGG renderer produces identical binary files when writing to disk - however, when encoding both images, they do not encode to the same output. Moreover, the test output appears invalid and many browsers do not seem to want to render it. * Update SVG reference files for f309cf4 Semi-colons matter!
1 parent b1960a0 commit f260201

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+733
-578
lines changed

Tests/SwiftPlotTests/AGGRenderer/agg-png-output.swift

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,42 @@ import SwiftPlot
44
import AGGRenderer
55

66
extension AGGRendererTests {
7+
8+
/// **XFAIL**
9+
///
10+
/// Tests that base64 encoding is accurate by drawing a known graph directly in to
11+
/// a PNG buffer (no files), then verifying the base64-encoded data matches that from
12+
/// the reference file.
13+
func testBase64Encoding() throws {
714

8-
func testBase64Encoding() {
9-
let renderer = AGGRenderer()
10-
let rect = Rect(origin: zeroPoint, size: Size(width: 200, height: 200))
11-
12-
renderer.imageSize = rect.size
13-
renderer.drawSolidRect(rect, fillColor: .white, hatchPattern: .none)
14-
renderer.drawSolidCircle(center: Point(100,100), radius: 75, fillColor: .red)
15-
16-
let png = renderer.base64Png()
17-
XCTAssertEqual(png.count, 2315)
18-
19-
// Check that we can decode it again.
20-
guard let data = Data(base64Encoded: png, options: .ignoreUnknownCharacters) else {
21-
XCTFail("Failed to decode base64-encoded PNG")
22-
return
23-
}
24-
XCTAssertEqual(data.count, 1710)
25-
// Check expected data.
26-
// A reference file would be better, but this will have to do for now.
27-
let pngPrefix = png.prefix(128)
28-
let pngSuffix = png.suffix(128)
29-
XCTAssertEqual(
30-
String(pngPrefix),
31-
#"iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAABL1BMVEX/////6+v/"# + "\r\n" +
32-
#"w8P/m5v/gYH/aWn/UVH/ODj/JCT/HBz/FBT/DAz/AwP//v7/39//pqb/bGz/PT3"#
33-
)
34-
XCTAssertEqual(
35-
String(pngSuffix),
36-
#"bOhf/ybcSl/8JBL307q16z"# + "\r\n" +
37-
#"r65fM1xf2bV6P3+K7hZuvI3bu9L9w/VjOPx4/XBfurtteG886F0mk8lkMplMJpPJ"# + "\r\n" +
38-
#"ZDKZTCaTSUH/ABlnILfhHFVMAAAAAElFTkSuQmCC"#
39-
)
15+
let x:[String] = ["2008","2009","2010","2011"]
16+
let y:[Float] = [320,-100,420,500]
17+
let barGraph = BarGraph<String,Float>(enableGrid: true)
18+
barGraph.addSeries(x, y, label: "Plot 1", color: .orange, hatchPattern: .cross)
19+
barGraph.plotTitle = PlotTitle("HATCHED BAR CHART")
20+
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
21+
22+
let renderer = AGGRenderer()
23+
barGraph.drawGraph(renderer: renderer)
24+
let outputBase64 = renderer.base64Png()
25+
XCTAssertEqual(outputBase64.count, 47397)
26+
27+
// First, sanity check: ensure *we* can decode the string.
28+
guard let _ = Data(base64Encoded: outputBase64, options: .ignoreUnknownCharacters) else {
29+
XCTFail("Failed to decode base64-encoded PNG")
30+
return
4031
}
32+
// Check the contents match a base64-encoded version of the
33+
// reference image.
34+
let fileName = "_15_bar_chart_cross_hatched"
35+
let referenceFile = referenceDirectory(for: .agg)
36+
.appendingPathComponent(fileName)
37+
.appendingPathExtension(KnownRenderer.agg.fileExtension)
38+
let referenceBase64 = try Data(contentsOf: referenceFile)
39+
.base64EncodedString()//(options: .lineLength64Characters)
40+
41+
//XCTAssertEqual(outputBase64, referenceBase64)
42+
}
4143
}
4244

4345
#endif // canImport(AGGRenderer)

Tests/SwiftPlotTests/BarChart/barchart-hatched-backwardslash.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-cross.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import QuartzRenderer
1010
@available(tvOS 13, watchOS 13, *)
1111
extension BarchartTests {
1212

13+
/// - note: This test is duplicated to also test base64 encoding.
14+
/// If the test changes, please update that test, too.
1315
func testBarchartHatchedCross() throws {
1416

1517
let fileName = "_15_bar_chart_cross_hatched"
@@ -23,17 +25,20 @@ extension BarchartTests {
2325
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2426

2527
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
28+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2729
renderer: svg_renderer)
30+
verifyImage(name: fileName, renderer: .svg)
2831
#if canImport(AGGRenderer)
2932
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
33+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3134
renderer: agg_renderer)
35+
verifyImage(name: fileName, renderer: .agg)
3236
#endif
3337
#if canImport(QuartzRenderer)
3438
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
39+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3640
renderer: quartz_renderer)
41+
verifyImage(name: fileName, renderer: .coreGraphics)
3742
#endif
3843
}
3944
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-filledcircle.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-forwardsslash.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-grid.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-hollowcircle.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-horizontal.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-hatched-vertical.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

Tests/SwiftPlotTests/BarChart/barchart-orientation-horizontal.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension BarchartTests {
2323
barGraph.plotLabel = PlotLabel(xLabel: "X-AXIS", yLabel: "Y-AXIS")
2424

2525
let svg_renderer = SVGRenderer()
26-
try barGraph.drawGraphAndOutput(fileName: self.svgOutputDirectory+fileName,
26+
try barGraph.drawGraphAndOutput(fileName: svgOutputDirectory+fileName,
2727
renderer: svg_renderer)
28+
verifyImage(name: fileName, renderer: .svg)
2829
#if canImport(AGGRenderer)
2930
let agg_renderer = AGGRenderer()
30-
try barGraph.drawGraphAndOutput(fileName: self.aggOutputDirectory+fileName,
31+
try barGraph.drawGraphAndOutput(fileName: aggOutputDirectory+fileName,
3132
renderer: agg_renderer)
33+
verifyImage(name: fileName, renderer: .agg)
3234
#endif
3335
#if canImport(QuartzRenderer)
3436
let quartz_renderer = QuartzRenderer()
35-
try barGraph.drawGraphAndOutput(fileName: self.coreGraphicsOutputDirectory+fileName,
37+
try barGraph.drawGraphAndOutput(fileName: coreGraphicsOutputDirectory+fileName,
3638
renderer: quartz_renderer)
39+
verifyImage(name: fileName, renderer: .coreGraphics)
3740
#endif
3841
}
3942
}

0 commit comments

Comments
 (0)