public void CreateDistance()
        {
            #region UsageDistance

            // Extension method for the distance base unit (Meters).
            var meters = 4.Meters();

            // Extension method with a unit selector for selecting any unit.
            var kilometers = 5.ToDistance(x => x.Kilo.Meters);

            // Same as above, but as a direct call to the constructor.
            var micrometers = new Distance(6, x => x.Micro.Meters);

            // Constructor, which accepts any IUnit (Primarily used by serialization).
            var millimeters = new Distance(7, UnitSystem.GetUnitFrom("mm", ParseSettings.DefaultInvariantCulture).Value);

            this.output.WriteLine(meters);
            this.output.WriteLine(kilometers);
            this.output.WriteLine(micrometers);
            this.output.WriteLine(millimeters);

            // 4 [m]
            // 5 [km]
            // 6 [μm]
            // 7 [mm]

            #endregion
        }
        public void Distance_Division_Then_ResultShouldBeExpected(double lhs, double rhs, double expected)
        {
            var testee1 = new Distance(lhs, x => x.Meters);
            var testee2 = new Distance(rhs, x => x.Meters);

            var result = testee1 / testee2;

            result.Should().Be(expected);
        }
        public void Distance_CompareTo_Then_ResultShouldBeExpected(double lhs, double rhs, int expected)
        {
            var testee1 = new Distance(lhs, x => x.Centi.Meters);
            var testee2 = new Distance(rhs, x => x.Centi.Meters);

            var result = testee1.CompareTo(testee2);

            result.Should().Be(expected);
        }
        public void Distance_CompareTo_Then_ResultShouldBeAsExpected()
        {
            var testee1 = 1000.Meters();
            var testee2 = new Distance(1, x => x.Kilo.Meters);

            var result = testee1.CompareTo(testee2);

            result.Should().Be(0);
        }
        public void Distance_Multiplication_Then_ResultShouldBeExpected(double lhs, double rhs, double expected)
        {
            var testee1 = new Distance(lhs, x => x.Meters);
            var testee2 = new Distance(rhs, x => x.Meters);

            var result = testee1 * testee2;

            result.Should().Be(expected, "m²");
        }
        public void Distance_Equals_Then_ResultShouldBeAsExpected(double lhs, double rhs, bool expected)
        {
            var testee1 = new Distance(lhs, x => x.Miles);
            var testee2 = new Distance(rhs, x => x.Miles);

            var result = testee1.Equals(testee2);

            result.Should().Be(expected);
        }
        public void Distance_Subtraction_Then_ResultShouldBeExpected(double lhs, double rhs, double expected)
        {
            var testee1 = new Distance(lhs, x => x.Meters);
            var testee2 = new Distance(rhs, x => x.Centi.Meters);

            var result = testee1 - testee2;

            result.Should().Be(expected, "m");
        }
예제 #8
0
        public void Distance_ToUnit_When_ConvertingFromMilliMeterToMile_Then_ResultShouldBeAsExpected(
            double length,
            double expected)
        {
            var testee = new Distance(length, x => x.Milli.Meters);

            IQuantity result = testee.ToUnit(x => x.Miles);

            result.Value.Should().BeApproximately(expected, TestHelper.DefaultAssertPrecision);
        }
        public void Distance_Subtraction_When_SubtractingAnyNumber_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee = new Distance(lhs, x => x.Meters);

            var result = testee - rhs;

            result.Should().Be(expected, "m");
        }
        public void Distance_Multiplication_When_MultiplyingWithAnyNumber_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Meters);

            var result = testee1 * rhs;

            result.Should().Be(expected, "m");
        }
        public void Distance_Division_When_DividingWithAnyNumber_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee = new Distance(lhs, x => x.Meters);

            var result = testee / rhs;

            result.Should().Be(expected, "m");
        }
        public void Distance_Division_When_RhsIsVelocity_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Meters);
            var testee2 = new Velocity(rhs, selector => selector.Meters / selector.Seconds);

            var result = testee1 / testee2;

            result.Should().BeApproximately(expected, "s");
        }
        public void Distance_Division_When_RhsIsVelocityAndPrefixesAreDifferent_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Centi.Meters);
            var testee2 = new Velocity(rhs, selector => selector.Meters / selector.Seconds);

            var result = testee1 / testee2;

            result.Should().BeApproximately(expected, "s", TestHelper.DefaultAssertPrecision);
        }
        public void Distance_Addition_When_PrefixesAreDifferent_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Kilo.Meters);
            var testee2 = new Distance(rhs, x => x.Meters);

            var result = testee1 + testee2;

            result.Should().Be(expected, "km");
        }
        public void Distance_Multiplication_When_UnitsAndPrefixesAreDifferent_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Deci.Meters);
            var testee2 = new Distance(rhs, x => x.Centi.Meters);

            var result = testee1 * testee2;

            result.Should().BeApproximately(expected, "dm²", TestHelper.DefaultAssertPrecision);
        }
        public void Area_Multiplication_When_MultiplyingWithAnyLength_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee = new Area(lhs, x => x.Square.Meters);
            var length = new Distance(rhs, x => x.Miles);

            var result = testee * length;

            result.Should().Be(expected, "m³");
        }
        public void Distance_Addition_When_UnitsAreDifferent_Then_ResultShouldBeAsExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Miles);
            var testee2 = new Distance(rhs, x => x.Kilo.Meters);

            var result = testee1 + testee2;

            result.Should().BeApproximately(expected, "mi", TestHelper.DefaultAssertPrecision);
        }
        public void Volume_Division_When_DividingWithLength_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Volume(lhs, x => x.Cubic.Meters);
            var testee2 = new Distance(rhs, x => x.Meters);

            var result = testee1 / testee2;

            result.Should().Be(expected, "m" + Constants.Exponent2);
        }
        public void Distance_Equals_When_PrefixesAreDifferent_Then_ResultShouldBeAsExpected(
            double lhs,
            double lhsPrefix,
            double rhs,
            double rhsPrefix,
            bool expected)
        {
            var testee1 = new Distance(lhs, x => x.By(lhsPrefix).Meters);
            var testee2 = new Distance(rhs, x => x.By(rhsPrefix).Meters);

            var result = testee1.Equals(testee2);

            result.Should().Be(expected);
        }
        public void Distance_Division_When_RhsIsTime_Then_ResultShouldBeExpected(
            double lhs,
            double rhs,
            double expected)
        {
            var testee1 = new Distance(lhs, x => x.Meters);
            var testee2 = new Time(rhs, x => x.Seconds);

            var result = testee1 / testee2;

            result.Should().BeApproximately(expected, "m/s");
        }