Seite 1 von 1

problem with testing Filter function

Verfasst: 3. Mai 2015 21:41
von m.hosseinian
Hi,

I have implemented filter function for IntSet class (using union function, it is also used in intersect function, and working well) but when I run the test file it complains about it, yielding:

{1,2,3,4}.filter {x -> even(x) }
- should return {2,4} *** FAILED ***
2 4 did not equal 2 4 (TreeSetsTests.scala:46)

It looks strange to me because I assume the function is working properly. Can you guide me on that? Maybe test file is not written correctly.

Regards,
Moe

Re: problem with testing Filter function

Verfasst: 4. Mai 2015 10:47
von leonidglanz
Hello,

I have checked the TestSuite and I had no failing tests.
It is hard to see the issue without your code, please ask for help in the office hours of our tutors. (like today at 11:00 a.m.)

Regards,
Leonid Glanz

Re: problem with testing Filter function

Verfasst: 4. Mai 2015 11:22
von m.hosseinian
the problem is that the test case is expecting that elements are included in the same order it preserves, which is irrelevant according Set Theory, {2, 4} = {4, 2}
if .toString() is included to each side of equality it passes. Isn't it a better idea to change the tests this way?

Re: problem with testing Filter function

Verfasst: 4. Mai 2015 12:38
von leonidglanz
It is right that a set doesn't have an order, but a IntSet belongs to the TreeSet implementation and that is an ordered set.
So it is important that the result of your implementation should be ordered.

Re: problem with testing Filter function

Verfasst: 4. Mai 2015 23:02
von m.hosseinian
Yes, I see the ordered implementation requirement, but notice:
A: NonEmpty = {
elem: Int = 2
left: IntSet = Empty
right: IntSet = new NonEmpty(4, Empty, Empty)
}
and
B: NonEmpty = {
elem: Int = 4
left: IntSet = new NonEmpty(2, Empty, Empty)
right: IntSet = Empty
}
both preserves the binary tree principles and therefore, ordered, but actually different objects presenting the same set.
test case should be able to identify this and consider them as equal sets, which in our case it isn't apparently!

Re: problem with testing Filter function

Verfasst: 5. Mai 2015 08:48
von leonidglanz
For this exercise it is important to traverse the TreeSet in-order and it should not depend on the insertion order. We want that the implementation is as simple as possible for that we want to use the equals method of case-classes.

Re: problem with testing Filter function

Verfasst: 5. Mai 2015 10:51
von ManuelWeiel
m.hosseinian hat geschrieben:Hi,

I have implemented filter function for IntSet class (using union function, it is also used in intersect function, and working well) but when I run the test file it complains about it, yielding:

{1,2,3,4}.filter {x -> even(x) }
- should return {2,4} *** FAILED ***
2 4 did not equal 2 4 (TreeSetsTests.scala:46)

It looks strange to me because I assume the function is working properly. Can you guide me on that? Maybe test file is not written correctly.

Regards,
Moe
It is also possible that it is just a problem of white spaces. Check the test and your implementation that both match your style. Especially in the case of the last number (might get a space added afterwards or not).

Re: problem with testing Filter function

Verfasst: 5. Mai 2015 11:40
von m.hosseinian
ManuelWeiel hat geschrieben:
m.hosseinian hat geschrieben:Hi,

I have implemented filter function for IntSet class (using union function, it is also used in intersect function, and working well) but when I run the test file it complains about it, yielding:

{1,2,3,4}.filter {x -> even(x) }
- should return {2,4} *** FAILED ***
2 4 did not equal 2 4 (TreeSetsTests.scala:46)

It looks strange to me because I assume the function is working properly. Can you guide me on that? Maybe test file is not written correctly.

Regards,
Moe
It is also possible that it is just a problem of white spaces. Check the test and your implementation that both match your style. Especially in the case of the last number (might get a space added afterwards or not).
.toString() test passes.. also in this case if you add it to both sides it will pass.. maybe testing using combination of .contains() is wiser.

Re: problem with testing Filter function

Verfasst: 5. Mai 2015 11:45
von ManuelWeiel
You are free to modify the tests as you like. The shipped tests are just a reference. Just make sure, that the intended functionality is kept...