locked
parameter generation for CompoundValues including circular definition

    Soru

  • hello everybody


    i am using spec explorer as a (logical) test case generator, that means i don't actually generate test code from it within spec explorer itself, but instead export the exploration results to uml.

    both the cord file and the model code will be generated from uml.

    i am currently looking for the best way to handle parameter generation for complex data types.

    my first idea was to use structs to define complex data types.

    example:

    public struct ComplexType1
    {
        public int var1;
        public ComplexType2 var2;
    }
    
    public struct ComplexType2
    {
        public int var1;
    }
    config ParameterCombination: Main 
    {
        action abstract static void MWO.TRANSITION_start(int par1, ModelProgram.ComplexType1 par2)
            where 
            {.
                Condition.In(par1, 30, 60);
                Condition.In(par2.var1, 60, 90);
                Condition.In(par2.var2.var1, 100);
            .};
    }

    this works nice, except for the problem that circular definitions within structs are not allowed.

    so i tried to use CompoundValues instead.

    example:

    public class ComplexType : CompoundValue
    {
         public int var1;
         public ComplexType var2;
    
         ComplexType(int a, ComplexType b)
        {
             var1 = a;
             var2 = b;
        }
    }

    while this works as well, i struggle to figure out how to constraint parameter generation for var2.

    the following is successfull

    config ParameterCombination: Main 
    {
        action abstract static void MWO.TRANSITION_start(int par1, ModelProgram.ComplexType par2)
            where 
            {.
                Condition.In(par1, 30, 60);
                Condition.In(par2.var1, 90);
            .};}

    but i am not sure if it is possible to constraint for example par2.var2. i tried this but it does not work.

    config ParameterCombination: Main

    {

    action abstract static void MWO.TRANSITION_start(int par1, ModelProgram.ComplexType par2)

    where

    {.

    Condition.In(par1, 30, 60);

    Condition.In(par2.var1, 90);

    Condition.In(par2.var2.var2, null);

    .};

    }

    the idea is to specify that var2 of par2 can be either null or a ComplexType, but if var2 is another ComplexType, this objects var2 must be always null.

    so it's basically about constraining the nesting-depth of ComplexType.

    i hope i could make myself clear, and that someone has an idea how to solve this or if there is a better way of modeling arbitrary complex objects altogether.

    cheers

    mkranz



    • Düzenleyen mkranz 16 Şubat 2012 Perşembe 16:01
    16 Şubat 2012 Perşembe 15:54

Yanıtlar

  • Hi Mkranz,

    have not tried it, but this might work (example with depth 1-2, 0-2 is similar):

    Replacing the lines:
         Condition.IsNotNull(par2.var2);
         Condition.IsNull(par2.var2.var2);
         Condition.In(par2.var2.var1, 30);
    with these:
         Condition.IfThen(par2.var2 != null, par2.var2.var1 == 30);
         Condition.IfThen(par2.var2 != null, par2.var2.var2 == null);

    Hope it helps

    17 Şubat 2012 Cuma 09:29

Tüm Yanıtlar

  • ok, i did play around with it some more, and solved at least part of the problem.

    when using the compound value ComplexType as defined before, the following does work

    config ParameterCombination: Main 
    {
        action abstract static void MWO.TRANSITION_start(int par1, ModelProgram.ComplexType par2)
            where 
            {.
                Condition.In(par1, 30, 60);
                Condition.IsNotNull(par2);
                Condition.IsNotNull(par2.var2);
                Condition.IsNull(par2.var2.var2);
                Condition.In(par2.var1, 30);
                Condition.In(par2.var2.var1, 30);
            .};
    }

    the important thing here seems to be to only set conditions for nested parameters of objects that are guaranteed to exist (!= null).

    that means, using

    Condition.In(par2.var2.var1, 30);

    leads to an error during the exploration as soon as par2.var2 == null.

    ok, so this at least allows me to constraint the nesting-depth to a fixed value.

    i guess with some more conditions it might be possible to achive a flexible nesting-depth (for example, allow anything from depth 0 to 2)

    any ideas?


    16 Şubat 2012 Perşembe 17:14
  • Hi Mkranz,

    have not tried it, but this might work (example with depth 1-2, 0-2 is similar):

    Replacing the lines:
         Condition.IsNotNull(par2.var2);
         Condition.IsNull(par2.var2.var2);
         Condition.In(par2.var2.var1, 30);
    with these:
         Condition.IfThen(par2.var2 != null, par2.var2.var1 == 30);
         Condition.IfThen(par2.var2 != null, par2.var2.var2 == null);

    Hope it helps

    17 Şubat 2012 Cuma 09:29
  • hello, thanks for your reply

    i had some time today to play around with it some more, and using IfThen is a good idea to start with.

    the problem is however that it seems you have to tell spec explorer what to do also in case par2.var2 == null.

    example:

    config ParameterCombination: Main 
    {
        action abstract static void MWO.TRANSITION_start(int par1, ModelProgram.ComplexType par2)
            where 
            {.
                Condition.In(par1, 30, 60);
                Condition.IfThen(par2 != null, par2.var1 == 30 & par2.var2 == null);
            .};
    }

    this does work as long as par2 != null, but if par2 == null it leads to an exploration error.

    so what would be needed is a way to tell spec explorer to not try to access par2.* in case par2 == null.

    i have no idea how this could be achieved or if it is possible at all.

    21 Şubat 2012 Salı 15:50
  • Hi Mkranz,

    indeed. I think you can unmark the answer, so your question is open again. 
    Hope someone can help you.

    22 Şubat 2012 Çarşamba 15:34
  • Hi Mkranz,

    this should be a solution. Replace the line:

    Condition.IfThen(par2 != null, par2.var1 == 30 & par2.var2 == null);

    with:

    Condition.IfThen(par2 != null, test (par2));

    static bool test(ComplexType c)
    {       
        try
        {
            return (c.var1 == 30 & c.var2 == null);
        }
        catch
        {
           return (true);
        }
    }
    By the way, can you easily transfer such data-types like ComplexType to UML from the transition objects?

    Hope this helps.

    23 Şubat 2012 Perşembe 10:04