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

Equality with conversions #9070

Merged
merged 29 commits into from
Feb 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dce1b25
Enabling equality tests for Complex and Number
JaroslavTulach Feb 15, 2024
7c46739
Adding one more node in front of previously existing EqualsNode
JaroslavTulach Feb 15, 2024
b0a4e48
First of all compute results only then verify them
JaroslavTulach Feb 15, 2024
9f4cde3
Number can be equal to different type. Check with ==
JaroslavTulach Feb 15, 2024
a214c0b
Supporting conversions during evaluation of ==
JaroslavTulach Feb 15, 2024
a2bfb88
Removing accidentally committed fix from other PR
JaroslavTulach Feb 15, 2024
10f7941
TruffleObject vs. boolean specialization
JaroslavTulach Feb 15, 2024
b308014
Encapsulating in equalityCheck method
JaroslavTulach Feb 15, 2024
290b63b
Uncached version of the node may not use cached libraries
JaroslavTulach Feb 15, 2024
bbbbf73
Fool is now equal to anything as there is a Fool.from (that:Any) conv…
JaroslavTulach Feb 15, 2024
3fde985
Don't serialize caches in unit tests
JaroslavTulach Feb 15, 2024
ecd4b90
Enforce consistency of == and hash for converted objects
JaroslavTulach Feb 15, 2024
69510cd
Fool shall not be == unless it defines additional conversions
JaroslavTulach Feb 15, 2024
46666db
Merge remote-tracking branch 'origin/develop' into wip/jtulach/Equali…
JaroslavTulach Feb 16, 2024
0e249c0
Single letter typo fix
JaroslavTulach Feb 16, 2024
a5c0674
Both from conversions must be present in the module defining Complex …
JaroslavTulach Feb 16, 2024
145fc55
Equalities (and inequalities) with conversions test
JaroslavTulach Feb 17, 2024
6fac961
Ensure inconsistency of hash is reported when assert is on
JaroslavTulach Feb 17, 2024
1d16e40
Benchmark equality with conversion
JaroslavTulach Feb 17, 2024
866425c
Wrap also non-double values
JaroslavTulach Feb 17, 2024
3524bd9
Place the == on a separate line to make it more easily visible in IGV
JaroslavTulach Feb 17, 2024
2d708de
Reference to binary operator multiple dispatch
JaroslavTulach Feb 19, 2024
5d52d51
Describing multi-type custom equality
JaroslavTulach Feb 19, 2024
0b7f55c
Verify Comparator for both types is the same
JaroslavTulach Feb 19, 2024
8c88cc1
Use only one WithConversion node
JaroslavTulach Feb 19, 2024
8b48232
Merge remote-tracking branch 'origin/develop' into wip/jtulach/Equali…
JaroslavTulach Feb 19, 2024
12fd925
No need for Convert record. Boolean is enough.
JaroslavTulach Feb 19, 2024
f9af3ad
Fixing typo
JaroslavTulach Feb 19, 2024
d3510a8
Hide InvokeFunctionNode.build behind @TruffleBoundary
JaroslavTulach Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Equalities (and inequalities) with conversions test
JaroslavTulach committed Feb 17, 2024
commit 145fc55300109787f9c3a0569383468ea1afa761
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package org.enso.interpreter.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;
import org.graalvm.polyglot.Context;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class EqualsConversionsTest extends TestBase {
private static Context context;

@BeforeClass
public static void initContextAndData() {
context = createDefaultContext();
}

@AfterClass
public static void disposeContext() {
context.close();
}

@Test
public void testBasicInequalities() {
var results =
TestBase.evalModule(
context,
"""
from Standard.Base import all

Text.from (that:Number) = that.to_text

main =
r0 = "4"+"2" == "42"
r1 = 42 == "42"
r2 = "42" == 42
[ r0, r1, r2 ]
""")
.as(List.class);

assertTrue("strings are equal: " + results, (boolean) results.get(0));
assertFalse("string is not equal to number: " + results, (boolean) results.get(1));
assertFalse("number is not equal to string: " + results, (boolean) results.get(2));
}

@Test
public void testNumWrapperAroundIntegerIsEqualToInteger() {
var gen = new DefineComparableWrapper();
gen.intNumConversion = true;
gen.intComparator = true;
gen.numComparator = true;
assertTrue("Num.Value equal to Integer: ", gen.evaluate());
}

@Test
public void testMissingIntegerNumConversion() {
var gen = new DefineComparableWrapper();
gen.intNumConversion = false;
gen.intComparator = true;
gen.numComparator = true;
assertFalse("Num.Value not equal to Integer: ", gen.evaluate());
}

@Test
public void testMissingIntComparator() {
var gen = new DefineComparableWrapper();
gen.intNumConversion = true;
gen.intComparator = false;
gen.numComparator = true;
assertFalse("Num.Value not equal to Integer: ", gen.evaluate());
}

@Test
public void testMissingNumComparator() {
var gen = new DefineComparableWrapper();
gen.intNumConversion = true;
gen.intComparator = true;
gen.numComparator = false;
assertFalse("Num.Value not equal to Integer: ", gen.evaluate());
}

private static final class DefineComparableWrapper {
boolean intNumConversion;
boolean numComparator;
boolean intComparator;

boolean evaluate() {
var block0 =
"""
from Standard.Base import all

type Num
Value n:Integer

type Num_Comparator
compare x:Num y:Num = Ordering.compare x.n y.n
hash x:Num = x.n
""";

var block1 =
!intNumConversion
? ""
: """
Num.from (that:Integer) = Num.Value that
""";

var block2 =
!numComparator
? ""
: """
Comparable.from (_:Num) = Num_Comparator
""";

var block3 =
!intComparator ? "" : """
Comparable.from (_:Integer) = Num_Comparator
""";

var mainBlock =
"""
main =
num42 = Num.Value 42

r0 = 42 == num42
r0
""";
var res = TestBase.evalModule(context, block0 + block1 + block2 + block3 + mainBlock);
return res.asBoolean();
}
}
}