complement on list

42 views
Skip to first unread message

mathias louiset

unread,
Jul 3, 2013, 5:52:38 AM7/3/13
to testerm...@googlegroups.com

Hello,

I can’t figure out how works the “complement” primitive.

In this example both tests pass:

class TC_TEST_LIST(TestCase):

                def body(self, msg, comp):

                               

                                if match(msg, complement(*comp)):

                                                setverdict(PASS)

                                else:

                                                setverdict(FAIL)

 

 

TC_TEST_LIST().execute(msg = [ 1, 2, 3 ], comp = [1])

TC_TEST_LIST().execute(msg = [ 1, 2, 3 ], comp = [4])

 

Am I doing something wrong ?

Thanks for any help,

Mathias

 

Sébastien Lefèvre

unread,
Jul 3, 2013, 11:08:51 AM7/3/13
to testerm...@googlegroups.com

Ho Mathias,

'Complement' is equivalent to 'not included in the provided list'.

So, match(2, complement(1, 2, 3)) is false while match(4, complement(1, 2, 3)) is true (well, if not buggy of course).

Thanks,
-seb

--
You received this message because you are subscribed to the Google Groups "Testerman Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testerman-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

mathias louiset

unread,
Jul 3, 2013, 12:00:33 PM7/3/13
to testerm...@googlegroups.com

Oh yes! I see now

In fact that’s not what I need to do J

Is there a way to match a list if it contains some expected elements (“superset” works perfectly for this) AND if it does NOT contains other elements ?

By example,

match([1, 2, 3], magic_func(toMatch=[1, 2], toUnMatch=[4, 5])) would be true

match([1, 2, 3], magic_func(toMatch=[1, 4], toUnMatch=[5])) would be false

match([1, 2, 3], magic_func(toMatch=[1, 2], toUnMatch=[3])) would be false

 

Thanks,

Mathias

Sébastien Lefèvre

unread,
Jul 3, 2013, 4:56:34 PM7/3/13
to testerm...@googlegroups.com
Hi Mathias,

I initially thought that you could combine terminal conditions with the boolean conditions "and_()" and "not_()" or "or_()", something like:
template = and_(superset(1, 2), not_(in_(4, 5))

but the problem is that complement() or in_() won't work as you want for a list message.
We would need a "contains any of(...)" condition, which is currently not available.

Proposed workaround:

Use on-the-fly transformation before matching a template. 

To match a superset of L1 and making sure that no element of L2 is in the result, we could imagine using:

template = and_(superset(*L1), with_(lambda L: [e for e in L if e in L2], [] ))

The second condition in the and_() is making sure that the intersection between the (list) message and L2 is empty.

Example:

message = [ 1, 2, 3, 6, 7]
template = and_(superset(1, 2), with_(lambda L: [e for e in L if e in [4, 5] ], [] ))

match(message, template) -> true

message = [ 1, 2, 3, 4, 7]
template = and_(superset(1, 2), with_(lambda L: [e for e in L if e in [4, 5] ], [] ))

match(message, template) -> false

You may also create your "magic_func" directly and use it for with_()-based on the fly transformation (instead of using the and_(superset(), ...) construct).

I'll check with the TTCN3 standard to see if there is something close to "contains any of" primitive, and if not I'll probably add something in the testerman API anyway, this may be convenient.

thanks,
-seb




2013/7/3 mathias louiset <mathias...@actility.com>



--
Sebastien Lefevre
seb.l...@gmail.com

mathias louiset

unread,
Jul 4, 2013, 4:29:23 AM7/4/13
to testerm...@googlegroups.com

Hi,

Many thanks Seb, it works perfectly and fits exactly to what I need!

Cheers,

Mathias

 

PS: It took me a little while to understand the thing with “lambda” and “with_”…

May the force be with you! J

Reply all
Reply to author
Forward
0 new messages