?
Solved

Hopefully "fun" problem to solve - matrix of test values

Posted on 2012-04-05
4
Medium Priority
?
177 Views
Last Modified: 2012-04-06
I need some help conceptualizing (and realizing) a matrix of test values.

I want to test all possible permutations for a series of 6 permissions.  Each permission can be true or false.

CanCreate,CanRead,CanUpdate,CanDelete,CanUseWebservice,CanRunReports

I think the math is 2^6 or 64 different combinations possible:

1,0,0,0,0,0

would represent granting "Can Create" permission and no permissions on the rest.

1,1,0,0,0,0 would grant CanCreate, CanRead and no on the rest.

I want to cover every combination.

I am looking to create a simple matrix for the combinations, just a CSV file of sorts.


Here is what I have so far, but what is the correct way to do this so that no test values repeat and all combinations are represented?

If I find the answer I'll return here and post it.  Until then I await your answer, gurus!


private void buttonGenerateCSV_Click(object sender, EventArgs e)
        {
            string[] headervals = textBoxHeaderValues.Text.Split(',');
            string[] validvals = textBoxValidValues.Text.Split(',');

            foreach (string hs in headervals)
            {
                textBoxCSV.Text += hs;
                foreach (string s in validvals)
                {
                    textBoxCSV.Text += s;
                }
            }

        }

Open in new window

0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37813836
Here's one way:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonGenerateCSV_Click(object sender, EventArgs e)
        {
            textBoxCSV.Clear();
            Revision rev = new Revision("01", "000000");
            while (rev.CurrentRevision.Length == 6)
            {
                string combo = String.Join(",", rev.CurrentRevision.ToCharArray());
                textBoxCSV.AppendText(combo + Environment.NewLine);
                rev.NextRevision();
            }
        }
    }

    public class Revision
    {

        private string chars;
        private char[] values;

        private System.Text.StringBuilder curRevision;

        public Revision()
        {
            this.DefaultRevision();
        }

        public Revision(string validChars)
        {
            if (validChars.Length > 0)
            {
                chars = validChars.ToUpper();
                values = chars.ToCharArray();
                curRevision = new System.Text.StringBuilder(values[0]);
            }
            else
            {
                this.DefaultRevision();
            }
        }

        public Revision(string validChars, string startingRevision)
            : this(validChars)
        {
            curRevision = new System.Text.StringBuilder(startingRevision.ToUpper());
            int i = 0;
            for (i = 0; i <= curRevision.Length - 1; i++)
            {
                if (Array.IndexOf(values, curRevision[i]) == -1)
                {
                    curRevision = new System.Text.StringBuilder(values[0]);
                    break;
                }
            }
        }

        private void DefaultRevision()
        {
            chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            values = chars.ToCharArray();
            curRevision = new System.Text.StringBuilder(values[0]);
        }

        public string ValidChars
        {
            get { return chars; }
        }

        public string CurrentRevision
        {
            get { return curRevision.ToString(); }
        }

        public string NextRevision(int numRevisions = 1)
        {
            bool forward = (numRevisions > 0);
            numRevisions = Math.Abs(numRevisions);
            int i = 0;
            for (i = 1; i <= numRevisions; i++)
            {
                if (forward)
                {
                    this.Increment();
                }
                else
                {
                    this.Decrement();
                }
            }
            return this.CurrentRevision;
        }

        private void Increment()
        {
            char curChar = curRevision[curRevision.Length - 1];
            int index = Array.IndexOf(values, curChar);
            if (index < (chars.Length - 1))
            {
                index = index + 1;
                curRevision[curRevision.Length - 1] = values[index];
            }
            else
            {
                curRevision[curRevision.Length - 1] = values[0];
                int i = 0;
                int startPosition = curRevision.Length - 2;
                for (i = startPosition; i >= 0; i += -1)
                {
                    curChar = curRevision[i];
                    index = Array.IndexOf(values, curChar);
                    if (index < (values.Length - 1))
                    {
                        index = index + 1;
                        curRevision[i] = values[index];
                        return;
                    }
                    else
                    {
                        curRevision[i] = values[0];
                    }
                }
                curRevision.Insert(0, values[0]);
            }
        }

        private void Decrement()
        {
            char curChar = curRevision[curRevision.Length - 1];
            int index = Array.IndexOf(values, curChar);
            if (index > 0)
            {
                index = index - 1;
                curRevision[curRevision.Length - 1] = values[index];
            }
            else
            {
                curRevision[curRevision.Length - 1] = values[values.Length - 1];
                int i = 0;
                int startPosition = curRevision.Length - 2;
                for (i = startPosition; i >= 0; i += -1)
                {
                    curChar = curRevision[i];
                    index = Array.IndexOf(values, curChar);
                    if (index > 0)
                    {
                        index = index - 1;
                        curRevision[i] = values[index];
                        return;
                    }
                    else
                    {
                        curRevision[i] = values[values.Length - 1];
                    }
                }
                curRevision.Remove(0, 1);
                if (curRevision.Length == 0)
                {
                    curRevision.Insert(0, values[0]);
                }
            }
        }

    }

}

Open in new window

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 37816189
Here was my eventual solution:


using System;
using System.Linq;
using System.Windows.Forms;

namespace CSharpCodeGenAndSamples
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string ReturnDecAsBinStringWithPadding(int dectoconvert, int maxpadding)
        {
            string binValue = Convert.ToString(dectoconvert, 2);

            int padlen = binValue.Length;

            while (padlen < maxpadding)
            {
                binValue = "0" + binValue;
                padlen++;
            }

            return binValue;
        }

        private int PowerOf(int num, int basenum)
        {
            int newnum = num;

            for (int i = 1; i < basenum; i++)
            {
                newnum *= num;
            }

            return newnum;
        }

        private string InjectCharsIntoExistingString(string origstring, string chartoinject)
        {
            int strlen = origstring.Length;

            string newstring = "";

            for (int i = 0; i < strlen; i++)
            {
                newstring += origstring[i] + chartoinject;
            }

            newstring = newstring.Substring(0, newstring.Length - 1);
            return newstring;
        }

        private void ButtonGenerateCsvClick(object sender, EventArgs e)
        {
            string[] headervals = textBoxHeaderValues.Text.Split(',');
            string[] validvals = textBoxValidValues.Text.Split(',');

            int countofheaders = headervals.Count();
            int countofvalidvals = validvals.Count();
            int power = PowerOf(countofvalidvals, countofheaders);

            string headercols = headervals.Aggregate("", (current, hs) => current + (hs + ","));

            headercols = headercols.Substring(0, headercols.Length - 1);

            textBoxCSV.Text += headercols + Environment.NewLine;

            for (int i = 0; i < power; i++)
            {
                string binasstring = ReturnDecAsBinStringWithPadding(i, 6);
                string arrayofbinvals = InjectCharsIntoExistingString(binasstring, ",");

                textBoxCSV.Text += arrayofbinvals + Environment.NewLine;
                //string[] newarrayofbinvals = arrayofbinvals.Split(',');                
            }


            foreach (string s in validvals)
            {
                textBoxCSV.Text += s;
                foreach (string hs in headervals)
                {
                    textBoxCSV.Text += hs;
                }
            }
        }
    }
}

Open in new window

0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 37816192
Thank you for the example and for your time spent on this!

Tom
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37816211
No problem.  Definitely many ways to approach this problem...
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question