示例#1
0
        public void measure_dimension_should_measure_formulated_units_to_basic_unit_properly(
            double fromValue, double expected)
        {
            var celcius = new BasicMeasureUnitTestBuilder()
                          .WithSymbol(new Symbol(MeasureUnitSymbolTestData.CelciusUnitSymbol))
                          .WithTitle("سلسیوس")
                          .BuildArg();

            var formulatedUnitBuilder = new FormulatedMeasureUnitTestBuilder();
            var farenheit             = formulatedUnitBuilder
                                        .WithSymbol(new Symbol(MeasureUnitSymbolTestData.FarenheitUnitSymbol))
                                        .WithTitle("فارنهایت")
                                        .WithConvertFormulaToBasicUnit("5 / 9 * (a - 32)")
                                        .WitCconvertFormulaFromBasicUnit("32 + (9 / 5 * a)")
                                        .BuildArg();

            var dimension = new MeasureDimensionTestBuilder()
                            .WithBasicMeasureUnitArg(celcius)
                            .WithFormulatedMeasureUnitArg(farenheit)
                            .Build();

            var arg = new MeasurementArg
            {
                FromValue      = fromValue,
                FromUnitSymbol = new Symbol(MeasureUnitSymbolTestData.FarenheitUnitSymbol),
                ToUnitSymbol   = new Symbol(MeasureUnitSymbolTestData.CelciusUnitSymbol)
            };

            var measuredValue = dimension.MeasureUnitsFor(arg, new FormulaExpressionEvaluator());

            Check.That(measuredValue).IsEqualTo(expected);
        }
示例#2
0
        public void measure_dimension_should_measure_basic_units_properly()
        {
            var symbol       = new Symbol(MeasureUnitSymbolTestData.MeterUnitSymbol);
            var basicUnitArg = new BasicMeasureUnitTestBuilder()
                               .WithSymbol(symbol)
                               .WithTitle("متر")
                               .WithTitleSlug("Meter")
                               .BuildArg();

            var dimension = new MeasureDimensionTestBuilder()
                            .WithTitle("طول")
                            .WithBasicMeasureUnitArg(basicUnitArg)
                            .Build();

            var arg = new MeasurementArg
            {
                FromValue      = 22.5,
                FromUnitSymbol = symbol,
                ToUnitSymbol   = symbol
            };

            var expected = 22.5;

            var MeasureValue = dimension
                               .MeasureUnitsFor(arg, _formulaExpressionEvaluator);

            Check.That(MeasureValue).IsEqualTo(expected);
        }
示例#3
0
        public void measure_dimension_should_measure_coeffiecient_units_to_coeffiecient_units_properly()
        {
            var meter = new BasicMeasureUnitTestBuilder()
                        .WithSymbol(new Symbol(MeasureUnitSymbolTestData.MeterUnitSymbol))
                        .WithTitle("متر")
                        .BuildArg();

            var centiMeter = new CoefficientMeasureUnitTestBuilder()
                             .WithSymbol(new Symbol(MeasureUnitSymbolTestData.CentiMeterUnitSymbol))
                             .WithTitle("سانتیمتر")
                             .WithRatioFromBasicMeasureUnit(0.01)
                             .BuildArg();

            var kiloMeter = new CoefficientMeasureUnitTestBuilder()
                            .WithSymbol(new Symbol(MeasureUnitSymbolTestData.KiloMeterUnitSymbol))
                            .WithTitle("کیلومتر")
                            .WithRatioFromBasicMeasureUnit(1000)
                            .BuildArg();

            var dimension = new MeasureDimensionTestBuilder()
                            .WithTitle("طول")
                            .WithBasicMeasureUnitArg(meter)
                            .WithCoefficientMeasureUnitArg(centiMeter)
                            .WithCoefficientMeasureUnitArg(kiloMeter)
                            .Build();

            var arg = new MeasurementArg
            {
                FromValue      = 10,
                FromUnitSymbol = new Symbol(MeasureUnitSymbolTestData.KiloMeterUnitSymbol),
                ToUnitSymbol   = new Symbol(MeasureUnitSymbolTestData.CentiMeterUnitSymbol)
            };

            var expected = 1000000;

            var measuredValue = dimension.MeasureUnitsFor(arg, _formulaExpressionEvaluator);

            Check.That(measuredValue).IsEqualTo(expected);
        }