1

I've made a Spec Explorer project that has a list as system variable. Almost in every rule this list is adapted to get the correct results. But when I explore my project I get duplicate states. If I compare these states the only difference I find is:

_version: 25 System.Int32
_version: 23 System.Int32

After googling why this happens I found that each time a string is altered the version changes. So even though version 23 and 25 contain the same string, the version number makes Spec Explorer think they are different, so it produces 2 states. Is there anyway to fix this? Like resetting the string or maybe there is a way to force Spec Explorer to accept this.

Kyra
  • 173
  • 2
  • 16

1 Answers1

0

Here is an idea for a possible root cause:

The rich state objects like Set, Sequence or Map are immutable. This means, if you want to add an element the "Add"-method returns a new object with the changed content. Important is that this returned object still is detected as the same (but changed content) instance by Spec Explorer. So you should always reuse this returned object. You can do this by assigning the changed object back to the static state variable of you program model:

_version = _version.Add(15);

If in your program instead a complete new object is now created on every call of your rule method with a "new"-operator and this new object is copied to the static state variable of you program model you will get always a new instance and Spec Explorer will detect them as different instances, even if the content is the same.

_newversion = new Set<int>();  
...  
_version = _newversion;

Hope this helps in your case ...

Bas
  • 4,423
  • 8
  • 36
  • 53
goofy
  • 549
  • 2
  • 7
  • First thank you for answering, I don't think you get the exact problem. _version isn't the list name, it's the version of my list, my list is called 'enabled'. The list of version 23 and 25 are exactly the same except for the version number. This version number is something that I can not edit. Every time I do enabled.Add("something") or enabled.Clear() internally visual studio edits the version number, and Spec Explorer sees 2 different states, even though they are actually the same. The Add function returns void, so the proposed solution wouldn't work. – Kyra Mar 18 '15 at 09:34
  • @Kyra: In my test above I could reproduce your problem. So somehow you are doing something different. What kind of collection are you using (you mention a "list" which is not a part of Microsoft.Modeling)? Microsoft.Modeling.Set is really returning a Set and not void (See https://msdn.microsoft.com/en-us/library/ee680676.aspx). Or are you using a Container like Microsoft.Modelling.SetContainer? Please try to use one of these ... – goofy Mar 18 '15 at 11:20
  • @Kyra: If "_version" is not part of your state space I have no idea where it comes from. My only guess is, that it might be an internal state of the "list" implementation you are using, which is usually completely invisible for a user... – goofy Mar 18 '15 at 11:28
  • 1
    I just have a 'list enable' as a system variable. This indeed is invisible to the user. When I generate the model I see several times 'Deactivated' as state. Before this state is reached enable.Clear() is called. When I compare these states the difference is the _version of my system variable 'enable'. This is a version number that visual studio edits within the list. – Kyra Mar 18 '15 at 11:46
  • 1
    @Kyra: This is the reason: If possible "System.Collections.Generic.List" and all the other collections should not be used inside your model, but you should use Microsoft.Modeling.Set or Sequence etc.. The reason is that only the Modeling-classes are "clean" in a way that the implementer of these classes has not used internal states which lead to state explosion. That's why you'll find only these collections in the Spec Explorer Examples. – goofy Mar 18 '15 at 12:06
  • @Kyra: And this is really a very important point, because this is the reason, for Model based Testing: The productive code you are testing will use collection like "List" and exploring this code will definitively lead to state explosion. So thats why we build models and must use the "cleaner" classes. Does this makes sense? – goofy Mar 18 '15 at 12:06
  • I get what you are saying, and I tried making the same model with set or sequence. But when I do this the model immediatly goes into error state, because "sequence value is read only", same happens with set. – Kyra Mar 18 '15 at 12:13
  • @Kyra: The Modeling-classes are immutable, so if you want to change a value already in your collection you have to remove the element and add a new one with the changed value at the right position. This is some extra effort you have to take ... – goofy Mar 18 '15 at 12:55
  • Figured out the problem, set doesn't support clear. This will be an issue because I don't know what is in the list, I just want it cleared. Thanks anyway, I will do some research how to use sets. If this is the solution I will accept your answer later today/ – Kyra Mar 18 '15 at 13:11