File: charge_test.go

package info (click to toggle)
golang-gonum-v1-gonum 0.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,792 kB
  • sloc: asm: 6,252; fortran: 5,271; sh: 377; ruby: 211; makefile: 98
file content (55 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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 TestCharge(t *testing.T) {
	t.Parallel()
	for _, value := range []float64{-1, 0, 1} {
		var got Charge
		err := got.From(Charge(value).Unit())
		if err != nil {
			t.Errorf("unexpected error for %T conversion: %v", got, err)
		}
		if got != Charge(value) {
			t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, value, got, value)
		}
		if got != got.Charge() {
			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 TestChargeFormat(t *testing.T) {
	t.Parallel()
	for _, test := range []struct {
		value  Charge
		format string
		want   string
	}{
		{1.23456789, "%v", "1.23456789 C"},
		{1.23456789, "%.1v", "1 C"},
		{1.23456789, "%20.1v", "                 1 C"},
		{1.23456789, "%20v", "        1.23456789 C"},
		{1.23456789, "%1v", "1.23456789 C"},
		{1.23456789, "%#v", "unit.Charge(1.23456789)"},
		{1.23456789, "%s", "%!s(unit.Charge=1.23456789 C)"},
	} {
		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)
		}
	}
}