github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/unit/voltage_test.go (about)

     1  // Code generated by "go generate github.com/jingcheng-WU/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 TestVoltage(t *testing.T) {
    15  	t.Parallel()
    16  	for _, value := range []float64{-1, 0, 1} {
    17  		var got Voltage
    18  		err := got.From(Voltage(value).Unit())
    19  		if err != nil {
    20  			t.Errorf("unexpected error for %T conversion: %v", got, err)
    21  		}
    22  		if got != Voltage(value) {
    23  			t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
    24  		}
    25  		if got != got.Voltage() {
    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 TestVoltageFormat(t *testing.T) {
    36  	t.Parallel()
    37  	for _, test := range []struct {
    38  		value  Voltage
    39  		format string
    40  		want   string
    41  	}{
    42  		{1.23456789, "%v", "1.23456789 V"},
    43  		{1.23456789, "%.1v", "1 V"},
    44  		{1.23456789, "%20.1v", "                 1 V"},
    45  		{1.23456789, "%20v", "        1.23456789 V"},
    46  		{1.23456789, "%1v", "1.23456789 V"},
    47  		{1.23456789, "%#v", "unit.Voltage(1.23456789)"},
    48  		{1.23456789, "%s", "%!s(unit.Voltage=1.23456789 V)"},
    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, float64(test.value), got, test.want)
    53  		}
    54  	}
    55  }