diff --git a/unit/absorbedradioactivedose.go b/unit/absorbedradioactivedose.go index 9222faa6..feae9e4f 100644 --- a/unit/absorbedradioactivedose.go +++ b/unit/absorbedradioactivedose.go @@ -36,7 +36,7 @@ func (a AbsorbedRadioactiveDose) AbsorbedRadioactiveDose() AbsorbedRadioactiveDo func (a *AbsorbedRadioactiveDose) From(u Uniter) error { if !DimensionsMatch(u, Gray) { *a = AbsorbedRadioactiveDose(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *a = AbsorbedRadioactiveDose(u.Unit().Value()) return nil diff --git a/unit/absorbedradioactivedose_test.go b/unit/absorbedradioactivedose_test.go index 1688127a..2d3666b6 100644 --- a/unit/absorbedradioactivedose_test.go +++ b/unit/absorbedradioactivedose_test.go @@ -21,6 +21,13 @@ func TestAbsorbedRadioactiveDose(t *testing.T) { if got != AbsorbedRadioactiveDose(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) + } } } diff --git a/unit/acceleration.go b/unit/acceleration.go index 88aad8ce..7dfbfa81 100644 --- a/unit/acceleration.go +++ b/unit/acceleration.go @@ -34,7 +34,7 @@ func (a Acceleration) Acceleration() Acceleration { func (a *Acceleration) From(u Uniter) error { if !DimensionsMatch(u, Acceleration(0)) { *a = Acceleration(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *a = Acceleration(u.Unit().Value()) return nil diff --git a/unit/acceleration_test.go b/unit/acceleration_test.go index 031a037d..78263d2d 100644 --- a/unit/acceleration_test.go +++ b/unit/acceleration_test.go @@ -21,6 +21,13 @@ func TestAcceleration(t *testing.T) { if got != Acceleration(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) + } } } diff --git a/unit/angle.go b/unit/angle.go index be328aa6..0fbdd8e4 100644 --- a/unit/angle.go +++ b/unit/angle.go @@ -35,7 +35,7 @@ func (a Angle) Angle() Angle { func (a *Angle) From(u Uniter) error { if !DimensionsMatch(u, Rad) { *a = Angle(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *a = Angle(u.Unit().Value()) return nil diff --git a/unit/angle_test.go b/unit/angle_test.go index 9e4d7f6c..082f74eb 100644 --- a/unit/angle_test.go +++ b/unit/angle_test.go @@ -21,6 +21,13 @@ func TestAngle(t *testing.T) { if got != Angle(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) + } } } diff --git a/unit/area.go b/unit/area.go index 10d920fc..ab46a0b8 100644 --- a/unit/area.go +++ b/unit/area.go @@ -33,7 +33,7 @@ func (a Area) Area() Area { func (a *Area) From(u Uniter) error { if !DimensionsMatch(u, Area(0)) { *a = Area(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *a = Area(u.Unit().Value()) return nil diff --git a/unit/area_test.go b/unit/area_test.go index 0607a1ad..92a7133e 100644 --- a/unit/area_test.go +++ b/unit/area_test.go @@ -21,6 +21,13 @@ func TestArea(t *testing.T) { if got != Area(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) + } } } diff --git a/unit/capacitance.go b/unit/capacitance.go index 25f32db9..25211a62 100644 --- a/unit/capacitance.go +++ b/unit/capacitance.go @@ -38,7 +38,7 @@ func (cp Capacitance) Capacitance() Capacitance { func (cp *Capacitance) From(u Uniter) error { if !DimensionsMatch(u, Farad) { *cp = Capacitance(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *cp = Capacitance(u.Unit().Value()) return nil diff --git a/unit/capacitance_test.go b/unit/capacitance_test.go index 5429c1bd..a8561e34 100644 --- a/unit/capacitance_test.go +++ b/unit/capacitance_test.go @@ -21,6 +21,13 @@ func TestCapacitance(t *testing.T) { if got != Capacitance(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) + } } } diff --git a/unit/charge.go b/unit/charge.go index 47073d53..57a7638a 100644 --- a/unit/charge.go +++ b/unit/charge.go @@ -36,7 +36,7 @@ func (ch Charge) Charge() Charge { func (ch *Charge) From(u Uniter) error { if !DimensionsMatch(u, Coulomb) { *ch = Charge(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *ch = Charge(u.Unit().Value()) return nil diff --git a/unit/charge_test.go b/unit/charge_test.go index 285d2ea5..7db62266 100644 --- a/unit/charge_test.go +++ b/unit/charge_test.go @@ -21,6 +21,13 @@ func TestCharge(t *testing.T) { if got != Charge(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) + } } } diff --git a/unit/conductance.go b/unit/conductance.go index c5c4f496..e82adcce 100644 --- a/unit/conductance.go +++ b/unit/conductance.go @@ -38,7 +38,7 @@ func (co Conductance) Conductance() Conductance { func (co *Conductance) From(u Uniter) error { if !DimensionsMatch(u, Siemens) { *co = Conductance(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *co = Conductance(u.Unit().Value()) return nil diff --git a/unit/conductance_test.go b/unit/conductance_test.go index 5bed713d..1c9e014f 100644 --- a/unit/conductance_test.go +++ b/unit/conductance_test.go @@ -21,6 +21,13 @@ func TestConductance(t *testing.T) { if got != Conductance(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) + } } } diff --git a/unit/current.go b/unit/current.go index 48f6eaae..61887072 100644 --- a/unit/current.go +++ b/unit/current.go @@ -35,7 +35,7 @@ func (i Current) Current() Current { func (i *Current) From(u Uniter) error { if !DimensionsMatch(u, Ampere) { *i = Current(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *i = Current(u.Unit().Value()) return nil diff --git a/unit/current_test.go b/unit/current_test.go index d457cbdf..fab97676 100644 --- a/unit/current_test.go +++ b/unit/current_test.go @@ -21,6 +21,13 @@ func TestCurrent(t *testing.T) { if got != Current(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) + } } } diff --git a/unit/dimless.go b/unit/dimless.go index 71c2317e..54013278 100644 --- a/unit/dimless.go +++ b/unit/dimless.go @@ -30,7 +30,7 @@ func (d Dimless) Dimless() Dimless { func (d *Dimless) From(u Uniter) error { if !DimensionsMatch(u, Dimless(0)) { *d = Dimless(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *d = Dimless(u.Unit().Value()) return nil diff --git a/unit/dimless_test.go b/unit/dimless_test.go index f5a3631c..675b98f7 100644 --- a/unit/dimless_test.go +++ b/unit/dimless_test.go @@ -21,6 +21,13 @@ func TestDimless(t *testing.T) { if got != Dimless(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) + } } } diff --git a/unit/energy.go b/unit/energy.go index 059d2b0e..ada407e7 100644 --- a/unit/energy.go +++ b/unit/energy.go @@ -37,7 +37,7 @@ func (e Energy) Energy() Energy { func (e *Energy) From(u Uniter) error { if !DimensionsMatch(u, Joule) { *e = Energy(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *e = Energy(u.Unit().Value()) return nil diff --git a/unit/energy_test.go b/unit/energy_test.go index afef5c4b..52062824 100644 --- a/unit/energy_test.go +++ b/unit/energy_test.go @@ -21,6 +21,13 @@ func TestEnergy(t *testing.T) { if got != Energy(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) + } } } diff --git a/unit/equivalentradioactivedose.go b/unit/equivalentradioactivedose.go index 67020fd0..51d64062 100644 --- a/unit/equivalentradioactivedose.go +++ b/unit/equivalentradioactivedose.go @@ -36,7 +36,7 @@ func (a EquivalentRadioactiveDose) EquivalentRadioactiveDose() EquivalentRadioac func (a *EquivalentRadioactiveDose) From(u Uniter) error { if !DimensionsMatch(u, Sievert) { *a = EquivalentRadioactiveDose(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *a = EquivalentRadioactiveDose(u.Unit().Value()) return nil diff --git a/unit/equivalentradioactivedose_test.go b/unit/equivalentradioactivedose_test.go index 4967640f..7a6571fb 100644 --- a/unit/equivalentradioactivedose_test.go +++ b/unit/equivalentradioactivedose_test.go @@ -21,6 +21,13 @@ func TestEquivalentRadioactiveDose(t *testing.T) { if got != EquivalentRadioactiveDose(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) + } } } diff --git a/unit/force.go b/unit/force.go index ea5b230b..caa76b83 100644 --- a/unit/force.go +++ b/unit/force.go @@ -37,7 +37,7 @@ func (f Force) Force() Force { func (f *Force) From(u Uniter) error { if !DimensionsMatch(u, Newton) { *f = Force(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *f = Force(u.Unit().Value()) return nil diff --git a/unit/force_test.go b/unit/force_test.go index 01580e28..58ab409f 100644 --- a/unit/force_test.go +++ b/unit/force_test.go @@ -21,6 +21,13 @@ func TestForce(t *testing.T) { if got != Force(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) + } } } diff --git a/unit/frequency.go b/unit/frequency.go index 1708c7ac..56555038 100644 --- a/unit/frequency.go +++ b/unit/frequency.go @@ -35,7 +35,7 @@ func (f Frequency) Frequency() Frequency { func (f *Frequency) From(u Uniter) error { if !DimensionsMatch(u, Hertz) { *f = Frequency(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *f = Frequency(u.Unit().Value()) return nil diff --git a/unit/frequency_test.go b/unit/frequency_test.go index a312554e..7a5b68d4 100644 --- a/unit/frequency_test.go +++ b/unit/frequency_test.go @@ -21,6 +21,13 @@ func TestFrequency(t *testing.T) { if got != Frequency(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) + } } } diff --git a/unit/generate_unit.go b/unit/generate_unit.go index f0bbe149..7a131511 100644 --- a/unit/generate_unit.go +++ b/unit/generate_unit.go @@ -487,7 +487,7 @@ func ({{.Receiver}} {{.DimensionName}}) {{.DimensionName}}() {{.DimensionName}} func ({{.Receiver}} *{{.DimensionName}}) From(u Uniter) error { if !DimensionsMatch(u, {{if .Name}}{{.Name}}{{else}}{{.DimensionName}}(0){{end}}){ *{{.Receiver}} = {{.DimensionName}}(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *{{.Receiver}} = {{.DimensionName}}(u.Unit().Value()) return nil @@ -604,6 +604,13 @@ func Test{{.DimensionName}}(t *testing.T) { if got != {{.DimensionName}}(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) + } } } diff --git a/unit/inductance.go b/unit/inductance.go index d992bff2..0bc81943 100644 --- a/unit/inductance.go +++ b/unit/inductance.go @@ -38,7 +38,7 @@ func (i Inductance) Inductance() Inductance { func (i *Inductance) From(u Uniter) error { if !DimensionsMatch(u, Henry) { *i = Inductance(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *i = Inductance(u.Unit().Value()) return nil diff --git a/unit/inductance_test.go b/unit/inductance_test.go index 1dca8de5..fa139625 100644 --- a/unit/inductance_test.go +++ b/unit/inductance_test.go @@ -21,6 +21,13 @@ func TestInductance(t *testing.T) { if got != Inductance(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) + } } } diff --git a/unit/length.go b/unit/length.go index 066d3bb7..c989527b 100644 --- a/unit/length.go +++ b/unit/length.go @@ -35,7 +35,7 @@ func (l Length) Length() Length { func (l *Length) From(u Uniter) error { if !DimensionsMatch(u, Metre) { *l = Length(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *l = Length(u.Unit().Value()) return nil diff --git a/unit/length_test.go b/unit/length_test.go index 30d64998..1bc88c63 100644 --- a/unit/length_test.go +++ b/unit/length_test.go @@ -21,6 +21,13 @@ func TestLength(t *testing.T) { if got != Length(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) + } } } diff --git a/unit/luminousintensity.go b/unit/luminousintensity.go index 95a3e653..d57ce3b8 100644 --- a/unit/luminousintensity.go +++ b/unit/luminousintensity.go @@ -35,7 +35,7 @@ func (j LuminousIntensity) LuminousIntensity() LuminousIntensity { func (j *LuminousIntensity) From(u Uniter) error { if !DimensionsMatch(u, Candela) { *j = LuminousIntensity(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *j = LuminousIntensity(u.Unit().Value()) return nil diff --git a/unit/luminousintensity_test.go b/unit/luminousintensity_test.go index 8bcba3f6..d0795369 100644 --- a/unit/luminousintensity_test.go +++ b/unit/luminousintensity_test.go @@ -21,6 +21,13 @@ func TestLuminousIntensity(t *testing.T) { if got != LuminousIntensity(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) + } } } diff --git a/unit/magneticflux.go b/unit/magneticflux.go index 7be21c6c..3f6e20c9 100644 --- a/unit/magneticflux.go +++ b/unit/magneticflux.go @@ -38,7 +38,7 @@ func (m MagneticFlux) MagneticFlux() MagneticFlux { func (m *MagneticFlux) From(u Uniter) error { if !DimensionsMatch(u, Weber) { *m = MagneticFlux(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *m = MagneticFlux(u.Unit().Value()) return nil diff --git a/unit/magneticflux_test.go b/unit/magneticflux_test.go index e27cf5b5..13319d15 100644 --- a/unit/magneticflux_test.go +++ b/unit/magneticflux_test.go @@ -21,6 +21,13 @@ func TestMagneticFlux(t *testing.T) { if got != MagneticFlux(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) + } } } diff --git a/unit/magneticfluxdensity.go b/unit/magneticfluxdensity.go index ec6abe39..247ea2a8 100644 --- a/unit/magneticfluxdensity.go +++ b/unit/magneticfluxdensity.go @@ -37,7 +37,7 @@ func (m MagneticFluxDensity) MagneticFluxDensity() MagneticFluxDensity { func (m *MagneticFluxDensity) From(u Uniter) error { if !DimensionsMatch(u, Tesla) { *m = MagneticFluxDensity(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *m = MagneticFluxDensity(u.Unit().Value()) return nil diff --git a/unit/magneticfluxdensity_test.go b/unit/magneticfluxdensity_test.go index aa8c6cf8..cccd012a 100644 --- a/unit/magneticfluxdensity_test.go +++ b/unit/magneticfluxdensity_test.go @@ -21,6 +21,13 @@ func TestMagneticFluxDensity(t *testing.T) { if got != MagneticFluxDensity(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) + } } } diff --git a/unit/mass.go b/unit/mass.go index df9a6437..0645ac1e 100644 --- a/unit/mass.go +++ b/unit/mass.go @@ -39,7 +39,7 @@ func (m Mass) Mass() Mass { func (m *Mass) From(u Uniter) error { if !DimensionsMatch(u, Gram) { *m = Mass(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *m = Mass(u.Unit().Value()) return nil diff --git a/unit/mass_test.go b/unit/mass_test.go index c22f7526..0f5cf841 100644 --- a/unit/mass_test.go +++ b/unit/mass_test.go @@ -21,6 +21,13 @@ func TestMass(t *testing.T) { if got != Mass(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) + } } } diff --git a/unit/mole.go b/unit/mole.go index 81f5d2d7..ad201094 100644 --- a/unit/mole.go +++ b/unit/mole.go @@ -35,7 +35,7 @@ func (n Mole) Mole() Mole { func (n *Mole) From(u Uniter) error { if !DimensionsMatch(u, Mol) { *n = Mole(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *n = Mole(u.Unit().Value()) return nil diff --git a/unit/mole_test.go b/unit/mole_test.go index a6bb012b..c5422e1c 100644 --- a/unit/mole_test.go +++ b/unit/mole_test.go @@ -21,6 +21,13 @@ func TestMole(t *testing.T) { if got != Mole(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) + } } } diff --git a/unit/power.go b/unit/power.go index 0c3784a7..f3f63880 100644 --- a/unit/power.go +++ b/unit/power.go @@ -37,7 +37,7 @@ func (pw Power) Power() Power { func (pw *Power) From(u Uniter) error { if !DimensionsMatch(u, Watt) { *pw = Power(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *pw = Power(u.Unit().Value()) return nil diff --git a/unit/power_test.go b/unit/power_test.go index 49d07c21..2cc16a90 100644 --- a/unit/power_test.go +++ b/unit/power_test.go @@ -21,6 +21,13 @@ func TestPower(t *testing.T) { if got != Power(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) + } } } diff --git a/unit/pressure.go b/unit/pressure.go index f2aa708e..eddb3dc9 100644 --- a/unit/pressure.go +++ b/unit/pressure.go @@ -37,7 +37,7 @@ func (pr Pressure) Pressure() Pressure { func (pr *Pressure) From(u Uniter) error { if !DimensionsMatch(u, Pascal) { *pr = Pressure(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *pr = Pressure(u.Unit().Value()) return nil diff --git a/unit/pressure_test.go b/unit/pressure_test.go index 9da4cc51..65624602 100644 --- a/unit/pressure_test.go +++ b/unit/pressure_test.go @@ -21,6 +21,13 @@ func TestPressure(t *testing.T) { if got != Pressure(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) + } } } diff --git a/unit/radioactivity.go b/unit/radioactivity.go index 5fd06edd..626aa85d 100644 --- a/unit/radioactivity.go +++ b/unit/radioactivity.go @@ -35,7 +35,7 @@ func (r Radioactivity) Radioactivity() Radioactivity { func (r *Radioactivity) From(u Uniter) error { if !DimensionsMatch(u, Becquerel) { *r = Radioactivity(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *r = Radioactivity(u.Unit().Value()) return nil diff --git a/unit/radioactivity_test.go b/unit/radioactivity_test.go index d40b9671..15b6ffbd 100644 --- a/unit/radioactivity_test.go +++ b/unit/radioactivity_test.go @@ -21,6 +21,13 @@ func TestRadioactivity(t *testing.T) { if got != Radioactivity(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) + } } } diff --git a/unit/resistance.go b/unit/resistance.go index 42abae28..139633b6 100644 --- a/unit/resistance.go +++ b/unit/resistance.go @@ -38,7 +38,7 @@ func (r Resistance) Resistance() Resistance { func (r *Resistance) From(u Uniter) error { if !DimensionsMatch(u, Ohm) { *r = Resistance(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *r = Resistance(u.Unit().Value()) return nil diff --git a/unit/resistance_test.go b/unit/resistance_test.go index 0e01d29c..c1eaae23 100644 --- a/unit/resistance_test.go +++ b/unit/resistance_test.go @@ -21,6 +21,13 @@ func TestResistance(t *testing.T) { if got != Resistance(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) + } } } diff --git a/unit/temperature.go b/unit/temperature.go index 017ddd49..f5c1d84a 100644 --- a/unit/temperature.go +++ b/unit/temperature.go @@ -35,7 +35,7 @@ func (t Temperature) Temperature() Temperature { func (t *Temperature) From(u Uniter) error { if !DimensionsMatch(u, Kelvin) { *t = Temperature(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *t = Temperature(u.Unit().Value()) return nil diff --git a/unit/temperature_test.go b/unit/temperature_test.go index c7000077..40d90c20 100644 --- a/unit/temperature_test.go +++ b/unit/temperature_test.go @@ -21,6 +21,13 @@ func TestTemperature(t *testing.T) { if got != Temperature(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) + } } } diff --git a/unit/time.go b/unit/time.go index c0adf539..bd6f2e01 100644 --- a/unit/time.go +++ b/unit/time.go @@ -40,7 +40,7 @@ func (t Time) Time() Time { func (t *Time) From(u Uniter) error { if !DimensionsMatch(u, Second) { *t = Time(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *t = Time(u.Unit().Value()) return nil diff --git a/unit/time_test.go b/unit/time_test.go index 474db456..988981fe 100644 --- a/unit/time_test.go +++ b/unit/time_test.go @@ -21,6 +21,13 @@ func TestTime(t *testing.T) { if got != Time(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) + } } } diff --git a/unit/torque.go b/unit/torque.go index 1717e6e9..49d3c994 100644 --- a/unit/torque.go +++ b/unit/torque.go @@ -37,7 +37,7 @@ func (t Torque) Torque() Torque { func (t *Torque) From(u Uniter) error { if !DimensionsMatch(u, Newtonmetre) { *t = Torque(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *t = Torque(u.Unit().Value()) return nil diff --git a/unit/torque_test.go b/unit/torque_test.go index 3f25b1b3..fb431ab3 100644 --- a/unit/torque_test.go +++ b/unit/torque_test.go @@ -21,6 +21,13 @@ func TestTorque(t *testing.T) { if got != Torque(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) + } } } diff --git a/unit/unit_test.go b/unit/unit_test.go index 7f001fcd..516df4f7 100644 --- a/unit/unit_test.go +++ b/unit/unit_test.go @@ -10,6 +10,13 @@ import ( "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 { unit Uniter format string diff --git a/unit/velocity.go b/unit/velocity.go index ef636135..62e2e227 100644 --- a/unit/velocity.go +++ b/unit/velocity.go @@ -34,7 +34,7 @@ func (v Velocity) Velocity() Velocity { func (v *Velocity) From(u Uniter) error { if !DimensionsMatch(u, Velocity(0)) { *v = Velocity(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *v = Velocity(u.Unit().Value()) return nil diff --git a/unit/velocity_test.go b/unit/velocity_test.go index 7c3c47db..7bf94f00 100644 --- a/unit/velocity_test.go +++ b/unit/velocity_test.go @@ -21,6 +21,13 @@ func TestVelocity(t *testing.T) { if got != Velocity(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) + } } } diff --git a/unit/voltage.go b/unit/voltage.go index 4336cb8d..079062f5 100644 --- a/unit/voltage.go +++ b/unit/voltage.go @@ -38,7 +38,7 @@ func (v Voltage) Voltage() Voltage { func (v *Voltage) From(u Uniter) error { if !DimensionsMatch(u, Volt) { *v = Voltage(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *v = Voltage(u.Unit().Value()) return nil diff --git a/unit/voltage_test.go b/unit/voltage_test.go index 322e03b2..2d520471 100644 --- a/unit/voltage_test.go +++ b/unit/voltage_test.go @@ -21,6 +21,13 @@ func TestVoltage(t *testing.T) { if got != Voltage(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) + } } } diff --git a/unit/volume.go b/unit/volume.go index 32d70c19..20c65fb6 100644 --- a/unit/volume.go +++ b/unit/volume.go @@ -35,7 +35,7 @@ func (v Volume) Volume() Volume { func (v *Volume) From(u Uniter) error { if !DimensionsMatch(u, Litre) { *v = Volume(math.NaN()) - return errors.New("Dimension mismatch") + return errors.New("unit: dimension mismatch") } *v = Volume(u.Unit().Value()) return nil diff --git a/unit/volume_test.go b/unit/volume_test.go index 37c25979..88b141e4 100644 --- a/unit/volume_test.go +++ b/unit/volume_test.go @@ -21,6 +21,13 @@ func TestVolume(t *testing.T) { if got != Volume(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) + } } }