Randomized data generation for parameters.
-
Dienstag, 24. Juli 2012 15:22
Hello all,
I have an rule like
DoSomething(int n)
{
if (n>10)
goto state A
else goto state B
}
I want to assign value for n in such a way that every time the rule is invoked, it randomly assigns a value to n.
Is there any way to do it?
- Bearbeitet Vivek.Vishal Dienstag, 24. Juli 2012 15:22
Alle Antworten
-
Dienstag, 24. Juli 2012 17:22
It appears there is a Choice class in Spec Explorer to randomly choose a value from a set of values/ranges.
Another possibility:
Condition.IsTrue(n>0) - for letting the Spec Explorer choose a positive random value, for example.
Hope it helps.
Dharma
-
Mittwoch, 25. Juli 2012 08:28
Hello Dharma,
Thanks for your reply. One of the requirements of my testing is to test a rule with different random assignment of parameters (satisfying some condition). However, every time I get the same random value of parameters (satisfying the conditions) for my rule.
Thanks,
Vivek
-
Mittwoch, 25. Juli 2012 12:07
I saw "random" discussions here: http://appmbt.blogspot.com/2012/05/modeling-stochastic-systems-in-spec.html
- Als Antwort markiert Vivek.Vishal Sonntag, 29. Juli 2012 09:26
-
Sonntag, 29. Juli 2012 09:26
Finally found the solution, Thanks Dharma,
Somthing like following solves the problem,
DoSomething(int n)
{
Combination.Strategy(CombinationStrategy.Coverage);
Condition.IsTrue(appStatus == States.ABC);
if (n > 10)
{
Condition.IsTrue(i == random.Next(11,100));
appStatus = States.A;
}
else
{
Condition.IsTrue(i == random.Next(-100, 10));
appStatus = States.B;
}
}- Als Antwort markiert Vivek.Vishal Sonntag, 29. Juli 2012 09:26

