Skip to content

Commit

Permalink
refacted and add test case for __mul__ for float datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
svmundada committed Mar 2, 2018
1 parent e7d2535 commit 3bba04a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 3 additions & 6 deletions python/common/org/python/types/Float.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,10 @@ public org.python.Object __mul__(org.python.Object other) {
return new org.python.types.Float(this.value * (((org.python.types.Bool) other).__int__().value));
} else if (other instanceof org.python.types.Complex) {
return ((org.python.types.Complex) other).__mul__(this);
} else {
super.__mul__(other);
}

throw new org.python.exceptions.NotImplementedError("float.__mul__() has not been implemented.");
return super.__mul__(other);

}


Expand All @@ -339,10 +338,8 @@ public org.python.Object __imul__(org.python.Object other) {
return new org.python.types.Float(this.value * (((org.python.types.Bool) other).__int__().value));
} else if (other instanceof org.python.types.Complex) {
return ((org.python.types.Complex) other).__imul__(this);
} else {
super.__imul__(other);
}
throw new org.python.exceptions.NotImplementedError("float.__mul__() has not been implemented.");
return super.__imul__(other);
}


Expand Down
1 change: 0 additions & 1 deletion tests/builtins/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class BuiltinSetFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
not_implemented = [
'test_bytes',
'test_str',
'test_tuple',
]

is_flakey = [
Expand Down
9 changes: 9 additions & 0 deletions tests/datatypes/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def test_hex(self):
code = '\n'.join(template.format(number) for number in numbers)
self.assertCodeExecution(code)

def test_mul_TypeError(self):
self.assertCodeExecution("""
a = 5.6
try:
print(a*None);
except TypeError as e:
print(e)
""")


class UnaryFloatOperationTests(UnaryOperationTestCase, TranspileTestCase):
data_type = 'float'
Expand Down

0 comments on commit 3bba04a

Please sign in to comment.