# units / units_test.go

 ``` 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 56 57 58``` ```package units import ( "testing" ) var valueEquivTable = []struct { a Value b Value }{ {Value{2, Watt}, Value{2, Watt}}, {Value{2, Watt}, Value{6, Joule}.Div(Value{3, Second})}, {Value{10, Volt}, Value{2, Ampere}.Mul(Value{5, Ohm})}, {Value{7, Pascal}, Value{2, Pascal}.Add(Value{5, Pascal})}, } func TestValueMath(t *testing.T) { for i, equiv := range valueEquivTable { if equiv.a != equiv.b { t.Errorf("%s and %s not equal (case %d).", equiv.a, equiv.b, i) } } } var fmtEquivTable = []struct { a string b interface { String() string } }{ {"m/s", Meter.per(Second)}, {"K", Kelvin}, {"kg*m/s/s", Newton}, {"kg/s/s/A", Tesla}, {"", Unitless}, {"4W", Value{4, Watt}}, {"123T", Value{123, Tesla}}, {"3.1m/s", Value{3.1, Meter.per(Second)}}, {"1200kg*s", Value{1200, Kilogram.times(Second)}}, {"1.21GW", Value{1.21e9, Watt}}, {"20mm", Value{.02, Meter}}, {"200ns", Value{200e-9, Second}}, {"25mg", Value{25e-6, Kilogram}}, {"4L", Value{.004, Kiloliter}}, {"1e+36YJ", Value{1e60, Joule}}, {"1e-36yJ", Value{1e-60, Joule}}, {"0W", Value{0, Watt}}, } func TestFmt(t *testing.T) { for i, equiv := range fmtEquivTable { if equiv.a != equiv.b.String() { t.Errorf("%q and %q not equal (case %d).", equiv.a, equiv.b, i) } } } ```