go-hep.org/x/hep@v0.38.1/hplot/plot_test.go (about) 1 // Copyright ©2020 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package hplot_test 6 7 import ( 8 "os" 9 "sync" 10 "testing" 11 12 "go-hep.org/x/hep/hplot" 13 "gonum.org/v1/plot/cmpimg" 14 "gonum.org/v1/plot/vg" 15 ) 16 17 func TestPlotWriterTo(t *testing.T) { 18 checkPlot(cmpimg.CheckPlot)(func() { 19 p := hplot.New() 20 p.Title.Text = "title" 21 p.X.Label.Text = "x" 22 p.Y.Label.Text = "y" 23 24 c, err := p.WriterTo(5*vg.Centimeter, 5*vg.Centimeter, "png") 25 if err != nil { 26 t.Fatal(err) 27 } 28 29 f, err := os.Create("testdata/plot_writerto.png") 30 if err != nil { 31 t.Fatal(err) 32 } 33 defer f.Close() 34 35 _, err = c.WriteTo(f) 36 if err != nil { 37 t.Fatal(err) 38 } 39 40 err = f.Close() 41 if err != nil { 42 t.Fatal(err) 43 } 44 }, t, "plot_writerto.png") 45 } 46 47 func TestNewPlotRace(t *testing.T) { 48 const N = 100 49 var wg sync.WaitGroup 50 wg.Add(N) 51 for range N { 52 go func() { 53 defer wg.Done() 54 55 _ = hplot.New() 56 }() 57 } 58 59 wg.Wait() 60 }