-
Notifications
You must be signed in to change notification settings - Fork 54
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
[Master] Add spec conformance tests for multiplicative expression containing int varref with other numeric operands #1173
Conversation
Description: Test float division with optional integers. | ||
Labels: DecimalNumber, float, float-NaN, int, multiplicative-expr, nil-literal, numeric-nil-lifting | ||
|
||
function init() { | ||
int? a = 4; | ||
int? b = (); | ||
float c = 4.5e-1; | ||
float d = float:NaN; | ||
|
||
float? v = c / a; | ||
io:println(v); // @output 0.1125 | ||
|
||
v = c / b; | ||
io:println(v); // @output () | ||
|
||
v = d / a; | ||
io:println(v); // @output NaN | ||
|
||
v = d / b; | ||
io:println(v); // @output () | ||
} | ||
|
||
Test-Case: output | ||
Description: Test optional float division with optional and non-optional integers. |
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.
For this, we should cover.
- optional float and non optional int
- optional float and optional int
- non optional float and non optional int
- non optional float and optional int
Some you have covered already. May be we can split them into four separate tests
} | ||
|
||
Test-Case: output | ||
Description: Test optional float division with optional and non-optional subtypes of integers. |
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.
Let's split the optional and non optional ones into two tests.
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.
For each of these tests with optional types, there are four different possible ways of doing the calculation. Hence let's add all possible scenarios separately with each of these types.
int? b = 5; | ||
|
||
var c = a / b; | ||
io:println(c is float); // @output true |
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.
We should have tests that check the result for calculations with var
too
v = d / e; | ||
io:println(v); // @output NaN | ||
} | ||
|
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.
Let's also add some tests with different user-defined subtypes of int and float
Ex:
const int A = 1;
const int B = 2;
type IntType1 int:Signed8|int:Unsigned8;
type IntType2 A|B;
type IntType3 A|int:Signed16;
type IntType4 IntType2|IntType3;
var i = constDecimal / constInt; | ||
io:println(i is decimal); // @output true | ||
} | ||
|
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.
Tests when the type of the lhs operand is inferred as float
or decimal
var a = 12d;
int b = 10;
var x = a / b;
var c = 12f;
var y = c / b;
const decimal r1 = a * c; // @error out of range for decimal | ||
const decimal r2 = a * d; // @error out of range for decimal | ||
const decimal r3 = b * c; // @error out of range for decimal | ||
const decimal r4 = b * d; // @error out of range for decimal |
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.
We should add a tests for
float a = 1;
decimal b = 1;
int c = 1;
var x = c / a; // operator '/' not defined for 'int'(dividend) and 'float'(divisor)
var y = c / b; // operator '/' not defined for 'int'(dividend) and 'decimal'(divisor)
var x = c % a; // operator '%' not defined for 'int'(dividend) and 'float'(divisor)
var y = c % b; // operator '%' not defined for 'int'(dividend) and 'decimal'(divisor)
} | ||
|
||
Test-Case: panic | ||
Fail-Issue: ballerina-platform/ballerina-lang#37541 |
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 fixed now. We can remove the fail issue.
Please check other places as well
@@ -371,3 +371,18 @@ Labels: multiplicative-expr, int, DecimalNumber | |||
string a = 2 * 12; // @error static type of integer multiplication is int | |||
string b = 2 / 1; // @error static type of integer division is int | |||
string c = 2 % 1; // @error static type of integer remainder is int | |||
|
|||
Test-Case: error | |||
Fail-Issue: ballerina-platform/ballerina-lang#37541 |
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 fixed now. We can remove the fail issue
} | ||
|
||
Test-Case: panic | ||
Fail-Issue: ballerina-platform/ballerina-lang#37541 |
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 fixed now.
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.
Let's do the same improvements for multiplication and remainder as well.
Purpose
$title
Fixes #37191