Skip to content

Commit

Permalink
Fixed issue#6 (is vs ==)
Browse files Browse the repository at this point in the history
  • Loading branch information
santinic committed Nov 28, 2018
1 parent 5eecad3 commit 63a98d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pampy/pampy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def match_value(pattern, value) -> Tuple[bool, List]:
if value is PaddedValue:
return False, []
elif isinstance(pattern, ValueType):
return pattern is value, []
eq = pattern == value
type_eq = type(pattern) == type(value)
return eq and type_eq, []
elif pattern is None:
return value is None, []
elif isinstance(pattern, type):
Expand Down
13 changes: 11 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ def test_match_value_None(self):
def test_match_None(self):
self.assertEqual(match(None, None, 'None', _, 'else'), 'None')

def test_equality_comparison_should_be_strict(self):
def test_equality_comparison_should_not_be_strict(self):
self.assertEqual(match_value(1, True), (False, []))
self.assertEqual(match_value(0, False), (False, []))
self.assertEqual(match_value(1.0, 1), (False, []))
self.assertEqual(match_value(0.0, 0), (False, []))
self.assertEqual(match_value(1.0, 1), (False, []))

def test_match_value_is_vs_equal(self):
a = 'x' * 1000000
b = 'x' * 1000000
self.assertEqual(a, b)
self.assertFalse(a is b)
self.assertEqual(match_value(a, b), (True, []))
self.assertEqual(match(a, b, True), True)

def test_match_value_var_extraction(self):
self.assertEqual(match_value(3, 3), (True, []))
self.assertEqual(match_value(_, 3), (True, [3]))
Expand Down Expand Up @@ -129,4 +137,5 @@ def what_is(pet):
_, "something else"
)

self.assertEqual(what_is('my-fuffy-cat'), 'fuffy-cat')
self.assertEqual(what_is('my-fuffy-cat'), 'fuffy-cat')

1 change: 1 addition & 0 deletions tests/test_elaborate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def lisp(exp):
self.assertEqual(lisp((plus, 1, 2)), 3)
self.assertEqual(lisp((plus, 1, (minus, 4, 2))), 3)
self.assertEqual(lisp((reduce, plus, (1, 2, 3))), 6)
self.assertEqual(lisp((reduce, plus, (range, 10))), 45)

def test_myzip(self):
def myzip(a, b):
Expand Down

0 comments on commit 63a98d8

Please sign in to comment.