Week 2 Assignment - Sets

208 views
Skip to first unread message

spida

unread,
Sep 28, 2012, 3:26:47 PM9/28/12
to scal...@googlegroups.com
Hi all,

How is anyone/everyone getting on with this week's maths test?

Is it just me or does the "contains()" function not work for anyone else for the singletonSet(). The way I see it, if you pass an element to the singletonSet() function it returns the set of that element=>true, so in testing it using the contains function it will always return true as it creates a new singleton set with the "elem" integer that you are testing it with.

Thoughts?

spida

unread,
Sep 28, 2012, 4:33:11 PM9/28/12
to scal...@googlegroups.com
Doh! Yep, it's not a self-fulfilling profecy afterall!

Best tip to those of you that haven't started yet is get the JUnit testing going in tandem with your working on the exercise.

spida

unread,
Sep 28, 2012, 4:51:15 PM9/28/12
to scal...@googlegroups.com
*prophecy (even)

Iain Hull

unread,
Sep 28, 2012, 4:57:33 PM9/28/12
to scal...@googlegroups.com

The singletonSet function returns a function that returns true when past the same integer that was used to create the function and false otherwise. So the contains function should work as expected. You pass the function returned from singletonSet into contains, so contains never calls singletonSet.

asset(contains(singletonSet(5), 5) == true)
asset(contains(singletonSet(5), 2) == false)

I hope this makes sense and helps a little,
Iain.

Reply all
Reply to author
Forward
0 new messages