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 spec conformance tests for Floating-point-literal #947

Closed
wants to merge 6 commits into from

Conversation

suleka96
Copy link
Contributor

@suleka96 suleka96 commented Oct 4, 2021

Purpose

$title

Related lang issue #32474

@suleka96 suleka96 changed the title Add floating point tests Add spec conformance tests for Floating-point-literal Oct 4, 2021
@pcnfernando
Copy link
Member

There are failing test cases against the test runner.

@hasithaa
Copy link
Contributor

hasithaa commented Dec 6, 2021

The Team is busy with finalizing the SwanLake GA release. Hence closing this PR temporarily.

@hasithaa hasithaa closed this Dec 6, 2021
@suleka96 suleka96 reopened this Jan 20, 2023
@suleka96 suleka96 changed the base branch from conformance-tests to master February 21, 2023 10:33
@KavinduZoysa
Copy link
Contributor

Let's add test cases for HexFloatingPointLiteral, that are combined(appended to hex value) with p, P, d, D, f, F.

@KavinduZoysa
Copy link
Contributor

There should have test cases for,

  1. NaN, infinities and subnormals are not supported; operations that would result in one of these values according to the normal rules of IEEE 754-2008 instead result in a panic.
  2. rounding on float and decimal
  3. Using NaN is float

@KavinduZoysa
Copy link
Contributor

Do we have test cases for this
Thus two decimal values have the same shape if they represent the same mathematical value, even if they do so using different exponents?

}

Test-Case: output
Description: Test HexFloatingPointLiteral with toString().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to add toString tests specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was added when when we first wrote the tests to see if the output was correct, like if it has the correct number of zero digits after the decimal point and so on.

@suleka96
Copy link
Contributor Author

@KavinduZoysa regarding :

Let's add test cases for HexFloatingPointLiteral, that are combined(appended to hex value) with p, P, d, D, f, F.

those tests are already there in: Test invalid hex floating point literal

@MaryamZi MaryamZi requested a review from KavinduZoysa March 24, 2023 05:57
@MaryamZi MaryamZi requested review from pcnfernando and MaryamZi April 4, 2023 05:05
g = 56763457;
io:println(g); // @output 56763457

g = 0d;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not split these tests similar to float above?

Comment on lines +790 to +795
Description: Test out of range decimal floating point literal with decimal type descriptor.
Labels: decimal

function init() {
decimal a = 9.99E+6111;
io:println(a); // @output 9.99E+6111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this output correct if out of range? cc @KavinduZoysa


}

function printDecimalFloatingPoint1() returns float|decimal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to change here, but taking this as an example for future tests, we can make tests simpler by avoiding testing the same thing over and over again.

We've already tested different literals against float|decimal, so we don't have to test in every context. Just one or two would be enough.

}

Test-Case: output
Description: Test the basic type when the applicable contextually expected type is a subtype of float, having a union with nil and float types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to keep, but why were these tests added? What exactly was the special scenario we wanted to test?

Comment on lines +4702 to +4704
io:println(x is float);
io:println(x is int);
io:println(x is decimal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in order int, float, decimal? Or at least float, decimal, int.

Comment on lines +4761 to +4765
Description: Test rounding floating point values with float type.
Labels: float, FloatingPointTypeSuffix, HexFloatingPointLiteral

function init() {
float c = float:round(0.001234, 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these tests added? These are float (and decimal) langlib tests.

}

Test-Case: error
Description: Test hex indicator with float type descriptor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't properly describe the test?

Labels: decimal, HexFloatingPointLiteral

function errorFunction() {
decimal _ = 0x1.0fp+10; // @error hex floating point literal is incompatible with 'decimal'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incompatible -> not allowed

function init() {
float|decimal a = 0x1.0;

if (a is decimal) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (a is decimal) {
if a is decimal {

}

Test-Case: output
Description: Test hex floating point literal type narrowing with floating point type descriptor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type narrowing is on the variable, not the literal. Can we update this to say narrowing when a literal is used with the union of float and decimal instead?

@hasithaa hasithaa closed this Jul 15, 2024
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.

6 participants