using System; using NUnit.Framework; namespace Chernobyl.Measures.Time { [TestFixture, Description("Tests for the Seconds type.")] public class SecondsTests : TimeTests { [Test, Description("A test that ensures the Seconds(double) constructor " + "sets the proper value.")] public void ConstructorDoubleTest() { Seconds seconds = new Seconds(32.1); Assert.AreEqual(32.1, seconds.Value, 0.0, "The value returned by Seconds.Value is not the expected value."); } [Test, Description("A test to ensure the implicit Seconds to double " + "conversion works as expected.")] public void ImplicitDoubleToSecondsConversionTest() { Seconds seconds = new Seconds(32.1); double value = seconds; Assert.AreEqual(seconds.Value, value, 0.0, "The value returned by the implicit Seconds to Double conversion " + "is not the expected value."); } [Test, Description("A test to ensure the implicit Double to Seconds " + "conversion works as expected.")] public void ExplicitDoubleToSecondsConversionTest() { const double value = 32.1; Seconds seconds = (Seconds)value; Assert.AreEqual(value, seconds.Value, 0.0, "The value returned by the explicit Double to Seconds conversion " + "is not the expected value."); } [TestFixture, Description("Tests for the IEquatable and Object " + "implementations of the Seconds type.")] public class EquatableTests : EquatableTests { protected override IEquatable CreateEquatable() { return new Seconds(32.1); } protected override Seconds CreateEqualObject() { return new Seconds(32.1); } protected override Seconds CreateNotEqualObject() { return new Seconds(15.5); } protected override string ExpectedToStringResult { get { return "32.1 s"; } } } [TestFixture, Description("Tests for the IComparable implementation " + "of the Seconds type.")] public class ComparableTests : ComparableTests { protected override IComparable CreateComparable() { return new Seconds(32.0); } protected override Seconds CreateLessThanObject() { return new Seconds(15.0); } protected override Seconds CreateEqualObject() { return new Seconds(32.0); } protected override Seconds CreateGreaterThanObject() { return new Seconds(33.0); } } [TestFixture, Description("Tests for the Seconds type's mathematical " + "operator overloads.")] public class MathematicalOperatorTests : MathematicalOperatorTests { protected override Seconds CreateX() { return new Seconds(X); } protected override Seconds CreateY() { return new Seconds(Y); } protected override Seconds ExpectedBinaryAdditionResult { get { return new Seconds(X + Y); } } protected override Seconds ExpectedBinarySubtractionResult { get { return new Seconds(X - Y); } } protected override Seconds OppositeExpectedBinarySubtractionResult { get { return new Seconds(Y - X); } } protected override Seconds ExpectedNegationResult { get { return new Seconds(-X); } } protected override Seconds ExpectedMultiplicationResult { get { return new Seconds(X * Y); } } protected override Seconds ExpectedDivisionResult { get { return new Seconds(X / Y); } } protected override Seconds OppositeExpectedDivisionResult { get { return new Seconds(Y / X); } } /// /// The double form of . /// const double X = 32.1; /// /// The double form of . /// const double Y = -56.75; } [TestFixture, Description("Tests for the Seconds type's equality " + "operator overloads.")] public class EqualityOperatorTests : EqualityOperatorTests { protected override Seconds CreateX() { return new Seconds(32.1); } protected override Seconds CreateEqual() { return new Seconds(32.1); } protected override Seconds CreateNotEqual() { return new Seconds(-43.6); } } [TestFixture, Description("Tests for the Seconds type's relational " + "operator overloads.")] public class RelationalOperatorTests : RelationalOperatorTests { protected override Seconds CreateX() { return new Seconds(32.1); } protected override Seconds CreateLessThan() { return new Seconds(32.0); } protected override Seconds CreateEqual() { return new Seconds(32.1); } protected override Seconds CreateGreaterThan() { return new Seconds(32.2); } } protected override ITime CreateTime() { return new Seconds(ToSecondsValue.Value); } } }