public void Inequality_null() { var ue = new UnitExponents(); Assert.IsFalse(ue.Equals(null)); Assert.IsFalse(object.Equals(ue, null)); }
public void ToStringReflectsDivide() { var ueMeter = new UnitExponents(1, 0, 0, 0, 0, 0, 0); var ueSecond = new UnitExponents(0, 0, 1, 0, 0, 0, 0); var ueMeterPerSecond = ueMeter / ueSecond; Assert.AreEqual("m/s", ueMeterPerSecond.ToString()); }
public void WorksWithListContains() { var ue = new UnitExponents(1, 1, 1, 1, 1, 1, 1); var same = new UnitExponents(1, 1, 1, 1, 1, 1, 1); var different = new UnitExponents(2, 1, 1, 1, 1, 1, 1); var lst = new System.Collections.Generic.List <UnitExponents>(); lst.Add(different); Assert.IsFalse(lst.Contains(ue)); lst.Add(same); Assert.IsTrue(lst.Contains(ue)); }
public void Equality() { var ue1 = new UnitExponents(1, 4, 0, 2, -3, -2, 1); var ue2 = new UnitExponents(1, 4, 0, 2, -3, -2, 1); var ue3 = new UnitExponents(0, 4, 0, 2, -3, -2, -1); Assert.AreEqual(ue1, ue2); Assert.AreNotSame(ue1, ue2); Assert.IsTrue(ue1 == ue2); Assert.IsFalse(ue1 == ue3); Assert.IsTrue(ue1.Equals(ue2)); Assert.IsTrue(object.Equals(ue1, ue2)); }
public void CanDivide() { var ue1 = new UnitExponents(1, 0, 0, 2, -3, -2, 1); var ue2 = new UnitExponents(0, 4, 1, -1, 0, -2, -1); var ueQuotient = ue1 / ue2; Assert.AreEqual(1, ueQuotient.Length); Assert.AreEqual(-4, ueQuotient.Mass); Assert.AreEqual(-1, ueQuotient.Time); Assert.AreEqual(3, ueQuotient.ElectricCurrent); Assert.AreEqual(-3, ueQuotient.Temperature); Assert.AreEqual(0, ueQuotient.AmountOfSubstance); Assert.AreEqual(2, ueQuotient.LuminousIntensity); }
public void CanMultiply() { var ue1 = new UnitExponents(1, 0, 0, 2, -3, -2, 1); var ue2 = new UnitExponents(0, 4, 1, -1, 0, -2, -1); var ueProduct = ue1 * ue2; Assert.AreEqual(1, ueProduct.Length); Assert.AreEqual(4, ueProduct.Mass); Assert.AreEqual(1, ueProduct.Time); Assert.AreEqual(1, ueProduct.ElectricCurrent); Assert.AreEqual(-3, ueProduct.Temperature); Assert.AreEqual(-4, ueProduct.AmountOfSubstance); Assert.AreEqual(0, ueProduct.LuminousIntensity); }
public override string ToString() { var nominator = UnitExponents .Select((multiplicity, idx) => new { SIBaseUnit = (SIBaseUnit)idx, Multiplicity = multiplicity }) .Where(kvp => kvp.Multiplicity > 0).ToList(); var denominator = UnitExponents .Select((multiplicity, idx) => new { SIBaseUnit = (SIBaseUnit)idx, Multiplicity = multiplicity }) .Where(kvp => kvp.Multiplicity < 0) .ToList(); if (!nominator.Any() && !denominator.Any()) { return(""); } var nominatorStrings = new List <string>(); foreach (var unitMultiplicity in nominator) { var nominatorUnit = unitMultiplicity.SIBaseUnit.StringRepresentation(); if (unitMultiplicity.Multiplicity > 1) { nominatorUnit += "^" + unitMultiplicity.Multiplicity; } nominatorStrings.Add(nominatorUnit); } var denominatorStrings = new List <string>(); foreach (var unitMultiplicity in denominator) { var denominatorUnit = unitMultiplicity.SIBaseUnit.StringRepresentation(); if (unitMultiplicity.Multiplicity.Abs() > 1) { denominatorUnit += "^" + unitMultiplicity.Multiplicity.Abs(); } denominatorStrings.Add(denominatorUnit); } var unitString = ""; if (nominatorStrings.Any()) { unitString += nominatorStrings.Aggregate((a, b) => a + " " + b); } else { unitString += "1"; } if (!denominator.Any()) { return(unitString); } unitString += "/"; unitString += denominatorStrings.Count > 1 ? $"({denominatorStrings.Aggregate((a, b) => a + " " + b)})" : denominatorStrings.Single(); return(unitString); }
public override int GetHashCode() { return(UnitExponents?.GetHashCode() ?? 0); }