/// <summary> /// Contruct a Measurement /// </summary> /// <param name="q">The (howevermany)s of (whatever)s we have</param> /// <param name="u">The (whatever)s we have (howevermany)s of</param> public Measurement(decimal q, string u) { var siUnits = new InternationalSystem(); Quantity = q; Exponent = siUnits.Exponent(u); BaseUnit = siUnits.BaseUnit(u); }
public void ShouldConvertInternationalSystemUnitsToBaseUnit( [Values("YV", "ZV", "EV", "PV", "TV", "GV", "MV", "kV", "hV", "daV", "V", "dV", "cV", "mV", "µV", "nV", "pV", "fV", "aV", "zV", "yV")] string units) { var siUnits = new InternationalSystem(); Assert.That(siUnits.BaseUnit(units), Is.EqualTo("V")); }
public void ShouldConvertExponentToInternationalSystemPrefix( [Values("Y", "Z", "E", "P", "T", "G", "M", "k", "h", "da", "", "d", "c", "m", "µ", "n", "p", "f", "a", "z", "y")] string prefix, [Values(24, 21, 18, 15, 12, 9, 6, 3, 2, 1, 0, -1, -2, -3, -6, -9, -12, -15, -18, -21, -24)] int exponent) { var siUnits = new InternationalSystem(); Assert.That(siUnits.ToPrefix(exponent), Is.EqualTo(prefix)); }
public void ShouldConvertInternationalSystemUnitsToExponent( [Values("YV", "ZV", "EV", "PV", "TV", "GV", "MV", "kV", "hV", "daV", "V", "dV", "cV", "mV", "µV", "nV", "pV", "fV", "aV", "zV", "yV")] string units, [Values(24, 21, 18, 15, 12, 9, 6, 3, 2, 1, 0, -1, -2, -3, -6, -9, -12, -15, -18, -21, -24)] int exponent) { var siUnits = new InternationalSystem(); Assert.That(siUnits.Exponent(units), Is.EqualTo(exponent)); }
public void ShouldHandleScalingInBaseUnitIdentityConversion( [Values(-3, -2, -1, 0, 1, 2, 3)] int toExp, [Values(-3, -2, -1, 0, 1, 2, 3)] int fromExp) { var q = 1.5m; var m = new Measurement(q, fromExp, "B"); var siUnits = new InternationalSystem(); Assert.That(Converters.Convert(m, string.Format("{0}{1}", siUnits.ToPrefix(toExp), "B")), Is.EqualTo(new Measurement(q * (decimal)Math.Pow(10, fromExp - toExp), toExp, "B"))); }