beeware / batavia

A JavaScript implementation of the Python virtual machine.
http://pybee.org/batavia
Other
1.39k stars 424 forks source link

union and intersection frozen set #730

Closed mdmjg closed 4 years ago

mdmjg commented 6 years ago

These are the union and intersection methods for frozen set.

mdmjg commented 6 years ago

I made some changes but there is an important issue that could be addressed in order to make these tests pass. When you do the following in CPython: x = frozenset([5,1,7,6]) print(x) It will return frozenset({1, 5, 6, 7}) <- an ordered version of the frozen set.

However, when you do the same in Batavia, the program will not return the set in increasing order. This makes the union function return a frozen set that is not increasing order, which in turn makes the tests fail. In order to make the union function return exactly the same as CPython, changes unrelated to the union method would have to be implemented.

martica commented 5 years ago

CPython isn't quite as predictable in its ordering.

These tests could be made to pass by changing print(frozenset... to print(sorted(frozenset... if the sorted() builtin was implemented.

Barring that, it looks like changing the format to something that tests properties of the output set would cover this.

Like:

x = frozenset([2,4,5,6])
y = frozenset([3,4,7,9])
z = x.union(y)
print(len(z))
print([elem in z for elem in x])
print([elem in z for elem in y])

x = frozenset([2,4,5,6])
y = frozenset([3,4,7,9])
z = x.intersection(y)
print(len(z))
print([elem in x and elem in y for elem in z])
phildini commented 4 years ago

Hi there! It looks like this PR might be dead, so we're closing it for now. Feel free to re-open it if you'd like to continue, or think about directing your efforts to https://github.com/beeware/briefcase or https://github.com/beeware/toga. Both of these have more active development right now. 😄