problem with testing Filter function

m.hosseinian
Windoof-User
Windoof-User
Beiträge: 34
Registriert: 3. Mai 2015 21:28

problem with testing Filter function

Beitrag 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

leonidglanz
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 126
Registriert: 29. Apr 2015 08:35

Re: problem with testing Filter function

Beitrag 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

m.hosseinian
Windoof-User
Windoof-User
Beiträge: 34
Registriert: 3. Mai 2015 21:28

Re: problem with testing Filter function

Beitrag 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?

leonidglanz
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 126
Registriert: 29. Apr 2015 08:35

Re: problem with testing Filter function

Beitrag 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.

m.hosseinian
Windoof-User
Windoof-User
Beiträge: 34
Registriert: 3. Mai 2015 21:28

Re: problem with testing Filter function

Beitrag 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!

leonidglanz
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 126
Registriert: 29. Apr 2015 08:35

Re: problem with testing Filter function

Beitrag 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.

ManuelWeiel
Mausschubser
Mausschubser
Beiträge: 72
Registriert: 7. Okt 2014 11:38

Re: problem with testing Filter function

Beitrag 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).

m.hosseinian
Windoof-User
Windoof-User
Beiträge: 34
Registriert: 3. Mai 2015 21:28

Re: problem with testing Filter function

Beitrag 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.

ManuelWeiel
Mausschubser
Mausschubser
Beiträge: 72
Registriert: 7. Okt 2014 11:38

Re: problem with testing Filter function

Beitrag 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...

Antworten

Zurück zu „Archiv“