static void Main(string[] args) { Quantity q = new Quantity(1, Unit.None); Console.WriteLine(q); Console.WriteLine(); Console.WriteLine("Press ENTER to end."); Console.ReadLine(); }
public void AdditionTest() { Quantity q1 = new Quantity(1, SIUnit.MassUnits.kg); Quantity q2 = new Quantity(2, SIUnit.MassUnits.kg); Assert.AreEqual(new Quantity(3, SIUnit.MassUnits.kg), q1 + q2); Assert.AreEqual(new Quantity(3, SIUnit.MassUnits.kg), q2 + q1); Quantity q3 = new Quantity(1000, SIUnit.MassUnits.g); Assert.AreEqual(new Quantity(2, SIUnit.MassUnits.kg), q1+q3); Assert.AreEqual(new Quantity(2, SIUnit.MassUnits.kg), q3+q1); }
public void SubtractionTest() { Unit u = new Unit("kilogram", "kg", SIUnit.SIUnitTypes.Mass); Quantity q1 = new Quantity(1, u); Quantity q2 = new Quantity(2, u); Assert.AreEqual(q1, q2 - q1); Unit g = new Unit("gram", "g", u/1000); Quantity q3 = new Quantity(1000, g); Assert.AreEqual(q1, q2 - q3); }
public void MultiplicationTest() { Quantity q1 = new Quantity(1, SIUnit.MassUnits.kg); Assert.AreEqual(new Quantity(123, SIUnit.MassUnits.kg), 123 * q1); Assert.AreEqual(new Quantity(123, SIUnit.MassUnits.kg), q1 * 123); Quantity q2 = new Quantity(10, SIUnit.MassUnits.kg); Assert.AreEqual(new Quantity(10, SIUnit.MassUnits.kg * SIUnit.MassUnits.kg), q1 * q2); Assert.AreEqual(new Quantity(10, SIUnit.MassUnits.kg * SIUnit.MassUnits.kg), q2 * q1); Quantity q3 = new Quantity(1000, SIUnit.MassUnits.g); Assert.AreEqual(new Quantity(1000, SIUnit.MassUnits.kg * SIUnit.MassUnits.g), q1 * q3); Assert.AreEqual(new Quantity(1000, SIUnit.MassUnits.g * SIUnit.MassUnits.kg), q3 * q1); }
public void EqualityTest() { Quantity q = new Quantity(1, Unit.None); Assert.AreEqual(q, q); Quantity q1 = new Quantity(1, Unit.None); Assert.AreEqual(q, q1); Quantity q2 = new Quantity(12, Unit.None); Assert.AreNotEqual(q, q2); Quantity kg = new Quantity(1, SIUnit.MassUnits.kg); Quantity g = new Quantity(1000, SIUnit.MassUnits.g); Assert.AreEqual(kg, g); }
public static Quantity Convert(Quantity quantity, Unit toUnit) { try { if (Object.ReferenceEquals(quantity.Unit, toUnit)) { return quantity; } if (quantity.Unit.IsCompatibleTo(toUnit)) { return new Quantity(quantity.Amount * quantity.Unit.Factor / toUnit.Factor, toUnit); } else { throw new NotImplementedException(); } } catch { throw new NotImplementedException(); } }
public bool Equals(Quantity quantity) { return (this == quantity); }