Exemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // Open a new form where FOCA will receive the pattern's position and all possible values
            var pav = new FormAddVariable.ParametersAddVariable {
                text = rtbPattern.Text
            };
            var intPatron = FindFirstFreePattern();

            pav.StrPattern = string.Format("{{{0}}}", intPatron);
            // Pattern's color changes
            Form frm = new FormAddVariable(this, pav, DefaultColors[intPatron % DefaultColors.Length]);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                var lvi = listViewPatterns.Items.Add(pav.StrPattern);
                lvi.SubItems.Add(pav.IsChar
                    ? string.Format("{0} - {1}", pav.ChrStartValue, pav.ChrEndValue)
                    : string.Format("{0} - {1}", pav.IntStartValue, pav.IntEndValue));
                lvi.UseItemStyleForSubItems = false;
                lvi.ForeColor   = DefaultColors[intPatron % DefaultColors.Length];
                lvi.Tag         = pav;
                rtbPattern.Text = rtbPattern.Text.Insert(pav.PosPattern, pav.StrPattern);
            }
            var valuesCount = CalculateTotalValuesCount();

            lblVariants.Text = valuesCount == 0 ? "The value exceeds the limits" : valuesCount.ToString();
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Increment the values array current value
 /// </summary>
 /// <param name="currentValues"></param>
 /// <param name="valueIndex"></param>
 /// <param name="pav"></param>
 /// <returns>False if the value can not be incremented</returns>
 private bool IncrementValue(ref int[] currentValues, int valueIndex, FormAddVariable.ParametersAddVariable pav)
 {
     if (currentValues[valueIndex] == pav.GetEndValue())
     {
         return(false);
     }
     currentValues[valueIndex]++;
     return(true);
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Generate all possible variants
        /// </summary>
        private void GeneraVariaciones()
        {
            var nPatterns = listViewPatterns.Items.Count;
            // this array will store the current value of each pattern
            var currentValues = new int[nPatterns];
            // existing patterns array
            var pav = new FormAddVariable.ParametersAddVariable[nPatterns];

            // set initial value of each pattern
            for (var i = 0; i < nPatterns; i++)
            {
                pav[i]           = (FormAddVariable.ParametersAddVariable)listViewPatterns.Items[i].Tag;
                currentValues[i] = pav[i].GetStartValue();
            }
            while (true)
            {
                do
                {
                    // add new variant
                    lstVariants.Add(VariantToString(rtbPattern.Text, currentValues, pav));
                } while (IncrementValue(ref currentValues, nPatterns - 1, pav[nPatterns - 1]));
                currentValues[nPatterns - 1] = pav[nPatterns - 1].GetStartValue();
                // if the current value is not the maximum, increment the previous value
                var indexIncrement = nPatterns - 2;
                while (indexIncrement >= 0 &&
                       !IncrementValue(ref currentValues, indexIncrement, pav[indexIncrement]))
                {
                    currentValues[indexIncrement] = pav[indexIncrement].GetStartValue();
                    indexIncrement--;
                }
                if (indexIncrement < 0)
                {
                    break;
                }
            }
        }