Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Add set.union and set.intersection aliases to set.__ior__ and set.__i… #684

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions batavia/types/Set.js
Expand Up @@ -489,6 +489,10 @@ Set.prototype.update = function(args) {
}
}

// note that union and intersection are equivalent to __ior__ and __iand__
Set.prototype.union = Set.prototype.__ior__
Set.prototype.intersection = Set.prototype.__iand__

/**************************************************
* Module exports
**************************************************/
Expand Down
28 changes: 28 additions & 0 deletions tests/datatypes/test_set.py
Expand Up @@ -62,6 +62,34 @@ def test_iter(self):
""")


def test__ior__(self):
self.assertCodeExecution("""
a = {'a', 'b', 'c'}
b = {'a', 'c', 'd'}
a.__ior__(b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check of __ior__ isn't needed - it's covered automatically by the InlineBinaryOperationTests.

""")

def test__iand__(self):
self.assertCodeExecution("""
a = {'a', 'b', 'c'}
b = {'a', 'c', 'd'}
a.__iand__(b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check of __iand__ isn't needed - it's covered automatically by the InlineBinaryOperationTests.

""")


def test_union(self):
self.assertCodeExecution("""
a = {'a', 'b', 'c'}
b = {'a', 'c', 'd'}
a.union(b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is executes the right code, it won't actually test anything. assertCodeExecution() performs a comparison of the output of executed code - so, this test will verify that the code doesn't output anything. This will verify that the code runs without error, but won't verify that the output is actually correct.

To test that the output is correct, you have to print the result of the operation so that there is something to compare.

""")

def test_intersection(self):
self.assertCodeExecution("""
a = {'a', 'b', 'c'}
b = {'a', 'c', 'd'}
a.intersection(b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with union, a print statement (or something else that generates output) is required.

""")

class UnarySetOperationTests(UnaryOperationTestCase, TranspileTestCase):
data_type = 'set'
Expand Down