mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 15:16:59 +08:00
unit: complete coverage of generate code
This commit is contained in:
@@ -36,7 +36,7 @@ func (a AbsorbedRadioactiveDose) AbsorbedRadioactiveDose() AbsorbedRadioactiveDo
|
|||||||
func (a *AbsorbedRadioactiveDose) From(u Uniter) error {
|
func (a *AbsorbedRadioactiveDose) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Gray) {
|
if !DimensionsMatch(u, Gray) {
|
||||||
*a = AbsorbedRadioactiveDose(math.NaN())
|
*a = AbsorbedRadioactiveDose(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*a = AbsorbedRadioactiveDose(u.Unit().Value())
|
*a = AbsorbedRadioactiveDose(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestAbsorbedRadioactiveDose(t *testing.T) {
|
|||||||
if got != AbsorbedRadioactiveDose(value) {
|
if got != AbsorbedRadioactiveDose(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.AbsorbedRadioactiveDose() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ func (a Acceleration) Acceleration() Acceleration {
|
|||||||
func (a *Acceleration) From(u Uniter) error {
|
func (a *Acceleration) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Acceleration(0)) {
|
if !DimensionsMatch(u, Acceleration(0)) {
|
||||||
*a = Acceleration(math.NaN())
|
*a = Acceleration(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*a = Acceleration(u.Unit().Value())
|
*a = Acceleration(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestAcceleration(t *testing.T) {
|
|||||||
if got != Acceleration(value) {
|
if got != Acceleration(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Acceleration() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (a Angle) Angle() Angle {
|
|||||||
func (a *Angle) From(u Uniter) error {
|
func (a *Angle) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Rad) {
|
if !DimensionsMatch(u, Rad) {
|
||||||
*a = Angle(math.NaN())
|
*a = Angle(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*a = Angle(u.Unit().Value())
|
*a = Angle(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestAngle(t *testing.T) {
|
|||||||
if got != Angle(value) {
|
if got != Angle(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Angle() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ func (a Area) Area() Area {
|
|||||||
func (a *Area) From(u Uniter) error {
|
func (a *Area) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Area(0)) {
|
if !DimensionsMatch(u, Area(0)) {
|
||||||
*a = Area(math.NaN())
|
*a = Area(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*a = Area(u.Unit().Value())
|
*a = Area(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestArea(t *testing.T) {
|
|||||||
if got != Area(value) {
|
if got != Area(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Area() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func (cp Capacitance) Capacitance() Capacitance {
|
|||||||
func (cp *Capacitance) From(u Uniter) error {
|
func (cp *Capacitance) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Farad) {
|
if !DimensionsMatch(u, Farad) {
|
||||||
*cp = Capacitance(math.NaN())
|
*cp = Capacitance(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*cp = Capacitance(u.Unit().Value())
|
*cp = Capacitance(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestCapacitance(t *testing.T) {
|
|||||||
if got != Capacitance(value) {
|
if got != Capacitance(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Capacitance() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ func (ch Charge) Charge() Charge {
|
|||||||
func (ch *Charge) From(u Uniter) error {
|
func (ch *Charge) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Coulomb) {
|
if !DimensionsMatch(u, Coulomb) {
|
||||||
*ch = Charge(math.NaN())
|
*ch = Charge(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*ch = Charge(u.Unit().Value())
|
*ch = Charge(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestCharge(t *testing.T) {
|
|||||||
if got != Charge(value) {
|
if got != Charge(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func (co Conductance) Conductance() Conductance {
|
|||||||
func (co *Conductance) From(u Uniter) error {
|
func (co *Conductance) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Siemens) {
|
if !DimensionsMatch(u, Siemens) {
|
||||||
*co = Conductance(math.NaN())
|
*co = Conductance(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*co = Conductance(u.Unit().Value())
|
*co = Conductance(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestConductance(t *testing.T) {
|
|||||||
if got != Conductance(value) {
|
if got != Conductance(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Conductance() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (i Current) Current() Current {
|
|||||||
func (i *Current) From(u Uniter) error {
|
func (i *Current) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Ampere) {
|
if !DimensionsMatch(u, Ampere) {
|
||||||
*i = Current(math.NaN())
|
*i = Current(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*i = Current(u.Unit().Value())
|
*i = Current(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestCurrent(t *testing.T) {
|
|||||||
if got != Current(value) {
|
if got != Current(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Current() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ func (d Dimless) Dimless() Dimless {
|
|||||||
func (d *Dimless) From(u Uniter) error {
|
func (d *Dimless) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Dimless(0)) {
|
if !DimensionsMatch(u, Dimless(0)) {
|
||||||
*d = Dimless(math.NaN())
|
*d = Dimless(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*d = Dimless(u.Unit().Value())
|
*d = Dimless(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestDimless(t *testing.T) {
|
|||||||
if got != Dimless(value) {
|
if got != Dimless(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Dimless() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ func (e Energy) Energy() Energy {
|
|||||||
func (e *Energy) From(u Uniter) error {
|
func (e *Energy) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Joule) {
|
if !DimensionsMatch(u, Joule) {
|
||||||
*e = Energy(math.NaN())
|
*e = Energy(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*e = Energy(u.Unit().Value())
|
*e = Energy(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestEnergy(t *testing.T) {
|
|||||||
if got != Energy(value) {
|
if got != Energy(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Energy() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ func (a EquivalentRadioactiveDose) EquivalentRadioactiveDose() EquivalentRadioac
|
|||||||
func (a *EquivalentRadioactiveDose) From(u Uniter) error {
|
func (a *EquivalentRadioactiveDose) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Sievert) {
|
if !DimensionsMatch(u, Sievert) {
|
||||||
*a = EquivalentRadioactiveDose(math.NaN())
|
*a = EquivalentRadioactiveDose(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*a = EquivalentRadioactiveDose(u.Unit().Value())
|
*a = EquivalentRadioactiveDose(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestEquivalentRadioactiveDose(t *testing.T) {
|
|||||||
if got != EquivalentRadioactiveDose(value) {
|
if got != EquivalentRadioactiveDose(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.EquivalentRadioactiveDose() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ func (f Force) Force() Force {
|
|||||||
func (f *Force) From(u Uniter) error {
|
func (f *Force) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Newton) {
|
if !DimensionsMatch(u, Newton) {
|
||||||
*f = Force(math.NaN())
|
*f = Force(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*f = Force(u.Unit().Value())
|
*f = Force(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestForce(t *testing.T) {
|
|||||||
if got != Force(value) {
|
if got != Force(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Force() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (f Frequency) Frequency() Frequency {
|
|||||||
func (f *Frequency) From(u Uniter) error {
|
func (f *Frequency) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Hertz) {
|
if !DimensionsMatch(u, Hertz) {
|
||||||
*f = Frequency(math.NaN())
|
*f = Frequency(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*f = Frequency(u.Unit().Value())
|
*f = Frequency(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestFrequency(t *testing.T) {
|
|||||||
if got != Frequency(value) {
|
if got != Frequency(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Frequency() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -487,7 +487,7 @@ func ({{.Receiver}} {{.DimensionName}}) {{.DimensionName}}() {{.DimensionName}}
|
|||||||
func ({{.Receiver}} *{{.DimensionName}}) From(u Uniter) error {
|
func ({{.Receiver}} *{{.DimensionName}}) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, {{if .Name}}{{.Name}}{{else}}{{.DimensionName}}(0){{end}}){
|
if !DimensionsMatch(u, {{if .Name}}{{.Name}}{{else}}{{.DimensionName}}(0){{end}}){
|
||||||
*{{.Receiver}} = {{.DimensionName}}(math.NaN())
|
*{{.Receiver}} = {{.DimensionName}}(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*{{.Receiver}} = {{.DimensionName}}(u.Unit().Value())
|
*{{.Receiver}} = {{.DimensionName}}(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
@@ -604,6 +604,13 @@ func Test{{.DimensionName}}(t *testing.T) {
|
|||||||
if got != {{.DimensionName}}(value) {
|
if got != {{.DimensionName}}(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.{{.DimensionName}}() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func (i Inductance) Inductance() Inductance {
|
|||||||
func (i *Inductance) From(u Uniter) error {
|
func (i *Inductance) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Henry) {
|
if !DimensionsMatch(u, Henry) {
|
||||||
*i = Inductance(math.NaN())
|
*i = Inductance(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*i = Inductance(u.Unit().Value())
|
*i = Inductance(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestInductance(t *testing.T) {
|
|||||||
if got != Inductance(value) {
|
if got != Inductance(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Inductance() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (l Length) Length() Length {
|
|||||||
func (l *Length) From(u Uniter) error {
|
func (l *Length) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Metre) {
|
if !DimensionsMatch(u, Metre) {
|
||||||
*l = Length(math.NaN())
|
*l = Length(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*l = Length(u.Unit().Value())
|
*l = Length(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestLength(t *testing.T) {
|
|||||||
if got != Length(value) {
|
if got != Length(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Length() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (j LuminousIntensity) LuminousIntensity() LuminousIntensity {
|
|||||||
func (j *LuminousIntensity) From(u Uniter) error {
|
func (j *LuminousIntensity) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Candela) {
|
if !DimensionsMatch(u, Candela) {
|
||||||
*j = LuminousIntensity(math.NaN())
|
*j = LuminousIntensity(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*j = LuminousIntensity(u.Unit().Value())
|
*j = LuminousIntensity(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestLuminousIntensity(t *testing.T) {
|
|||||||
if got != LuminousIntensity(value) {
|
if got != LuminousIntensity(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.LuminousIntensity() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func (m MagneticFlux) MagneticFlux() MagneticFlux {
|
|||||||
func (m *MagneticFlux) From(u Uniter) error {
|
func (m *MagneticFlux) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Weber) {
|
if !DimensionsMatch(u, Weber) {
|
||||||
*m = MagneticFlux(math.NaN())
|
*m = MagneticFlux(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*m = MagneticFlux(u.Unit().Value())
|
*m = MagneticFlux(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestMagneticFlux(t *testing.T) {
|
|||||||
if got != MagneticFlux(value) {
|
if got != MagneticFlux(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.MagneticFlux() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ func (m MagneticFluxDensity) MagneticFluxDensity() MagneticFluxDensity {
|
|||||||
func (m *MagneticFluxDensity) From(u Uniter) error {
|
func (m *MagneticFluxDensity) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Tesla) {
|
if !DimensionsMatch(u, Tesla) {
|
||||||
*m = MagneticFluxDensity(math.NaN())
|
*m = MagneticFluxDensity(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*m = MagneticFluxDensity(u.Unit().Value())
|
*m = MagneticFluxDensity(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestMagneticFluxDensity(t *testing.T) {
|
|||||||
if got != MagneticFluxDensity(value) {
|
if got != MagneticFluxDensity(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.MagneticFluxDensity() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,7 +39,7 @@ func (m Mass) Mass() Mass {
|
|||||||
func (m *Mass) From(u Uniter) error {
|
func (m *Mass) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Gram) {
|
if !DimensionsMatch(u, Gram) {
|
||||||
*m = Mass(math.NaN())
|
*m = Mass(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*m = Mass(u.Unit().Value())
|
*m = Mass(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestMass(t *testing.T) {
|
|||||||
if got != Mass(value) {
|
if got != Mass(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Mass() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (n Mole) Mole() Mole {
|
|||||||
func (n *Mole) From(u Uniter) error {
|
func (n *Mole) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Mol) {
|
if !DimensionsMatch(u, Mol) {
|
||||||
*n = Mole(math.NaN())
|
*n = Mole(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*n = Mole(u.Unit().Value())
|
*n = Mole(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestMole(t *testing.T) {
|
|||||||
if got != Mole(value) {
|
if got != Mole(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Mole() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ func (pw Power) Power() Power {
|
|||||||
func (pw *Power) From(u Uniter) error {
|
func (pw *Power) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Watt) {
|
if !DimensionsMatch(u, Watt) {
|
||||||
*pw = Power(math.NaN())
|
*pw = Power(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*pw = Power(u.Unit().Value())
|
*pw = Power(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestPower(t *testing.T) {
|
|||||||
if got != Power(value) {
|
if got != Power(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Power() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ func (pr Pressure) Pressure() Pressure {
|
|||||||
func (pr *Pressure) From(u Uniter) error {
|
func (pr *Pressure) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Pascal) {
|
if !DimensionsMatch(u, Pascal) {
|
||||||
*pr = Pressure(math.NaN())
|
*pr = Pressure(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*pr = Pressure(u.Unit().Value())
|
*pr = Pressure(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestPressure(t *testing.T) {
|
|||||||
if got != Pressure(value) {
|
if got != Pressure(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Pressure() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (r Radioactivity) Radioactivity() Radioactivity {
|
|||||||
func (r *Radioactivity) From(u Uniter) error {
|
func (r *Radioactivity) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Becquerel) {
|
if !DimensionsMatch(u, Becquerel) {
|
||||||
*r = Radioactivity(math.NaN())
|
*r = Radioactivity(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*r = Radioactivity(u.Unit().Value())
|
*r = Radioactivity(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestRadioactivity(t *testing.T) {
|
|||||||
if got != Radioactivity(value) {
|
if got != Radioactivity(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Radioactivity() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func (r Resistance) Resistance() Resistance {
|
|||||||
func (r *Resistance) From(u Uniter) error {
|
func (r *Resistance) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Ohm) {
|
if !DimensionsMatch(u, Ohm) {
|
||||||
*r = Resistance(math.NaN())
|
*r = Resistance(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*r = Resistance(u.Unit().Value())
|
*r = Resistance(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestResistance(t *testing.T) {
|
|||||||
if got != Resistance(value) {
|
if got != Resistance(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Resistance() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (t Temperature) Temperature() Temperature {
|
|||||||
func (t *Temperature) From(u Uniter) error {
|
func (t *Temperature) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Kelvin) {
|
if !DimensionsMatch(u, Kelvin) {
|
||||||
*t = Temperature(math.NaN())
|
*t = Temperature(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*t = Temperature(u.Unit().Value())
|
*t = Temperature(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestTemperature(t *testing.T) {
|
|||||||
if got != Temperature(value) {
|
if got != Temperature(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Temperature() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ func (t Time) Time() Time {
|
|||||||
func (t *Time) From(u Uniter) error {
|
func (t *Time) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Second) {
|
if !DimensionsMatch(u, Second) {
|
||||||
*t = Time(math.NaN())
|
*t = Time(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*t = Time(u.Unit().Value())
|
*t = Time(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestTime(t *testing.T) {
|
|||||||
if got != Time(value) {
|
if got != Time(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Time() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ func (t Torque) Torque() Torque {
|
|||||||
func (t *Torque) From(u Uniter) error {
|
func (t *Torque) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Newtonmetre) {
|
if !DimensionsMatch(u, Newtonmetre) {
|
||||||
*t = Torque(math.NaN())
|
*t = Torque(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*t = Torque(u.Unit().Value())
|
*t = Torque(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestTorque(t *testing.T) {
|
|||||||
if got != Torque(value) {
|
if got != Torque(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Torque() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ether is a non-existant unit used for testing.
|
||||||
|
type ether float64
|
||||||
|
|
||||||
|
func (e ether) Unit() *Unit {
|
||||||
|
return New(float64(e), Dimensions{reserved: 1})
|
||||||
|
}
|
||||||
|
|
||||||
var formatTests = []struct {
|
var formatTests = []struct {
|
||||||
unit Uniter
|
unit Uniter
|
||||||
format string
|
format string
|
||||||
|
@@ -34,7 +34,7 @@ func (v Velocity) Velocity() Velocity {
|
|||||||
func (v *Velocity) From(u Uniter) error {
|
func (v *Velocity) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Velocity(0)) {
|
if !DimensionsMatch(u, Velocity(0)) {
|
||||||
*v = Velocity(math.NaN())
|
*v = Velocity(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*v = Velocity(u.Unit().Value())
|
*v = Velocity(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestVelocity(t *testing.T) {
|
|||||||
if got != Velocity(value) {
|
if got != Velocity(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Velocity() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func (v Voltage) Voltage() Voltage {
|
|||||||
func (v *Voltage) From(u Uniter) error {
|
func (v *Voltage) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Volt) {
|
if !DimensionsMatch(u, Volt) {
|
||||||
*v = Voltage(math.NaN())
|
*v = Voltage(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*v = Voltage(u.Unit().Value())
|
*v = Voltage(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestVoltage(t *testing.T) {
|
|||||||
if got != Voltage(value) {
|
if got != Voltage(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
||||||
}
|
}
|
||||||
|
if got != got.Voltage() {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func (v Volume) Volume() Volume {
|
|||||||
func (v *Volume) From(u Uniter) error {
|
func (v *Volume) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Litre) {
|
if !DimensionsMatch(u, Litre) {
|
||||||
*v = Volume(math.NaN())
|
*v = Volume(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("unit: dimension mismatch")
|
||||||
}
|
}
|
||||||
*v = Volume(u.Unit().Value())
|
*v = Volume(u.Unit().Value())
|
||||||
return nil
|
return nil
|
||||||
|
@@ -21,6 +21,13 @@ func TestVolume(t *testing.T) {
|
|||||||
if got != Volume(value) {
|
if got != Volume(value) {
|
||||||
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(value), got, value)
|
t.Errorf("unexpected result from round trip of %T(%v): got: %v want: %v", got, float64(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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user