MCPcopy Index your code
hub / github.com/gonum/plot / TestLineWidth

Function TestLineWidth

vg/vg_test.go:24–86  ·  view source on GitHub ↗

TestLineWidth tests output against test images generated by running tests with -tag good.

(t *testing.T)

Source from the content-addressed store, hash-verified

22// TestLineWidth tests output against test images generated by
23// running tests with -tag good.
24func TestLineWidth(t *testing.T) {
25 formats := []string{
26 // TODO: Add logic to cope with run to run eps differences.
27 "pdf",
28 "svg",
29 "png",
30 "tiff",
31 "jpg",
32 }
33
34 const (
35 width = 100
36 height = 100
37 )
38
39 for _, w := range []vg.Length{-1, 0, 1} {
40 for _, typ := range formats {
41 p, err := lines(w)
42 if err != nil {
43 log.Fatalf("failed to create plot for %v:%s: %v", w, typ, err)
44 }
45
46 c, err := p.WriterTo(width, height, typ)
47 if err != nil {
48 t.Fatalf("failed to render plot for %v:%s: %v", w, typ, err)
49 }
50
51 var buf bytes.Buffer
52 if _, err = c.WriteTo(&buf); err != nil {
53 t.Fatalf("failed to write plot for %v:%s: %v", w, typ, err)
54 }
55
56 name := filepath.Join(".", "testdata", fmt.Sprintf("width_%v_golden.%s", w, typ))
57
58 // Recreate Golden images.
59 if *cmpimg.GenerateTestData {
60 err = p.Save(width, height, name)
61 if err != nil {
62 log.Fatalf("failed to save %q: %v", name, err)
63 }
64 }
65
66 want, err := os.ReadFile(name)
67 if err != nil {
68 t.Fatalf("failed to read test image [%s]: %v\n", name, err)
69 }
70
71 ok, err := cmpimg.Equal(typ, buf.Bytes(), want)
72 if err != nil {
73 t.Fatalf("failed to run cmpimg test [%s]: %v\n", name, err)
74 }
75
76 if !ok {
77 got := strings.Replace(name, "_golden.", ".", 1)
78 err = os.WriteFile(got, buf.Bytes(), 0644)
79 if err != nil {
80 t.Errorf("could not write plot image %q: %+v", got, err)
81 }

Callers

nothing calls this directly

Calls 5

EqualFunction · 0.92
linesFunction · 0.85
WriterToMethod · 0.80
SaveMethod · 0.80
WriteToMethod · 0.45

Tested by

no test coverage detected