示例#1
0
        public void LengthTimesLength_Returns_AreaQuantity()
        {
            // Arrange
            SiUnitSystemFactory siFactory = new SiUnitSystemFactory();
            IUnitSystem         siSystem  = siFactory.Create();

            StandardQuantitiesCatalog.Setup();

            // Act
            Quantity <float> width    = new Quantity <float>(2.0f, StandardUnitsCatalog.Meter);
            Quantity <float> height   = new Quantity <float>(4.0f, StandardUnitsCatalog.Meter);
            Quantity <float> resultm2 = (Quantity <float>)(width * height);

            IValueConverter converter = siSystem.CreateConverter(resultm2.Unit, StandardUnitsCatalog.SquareCentimeter);

            Assert.NotNull(converter);

            Quantity <float> resultcm2 = new Quantity <float>(converter.Convert(resultm2.Value), converter.Target);

            // Assert
            Assert.AreEqual(8.0f, resultm2.Value);
            Assert.AreEqual(StandardUnitsCatalog.SquareMeter, resultm2.Unit);
            Assert.AreEqual(StandardDimensionsCatalog.Area, resultm2.Dimension);
            Assert.AreEqual(StandardDimensionsCatalog.Area, resultcm2.Dimension);
            Assert.AreEqual(resultm2.Value * 100.0f * 100.0f, resultcm2.Value);
        }
示例#2
0
        public Program()
        {
            SiUnitSystemFactory siFactory = new SiUnitSystemFactory();

            _siSystem = siFactory.Create();
            StandardQuantitiesCatalog.Setup();
        }
        public void Setup_Subtract_SameValueTypeIsWorking()
        {
            // Arrange
            StandardQuantitiesCatalog.Setup();

            // Act/Assert (left input, right input, expected output)
            Assert.DoesNotThrow(DoQuantitySubtract <float, float, float>);
            Assert.DoesNotThrow(DoQuantitySubtract <double, double, double>);
            Assert.DoesNotThrow(DoQuantitySubtract <int, int, int>);
            Assert.DoesNotThrow(DoQuantitySubtract <long, long, long>);
        }
        public void Setup_Add_CombinationsThrowsInvalidOperationException()
        {
            // Arrange
            StandardQuantitiesCatalog.Setup();

            // Act/Assert (left input, right input, expected output)
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <float, double, double>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <double, float, double>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <int, long, long>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <long, int, int>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <float, int, float>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <int, float, float>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <float, long, float>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <long, float, float>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <double, int, double>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <int, double, double>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <double, long, double>);
            Assert.Throws <InvalidOperationException>(DoQuantityAdd <long, double, double>);
        }
        public void Setup_Divide_AllAssosciativeCombinationsAreWorking()
        {
            // Arrange
            StandardQuantitiesCatalog.Setup();

            // Act/Assert (left input, right input, expected output)
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <float, float, float>(1, 1));
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <double, double, double>(1, 1));
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <int, int, int>(1, 1));
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <long, long, long>(1, 1));

            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <double, int, double>(1, 1));
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <double, long, double>(1, 1));
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <double, float, double>(1, 1));

            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <float, int, float>(1, 1));
            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <float, long, float>(1, 1));

            Assert.DoesNotThrow(() => DoAssosciativeQuantityDivide <int, long, long>(1, 1));
        }
        public void Setup_Multiply_AllAssosciativeCombinationsAreWorking()
        {
            // Arrange
            StandardQuantitiesCatalog.Setup();

            // Act/Assert (left input, right input, expected output)
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <float, float, float>);
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <double, double, double>);
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <int, int, int>);
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <long, long, long>);

            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <double, int, double>);
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <double, long, double>);
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <double, float, double>);

            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <float, int, float>);
            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <float, long, float>);

            Assert.DoesNotThrow(DoAssosciativeQuantityMultiply <int, long, long>);
        }