public void CheckSimple() { CompositeUnit u = new CompositeUnit(Unit.Meters); Assert.IsTrue(u.IsSimple); u._components.Add(Unit.Seconds, -1); Assert.IsFalse(u.IsSimple); }
public void ReduceToCoeff() { CompositeUnit u = new CompositeUnit(new CompositeUnit(Unit.DegreesC), Unit.Meters, -1); CompositeUnit uu = u * u.Inverse(); Assert.AreEqual(Unit.None, uu.TryReduceToSimple()); }
public void EqualSimple() { CompositeUnit u1 = new CompositeUnit(Unit.Seconds); CompositeUnit u2 = new CompositeUnit(Unit.Seconds); Assert.AreEqual(u1, u2); }
public void DivideComposite() { CompositeUnit u1 = new CompositeUnit(new CompositeUnit(new CompositeUnit(Unit.Kilograms), Unit.Meters, -1), Unit.Seconds, -2); CompositeUnit u2 = new CompositeUnit(new CompositeUnit(Unit.Seconds), Unit.DegreesC, -1); Assert.AreEqual(new CompositeUnit(new CompositeUnit(new CompositeUnit(new CompositeUnit(Unit.Kilograms), Unit.Meters, -1), Unit.Seconds, -3), Unit.DegreesC, 1), u1 / u2); }
public override bool Equals(object obj) { if (!(obj is CompositeUnit)) { return(false); } CompositeUnit cu = (CompositeUnit)obj; if (cu._components.Count != this._components.Count) { return(false); } foreach (Unit el in _components.Keys) { if (!cu._components.ContainsKey(el)) { return(false); } if (cu._components[el] != this._components[el]) { return(false); } } return(true); }
public void MultiplyComposite() { CompositeUnit u1 = new CompositeUnit(new CompositeUnit(new CompositeUnit(Unit.Kilograms), Unit.Meters, -1), Unit.Seconds, -2); CompositeUnit u2 = new CompositeUnit(new CompositeUnit(Unit.Seconds), Unit.DegreesC, -1); Assert.AreEqual(new CompositeUnit(new CompositeUnit(new CompositeUnit(new CompositeUnit(Unit.Kilograms), Unit.Meters, -1), Unit.Seconds, -1), Unit.DegreesC, -1), u1 * u2); CompositeUnit u3 = new CompositeUnit(new CompositeUnit(Unit.Seconds, 2), Unit.Meters, -1); Assert.AreEqual(new CompositeUnit(new CompositeUnit(Unit.Kilograms), Unit.Meters, -2), u3 * u1); }
public void MultiplySimple() { CompositeUnit u1 = new CompositeUnit(Unit.Meters); CompositeUnit u2 = new CompositeUnit(Unit.Seconds); CompositeUnit u = u1 * u2; Assert.AreEqual(new CompositeUnit(new CompositeUnit(Unit.Meters), Unit.Seconds, 1), u); Assert.AreEqual(new CompositeUnit(new CompositeUnit(Unit.Meters), Unit.Seconds, 2), u * u2); Assert.AreEqual(new CompositeUnit(new CompositeUnit(Unit.Meters, 2), Unit.Seconds, 2), u * u); }
public CompositeUnit(CompositeUnit u, Unit element, int power) : this() { foreach (Unit el in u._components.Keys) { _components.Add(el, u._components[el]); } _components.Add(element, power); }
public void EqualComposite() { CompositeUnit u1 = new CompositeUnit(new CompositeUnit(Unit.Meters), Unit.Seconds, -1); CompositeUnit u2 = new CompositeUnit(new CompositeUnit(Unit.Seconds, -1), Unit.Meters, 1); CompositeUnit u3 = new CompositeUnit(new CompositeUnit(Unit.Meters, 2), Unit.Seconds, -1); Assert.AreEqual(u1, u2); Assert.AreEqual(u2, u1); Assert.AreNotEqual(u1, u3); Assert.AreNotEqual(u3, u2); }
public CompositeUnit Inverse() { CompositeUnit u = new CompositeUnit(); foreach (Unit el in this._components.Keys) { u._components.Add(el, -this._components[el]); } return(u); }
public static CompositeUnit operator /(CompositeUnit u1, CompositeUnit u2) { CompositeUnit u = u1.Clone(); foreach (Unit el in u2._components.Keys) { if (u._components.ContainsKey(el)) { u._components[el] -= u2._components[el]; } else { u._components.Add(el, -u2._components[el]); } if (u._components[el] == 0) { u._components.Remove(el); } } return(u); }
public void CheckInverse() { CompositeUnit u = new CompositeUnit(new CompositeUnit(Unit.Meters), Unit.Seconds, -2); Assert.AreEqual(new CompositeUnit(new CompositeUnit(Unit.Seconds, 2), Unit.Meters, -1), u.Inverse()); }
public void ToSimple() { CompositeUnit u = new CompositeUnit(Unit.Meters); Assert.AreEqual(Unit.Meters, u.TryReduceToSimple()); }
public void IllegalReduce() { CompositeUnit u = new CompositeUnit(new CompositeUnit(Unit.Meters), Unit.Seconds, 2); Unit uu = u.TryReduceToSimple(); }
public CompositeUnit Inverse() { CompositeUnit u = new CompositeUnit(); foreach (Unit el in this._components.Keys) { u._components.Add(el, -this._components[el]); } return u; }