Hello,
I have written a program to identify local trees in the area. Basically all you have to do is choose between 2 questions (A or B) each question leads to a new question where you have to choose A or B finally after some time it will zero down on the correct tree identification. I want to test the program, is there a way that I can simulate user input to test all possible conditions to see if there is a broken link someplace.
short of actually taking the cin >> input statement out and hard coding a value, is there another more effective way to simulate user input?
this is basically what my program looks like, it's a switch statement for each type of tree group. $ feed into the function and the correct switch question is asked, when the user inputs an answer the "if" and "else if" decides where to go next.
this is one of the shorter switch statments, there are others with more that 20 case questions. I want to test every possible out come to see if the program works correctly.
Thats a great idea, I was just wondering if there was something in c++ that could actually do that. none the less you gave me the idea to just replace cin with a bool function 0 = A, 1 = B it generates the letters randomly by modding rand() , I think looping it about 4000 times will hit every condition at least once.
could change your function to take istream&, and then you could pass it cin, an ifstream, an istringstream, etc.
btw, for your binary idea -- why use rand() when there's a countable amount of choices? Can generate every option one time with nested for loops or so.
icy1 yeah...I would like a bit more control. I have tried just random generating A or B and it does work fine. My program has 69 trees that can be Identified with the program. But it would be nice to decide what branch to follow v/s just randomly getting and output. Are you proposing maybe something like a truth table?
69 tree ID should mean that there are 69 possible branches to follow.
The Q and A can actually be drawn as a binary tree, but.....maybe for another day since it would be a binary tree of binary trees.....and I don't have too much time right now to tinker with it.
Now that I think about it 4000 loops is overkill.......
Since not all the ID's are going to be the same length, it might need a little modification but I see what you mean. This will also come in handy of my next little side project.