gonum.org/v1/gonum@v0.14.0/unit/magneticflux_test.go (about)

     1  // Code generated by "go generate gonum.org/v1/gonum/unit; DO NOT EDIT.
     2  
     3  // Copyright ©2019 The Gonum Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package unit
     8  
     9  import (
    10  	"fmt"
    11  	"testing"
    12  )
    13  
    14  func TestMagneticFlux(t *testing.T) {
    15  	t.Parallel()
    16  	for _, value := range []float64{-1, 0, 1} {
    17  		var got MagneticFlux
    18  		err := got.From(MagneticFlux(value).Unit())
    19  		if err != nil {
    20  			t.Errorf("unexpected error for %T conversion: %v", got, err)
    21  		}
    22  		if got != MagneticFlux(value) {
    23  			t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, value, got, value)
    24  		}
    25  		if got != got.MagneticFlux() {
    26  			t.Errorf("unexpected result from self interface method call: got: %#v want: %#v", got, value)
    27  		}
    28  		err = got.From(ether(1))
    29  		if err == nil {
    30  			t.Errorf("expected error for ether to %T conversion", got)
    31  		}
    32  	}
    33  }
    34  
    35  func TestMagneticFluxFormat(t *testing.T) {
    36  	t.Parallel()
    37  	for _, test := range []struct {
    38  		value  MagneticFlux
    39  		format string
    40  		want   string
    41  	}{
    42  		{1.23456789, "%v", "1.23456789 Wb"},
    43  		{1.23456789, "%.1v", "1 Wb"},
    44  		{1.23456789, "%20.1v", "                1 Wb"},
    45  		{1.23456789, "%20v", "       1.23456789 Wb"},
    46  		{1.23456789, "%1v", "1.23456789 Wb"},
    47  		{1.23456789, "%#v", "unit.MagneticFlux(1.23456789)"},
    48  		{1.23456789, "%s", "%!s(unit.MagneticFlux=1.23456789 Wb)"},
    49  	} {
    50  		got := fmt.Sprintf(test.format, test.value)
    51  		if got != test.want {
    52  			t.Errorf("Format %q %v: got: %q want: %q", test.format, test.value, got, test.want)
    53  		}
    54  	}
    55  }