...

Source file src/gonum.org/v1/plot/plotter/histogram_test.go

Documentation: gonum.org/v1/plot/plotter

     1  // Copyright ©2015 The Gonum 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 plotter_test
     6  
     7  import (
     8  	"testing"
     9  	"time"
    10  
    11  	"gonum.org/v1/plot"
    12  	"gonum.org/v1/plot/cmpimg"
    13  	"gonum.org/v1/plot/plotter"
    14  	"gonum.org/v1/plot/vg"
    15  )
    16  
    17  func TestHistogram(t *testing.T) {
    18  	cmpimg.CheckPlot(ExampleHistogram, t, "histogram.png")
    19  }
    20  
    21  func TestSingletonHistogram(t *testing.T) {
    22  	done := make(chan struct{}, 1)
    23  	go func() {
    24  		defer close(done)
    25  		p := plot.New()
    26  		hist, err := plotter.NewHist(plotter.Values([]float64{1.0}), 60)
    27  		if err != nil {
    28  			t.Errorf("unexpected error from NewHist: %v", err)
    29  			return
    30  		}
    31  		hist.Normalize(1)
    32  
    33  		p.Add(hist)
    34  
    35  		_, err = p.WriterTo(4*vg.Inch, 4*vg.Inch, "png")
    36  		if err != nil {
    37  			t.Errorf("unexpected error from WriterTo: %v", err)
    38  			return
    39  		}
    40  	}()
    41  
    42  	select {
    43  	case <-time.After(10 * time.Second):
    44  		t.Error("histogram timed out")
    45  	case <-done:
    46  	}
    47  }
    48  func TestHistogramLogScale(t *testing.T) {
    49  	cmpimg.CheckPlot(ExampleHistogram_logScaleY, t, "histogram_logy.png")
    50  }
    51  

View as plain text