private decimal[] GetCombinationValues(MultiplierCombination combination, decimal[] values, decimal increment)
 {
     for (int i = 0; i < values.Length; i++)
     {
         values[i] = _combination.GetIncrementStep(i, increment);
     }
     return values;
 }
        public static OldPrescriptionCalculator SetCombinations(Prescription prescription)
        {
            var pc = new OldPrescriptionCalculator(prescription);
            var combi = new MultiplierCombination(
                prescription,
                () => prescription.Total, () => prescription.Frequency, () => prescription.Quantity
            );

            pc.AddCalculation(combi);
            return pc;
        }
예제 #3
0
 public static void RandomizeCombination(MultiplierCombination combi)
 {
     var rnd = new Random();
     var total = rnd.Next(40, 120) * combi.GetUnitValue(0).Factor.IncrementSizes[0];
     var nr1 = rnd.Next(1, 60) * combi.GetUnitValue(1).Factor.IncrementSizes[0];
     var nr2 = rnd.Next(1, 60) * combi.GetUnitValue(2).Factor.IncrementSizes[0];
     combi.GetUnitValue(0).Value = total;
     combi.GetUnitValue(1).Value = nr1;
     combi.GetUnitValue(2).Value = nr2;
     File.AppendAllText(CalculationTest._testPath, "1: Value0=" + total + " Value1=" + nr1 + " Value2=" + nr2 + "\r\n");
 }
        /*
         * Calculate values based on discrete mathematics
         * First get the incrementStep from the property value then calculate the non calculated field
         * This method also corrects a property if the current values cannot be set.
         */
        public bool Calculate(MultiplierCombination combination, int index)
        {
            _combination = combination;

            /*
             * If not enough properties are available for calculation,
             * it is not possible to calculate it
             */
            if (!_combination.CanBeCalculated()) return false;

            //In case multiple substance increments are available, retrieve all fd
            decimal[] substanceIncrements = new[]{0.002m};
            decimal[] values = new decimal[3];

            //Get the property to be corrected
            int propertyToRectify = combination.GetIndexToRectify();
            int correctIndex = combination.GetIndexToRectify();

            /*
             * Loop through all possible substanceIncrements to calculate the index (=not calculated property in combination)
             * The calculated result is rounded to an integer for the closest possible value
             * After that the value is returned to an incrementValue and added to the list of possible values
             */
            foreach (decimal increment in substanceIncrements)
            {
                //Get IncrementSteps
                values = GetCombinationValues(combination, values, increment);

                values[index] = MathExt.RoundToInt(_calculate(index, values));

                values[correctIndex] = 0;
                _calculate(correctIndex, values);

                AddToValues(values, increment);
            }

            //Determine the closes possible value determined by the user
            int calculatedSubstanceIndex = _findCalculatedIndices();
            _combination.SetValue(propertyToRectify, _calculatedValues[correctIndex][calculatedSubstanceIndex]);
            _combination.SetValue(index, _calculatedValues[index][calculatedSubstanceIndex]);

            //Set the calculated and corrected value, and if a calculation is made, calculate any sibblings
            //bool didCorrectValue = _propertyManager.TrySetValue(propertyToRectify, _calculatedValues[correctIndex][calculatedSubstanceIndex]);
            //bool didCalculateValue = _propertyManager.TrySetValue(_combination.GetAt(index), _calculatedValues[index][calculatedSubstanceIndex]);
            //return didCalculateValue;);
            return true;
        }
예제 #5
0
        public void CalculatorCanRectifySimpleCalculation()
        {
            var prescription = CreateParacetamolRect(Prescription.NewPrescription());
            prescription.Frequency.Value = 2;
            prescription.Quantity.Value = 4;
            var pc = new OldPrescriptionCalculator(prescription);

            var combi = new MultiplierCombination(
                prescription,
                () => prescription.Total, () => prescription.Frequency, () => prescription.Quantity
            );

            pc.AddCalculation(combi);
            pc.Execute();
            pc.Finish();

            Assert.AreEqual(2, prescription.Frequency.Value, "wrong frequency value");
            Assert.AreEqual(8, prescription.Total.Value, "wrong total value");
            Assert.AreEqual(4, prescription.Quantity.Value, "woring quantity value");
        }
예제 #6
0
 public void AddCombiToCalculator(Prescription p, OldPrescriptionCalculator pc, params Expression<Func<UnitValue>>[] properties)
 {
     var combi = new MultiplierCombination(p,properties);
     pc.AddCalculation(combi);
 }