Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add math.sqrt() #1

wants to merge 6 commits into from

Conversation

ljbevemyr
Copy link
Owner

@ljbevemyr ljbevemyr commented Sep 9, 2021

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:

  • [ x] All new features have been tested
  • All new features have been documented
  • [x ] I have read the CONTRIBUTING.md file
  • [x ] I will abide by the code of conduct

Some cleaning.
Copy link
Collaborator

@rednaxela5950 rednaxela5950 left a 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;
Copy link
Collaborator

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");
Copy link
Collaborator

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));
Copy link
Collaborator

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));
Copy link
Collaborator

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) {
Copy link
Collaborator

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());
Copy link
Collaborator

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))
Copy link
Collaborator

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"))
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants