-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add math.sqrt() #1
base: master
Are you sure you want to change the base?
Conversation
Some cleaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Followed coding conventions, but some lines are dangerously close to the strict line limit of 119. One minor bug found. Tests fail.
super(); | ||
} | ||
|
||
public static org.python.Object _STRUCT_TM_ITEMS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this struct do?
public static org.python.Object _STRUCT_TM_ITEMS; | ||
|
||
@org.python.Attribute | ||
public static org.python.Object __file__ = new org.python.types.Str("python/common/python/math.java"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do? The file python/common/python/math.java
does not exist. Perhaps it is misplaced?
if(((org.python.types.Float) number).value < 0.0){ | ||
throw new org.python.exceptions.ValueError("math domain error"); | ||
} | ||
return new org.python.types.Float(Math.sqrt(((org.python.types.Float) number.__float__()).value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard to read. This could be changed into a variable set outside the if statement so it can be used on line 32.
if(((org.python.types.Int) number).value < 0){ | ||
throw new org.python.exceptions.ValueError("math domain error"); | ||
} | ||
return new org.python.types.Float(Math.sqrt(((org.python.types.Float) number.__float__()).value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment for line 26.
} | ||
return new org.python.types.Float(Math.sqrt(((org.python.types.Float) number.__float__()).value)); | ||
} | ||
else if(number instanceof org.python.types.Bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In python booleans are instances of Int: therefore we will never enter this case since we already check for integers in an earlier if statement on row 28.
return new org.python.types.Float(val ? 1 : 0); | ||
} | ||
else{ | ||
throw new org.python.exceptions.TypeError("floor() argument must be real number, not "+ number.typeName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
floor() should be changed to sqrt()
def test_sqrt_negatives(self): | ||
self.assertCodeExecution(""" | ||
import math | ||
print(math.sqrt(-1.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a test case for a negative integer
def test_sqrt_no_number(self): | ||
self.assertCodeExecution(""" | ||
import math | ||
print(math.sqrt("no number")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing a string. It should be math.sqrt()
.
@@ -76,7 +76,7 @@ def remove_output_dir(): | |||
) | |||
|
|||
try: | |||
out, err = proc.communicate(timeout=30) | |||
out, err = proc.communicate(timeout=60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind this change?
Added math.squrt to the library and created some tests.
This solves the problem of being able to use square root in the VOC system.
PR Checklist: