mirror of
https://github.com/gonum/gonum.git
synced 2025-09-27 03:26:04 +08:00

Ruleguard run with ruleguard -c=0 -rules ruleguard.rules.go ./... from https://github.com/dgryski/semgrep-go with the following rules inactivated to reduce noise: - unconvert for floating point values - oddcomparisons - floateq
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// Code generated by "go generate gonum.org/v1/gonum/unit; DO NOT EDIT.
|
|
|
|
// Copyright ©2019 The Gonum Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package unit
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestVolume(t *testing.T) {
|
|
t.Parallel()
|
|
for _, value := range []float64{-1, 0, 1} {
|
|
var got Volume
|
|
err := got.From(Volume(value).Unit())
|
|
if err != nil {
|
|
t.Errorf("unexpected error for %T conversion: %v", got, err)
|
|
}
|
|
if got != Volume(value) {
|
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, value, got, value)
|
|
}
|
|
if got != got.Volume() {
|
|
t.Errorf("unexpected result from self interface method call: got: %#v want: %#v", got, value)
|
|
}
|
|
err = got.From(ether(1))
|
|
if err == nil {
|
|
t.Errorf("expected error for ether to %T conversion", got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestVolumeFormat(t *testing.T) {
|
|
t.Parallel()
|
|
for _, test := range []struct {
|
|
value Volume
|
|
format string
|
|
want string
|
|
}{
|
|
{1.23456789, "%v", "1.23456789 m^3"},
|
|
{1.23456789, "%.1v", "1 m^3"},
|
|
{1.23456789, "%20.1v", " 1 m^3"},
|
|
{1.23456789, "%20v", " 1.23456789 m^3"},
|
|
{1.23456789, "%1v", "1.23456789 m^3"},
|
|
{1.23456789, "%#v", "unit.Volume(1.23456789)"},
|
|
{1.23456789, "%s", "%!s(unit.Volume=1.23456789 m^3)"},
|
|
} {
|
|
got := fmt.Sprintf(test.format, test.value)
|
|
if got != test.want {
|
|
t.Errorf("Format %q %v: got: %q want: %q", test.format, test.value, got, test.want)
|
|
}
|
|
}
|
|
}
|