public void TestEquality() { Duration first = new Duration(5, 565.0); Duration second = new Duration(5, 565.0); Assert.AreEqual(first, second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(second.Equals(first)); Assert.IsTrue(first == second); Assert.IsTrue(second == first); Assert.IsFalse(first != second); Assert.IsFalse(second != first); Assert.AreEqual(0, first.CompareTo(second)); Assert.AreEqual(0, second.CompareTo(first)); first = new Duration(5, 0.00001); second = new Duration(4, 86399.99999); Assert.AreNotEqual(first, second); Assert.IsFalse(first.Equals(second)); Assert.IsFalse(second.Equals(first)); Assert.IsFalse(first == second); Assert.IsFalse(second == first); Assert.IsTrue(first != second); Assert.IsTrue(second != first); Assert.AreNotEqual(0, first.CompareTo(second)); Assert.AreNotEqual(0, second.CompareTo(first)); Assert.IsTrue(first.EqualsEpsilon(second, 1e-4)); Assert.IsTrue(second.EqualsEpsilon(first, 1e-4)); // Make sure a Duration compared with a non-Duration returns false Assert.IsFalse(first.Equals(5)); }
public void TestDivisionByConstant() { Duration duration = new Duration(500, 100.0); Duration result = duration.Divide(100.0); Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10)); result = duration / 100.0; Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10)); duration = new Duration(5, 68010.0); result = duration.Divide(100.0); Assert.IsTrue(result.EqualsEpsilon(new Duration(0, 5000.1), Constants.Epsilon10)); result = duration / 100.0; Assert.IsTrue(result.EqualsEpsilon(new Duration(0, 5000.1), Constants.Epsilon10)); duration = new Duration(0, 64800.0); result = duration.Divide(0.5); Assert.IsTrue(result.EqualsEpsilon(new Duration(1, 43200.0), Constants.Epsilon10)); result = duration / 0.5; Assert.IsTrue(result.EqualsEpsilon(new Duration(1, 43200.0), Constants.Epsilon10)); duration = new Duration(502, 43300.5); result = duration.Divide(100.5); Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10)); result = duration / 100.5; Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10)); duration = new Duration(5, 1.0); result = duration / -2.0; Assert.IsTrue(result.EqualsEpsilon(new Duration(-2, -43200.5), Constants.Epsilon10)); duration = new Duration(0, 18 * 3600); result = duration / -0.5; Assert.AreEqual(-12 * 3600, result.Seconds); Assert.AreEqual(-1, result.Days); duration = new Duration(1, 4 * 3600); result = duration / -2; Assert.AreEqual(-14 * 3600, result.Seconds); Assert.AreEqual(0, result.Days); }
public void TestMultiplication() { Duration duration = new Duration(5, 1.0); Duration result = duration.Multiply(100.0); Assert.IsTrue(result.EqualsEpsilon(new Duration(500, 100.0), Constants.Epsilon10)); result = duration * 100.0; Assert.IsTrue(result.EqualsEpsilon(new Duration(500, 100.0), Constants.Epsilon10)); duration = new Duration(0, 5000.1); result = duration.Multiply(100.0); Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 68010.0), Constants.Epsilon10)); result = duration * 100.0; Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 68010.0), Constants.Epsilon10)); duration = new Duration(1, 43200.0); result = duration.Multiply(0.5); Assert.IsTrue(result.EqualsEpsilon(new Duration(0, 64800.0), Constants.Epsilon10)); result = duration * 0.5; Assert.IsTrue(result.EqualsEpsilon(new Duration(0, 64800.0), Constants.Epsilon10)); duration = new Duration(5, 1.0); result = duration.Multiply(100.5); Assert.IsTrue(result.EqualsEpsilon(new Duration(502, 43300.5), Constants.Epsilon10)); result = duration * 100.5; Assert.IsTrue(result.EqualsEpsilon(new Duration(502, 43300.5), Constants.Epsilon10)); result = duration * -0.5; Assert.IsTrue(result.EqualsEpsilon(new Duration(-2, -43200.5), Constants.Epsilon10)); duration = new Duration(0, 18 * 3600); result = duration * -2; Assert.AreEqual(-12 * 3600, result.Seconds); Assert.AreEqual(-1, result.Days); duration = new Duration(1, 4 * 3600); result = duration * -0.5; Assert.AreEqual(-14 * 3600, result.Seconds); Assert.AreEqual(0, result.Days); }