示例#1
0
        public void FromString_ValidString_CorrectDecimals(string asString, int expectedDecimals)
        {
            // Arrange and act
            var unitUnderTest = new LengthMetric().FromString(asString);

            // Assert
            Assert.That(unitUnderTest.Precision, Is.EqualTo(expectedDecimals));
        }
示例#2
0
        public void FromString_ValidStringWithSpaces_CorrectUnitSubType(string asString, QuantityMetric.MetricPrefix expectedMetricPrefix)
        {
            // Act
            var unitUnderTest = new LengthMetric().FromString(asString);

            // Assert
            Assert.That(unitUnderTest.UnitSubType, Is.EqualTo((ushort)expectedMetricPrefix));
        }
示例#3
0
        public void FromString_validString_ValueConverted(string asString, double expectedValue)
        {
            // Arrange and act
            var unitUnderTest = new LengthMetric().FromString(asString + "m");

            // Assert
            Assert.That(unitUnderTest.Value, Is.EqualTo(expectedValue));
        }
示例#4
0
        public void FromString_ValidString_CorrectUnitType(string asString)
        {
            // Act
            var unitUnderTest = new LengthMetric().FromString(asString);

            // Assert
            Assert.That(unitUnderTest.UnitType, Is.EqualTo((ushort)Length.LengthUnit.Metric));
        }
示例#5
0
        public void FromString_ValidString_CorrectQuantityType()
        {
            // Act
            var unitUnderTest = new LengthMetric().FromString("1 m");

            // Assert
            Assert.That(unitUnderTest.QuantityType, Is.EqualTo(QuantityType.Length));
        }
示例#6
0
        public void SubtractQuantity_SameUnits_ExpectedResult(string valueA, string valueB, string expectedOutcome)
        {
            var test = new LengthMetric();

            // Arrange
            var quantityA = QuantityFactory.FromString(valueA);
            var quantityB = QuantityFactory.FromString(valueB);

            // Act
            var actualResult = (quantityA - quantityB).ToString();

            // Assert
            Assert.That(actualResult, Is.EqualTo(expectedOutcome));
        }
示例#7
0
        public void Constructor_InvalidDna_ThrowsException()
        {
            // Arrange
            var invalidDna = new QuantityDna
            {
                QuantityType = QuantityType.Length,
                UnitType     = (ushort)Length.LengthUnit.Imperial,
                UnitSubType  = (ushort)QuantityMetric.MetricPrefix.Base,
                Precision    = 2
            };

            // Act and Assert
            Assert.Throws <ArgumentException>(() =>
            {
                var unused = new LengthMetric(invalidDna, 21.09);
            });
        }
示例#8
0
        public void Constructor_WithValidDna_CreatesLengthMetric()
        {
            // Arrange
            var validDna = new QuantityDna
            {
                QuantityType = QuantityType.Length,
                UnitType     = (ushort)Length.LengthUnit.Metric,
                UnitSubType  = (ushort)QuantityMetric.MetricPrefix.Base,
                Precision    = 2
            };

            // Act
            var unitUnderTest = new LengthMetric(validDna, 21.09);

            // Assert
            Assert.That(unitUnderTest.ToString(), Is.EqualTo("21,09m"));
        }