Skip to content

Commit

Permalink
update equality for boxed types (#2587)
Browse files Browse the repository at this point in the history
* update equality for boxed types

* update equality for boxed types

* update tests with library equals
  • Loading branch information
AFine-gs authored Jan 30, 2024
1 parent 96d8d8a commit dd86e40
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,8 @@ function meta::pure::executionPlan::platformBinding::legendJava::library::boolea
function meta::pure::executionPlan::platformBinding::legendJava::library::boolean::equalTo(ctx:FuncCoderContext[1], left:Code[1], right:Code[1], library:meta::external::language::java::metamodel::Class[1]): Code[1]
{
let eq = if ($left.type->isPrimitive() && $right.type->isPrimitive(),
| $left->j_eq($right),
|
if (($left.type == javaLong() || $left.type == javaLongBoxed()) && ($right.type == javaLong() || $right.type == javaLongBoxed()),
| $left->j_eq($right),
|
if (($left.type == javaDouble() || $left.type == javaDoubleBoxed()) && ($right.type == javaDouble() || $right.type == javaDoubleBoxed()),
| $left->j_eq($right),
| $library->j_invoke('equals', [$left, $right], javaBoolean())
)));
| $left->j_eq($right),
| $library->j_invoke('equals', [$left, $right], javaBoolean())
);
}

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests:
{
javaPureTests(engineConventions([]), [
meta::pure::functions::boolean::tests::testIsPrimitive__Boolean_1_,
meta::pure::functions::boolean::tests::testIsEnum__Boolean_1_
meta::pure::functions::boolean::tests::testIsEnum__Boolean_1_,
meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::testInstanceEquality__Boolean_1_
//meta::pure::functions::boolean::tests::testIsNonPrimitive__Boolean_1_, // TODO Requires New
//meta::pure::functions::boolean::tests::testIsNativeFunctions__Boolean_1_, // TODO Requires Metadata
//meta::pure::functions::boolean::tests::testIsConcreteFunctionDefinitions, // TODO Requires Metadata
Expand All @@ -86,3 +87,28 @@ meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests:
->generate(meta::pure::functions::boolean::tests::equalitymodel::TestEnum2)
->runTests();
}

function <<meta::pure::profiles::test.Test>>
meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::testInstanceEquality():Boolean[1]
{
let v1= ^meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::TestInstanceValues(float=1.0,decimal=1.0d);
let v2 = ^meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::TestInstanceValues(float=1.0,decimal=1.0d);
let v3 = ^meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::TestInstanceValues(string='test');
let v4 = ^meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::TestInstanceValues(float=1.1,decimal=1.1d);
assert($v1.float==$v2.float);
assert($v1.float==1.0);
assert(1.0==$v1.float);
assert($v1.float!=$v3.float);
assert($v1.float!=$v4.float);
assert($v1.decimal==$v2.decimal);
assert($v1.decimal==1.0d);
assert(1.0d==$v1.decimal);
assert($v1.decimal!=$v3.decimal);
}

Class meta::pure::executionPlan::platformBinding::legendJava::library::boolean::tests::TestInstanceValues
{
string:String[0..1];
decimal:Decimal[0..1];
float:Float[0..1];
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ meta::pure::executionPlan::platformBinding::legendJava::library::collection::tes
->assert('%s == 4L')
->addTest('count list', {|[]->count()}, 'java.util.Collections.emptyList().stream().count()', javaLong())
->assert('%s == 0L')
->addTest('exists singletons', {|[1]->exists(x:Integer[1] | $x == 1)}, 'java.util.stream.Stream.<Long>of(1L).anyMatch((Long x) -> x == 1L)', javaBoolean())
->addTest('exists singletons', {|[1]->exists(x:Integer[1] | $x == 1)}, 'java.util.stream.Stream.<Long>of(1L).anyMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 1L))', javaBoolean())
->assert('%s == true')
->addTest('exists list', {|[1,2,3,1]->exists(x:Integer[1] | $x == 1)}, 'java.util.Arrays.asList(1L, 2L, 3L, 1L).stream().anyMatch((Long x) -> x == 1L)', javaBoolean())
->addTest('exists list', {|[1,2,3,1]->exists(x:Integer[1] | $x == 1)}, 'java.util.Arrays.asList(1L, 2L, 3L, 1L).stream().anyMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 1L))', javaBoolean())
->assert('%s == true')
->addTest('exists empty', {|[]->exists(x:Integer[1] | $x == 1)}, 'java.util.Collections.emptyList().stream().map(Long.class::cast).anyMatch((Long x) -> x == 1L)', javaBoolean()) // this is almost like doing a preeval....
->addTest('exists empty', {|[]->exists(x:Integer[1] | $x == 1)}, 'java.util.Collections.emptyList().stream().map(Long.class::cast).anyMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 1L))', javaBoolean()) // this is almost like doing a preeval....
->assert('%s == false')
->addTest('forAll singletons', {|[1]->forAll(x:Integer[1] | $x == 1)}, 'java.util.stream.Stream.<Long>of(1L).allMatch((Long x) -> x == 1L)', javaBoolean())
->addTest('forAll singletons', {|[1]->forAll(x:Integer[1] | $x == 1)}, 'java.util.stream.Stream.<Long>of(1L).allMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 1L))', javaBoolean())
->assert('%s == true')
->addTest('forAll list', {|[1,2,3,1]->forAll(x:Integer[1] | $x == 1)}, 'java.util.Arrays.asList(1L, 2L, 3L, 1L).stream().allMatch((Long x) -> x == 1L)', javaBoolean())
->addTest('forAll list', {|[1,2,3,1]->forAll(x:Integer[1] | $x == 1)}, 'java.util.Arrays.asList(1L, 2L, 3L, 1L).stream().allMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 1L))', javaBoolean())
->assert('%s == false')
->addTest('forAll list', {|[3,3,3,3]->forAll(x:Integer[1] | $x == 3)}, 'java.util.Arrays.asList(3L, 3L, 3L, 3L).stream().allMatch((Long x) -> x == 3L)', javaBoolean())
->addTest('forAll list', {|[3,3,3,3]->forAll(x:Integer[1] | $x == 3)}, 'java.util.Arrays.asList(3L, 3L, 3L, 3L).stream().allMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 3L))', javaBoolean())
->assert('%s == true')
->addTest('forAll empty', {|[]->forAll(x:Integer[1] | $x == 1)}, 'java.util.Collections.emptyList().stream().map(Long.class::cast).allMatch((Long x) -> x == 1L)', javaBoolean())
->addTest('forAll empty', {|[]->forAll(x:Integer[1] | $x == 1)}, 'java.util.Collections.emptyList().stream().map(Long.class::cast).allMatch((Long x) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, 1L))', javaBoolean())
->assert('%s == true')
->runTests();
}
Expand Down Expand Up @@ -245,9 +245,9 @@ meta::pure::executionPlan::platformBinding::legendJava::library::collection::tes
->assert('%s == true')
->addTest('contains singleton test false', {|1->contains(5)}, 'java.util.Objects.equals(1L, 5L)', javaBoolean())
->assert('%s == false')
->addTest('contains function test true', {|[1,2,3]->contains(3, {x,y | $x == $y})}, 'org.finos.legend.engine.plan.dependencies.util.Library.contains(java.util.Arrays.asList(1L, 2L, 3L), 3L, (Long x, Long y) -> x == y)', javaBoolean())
->addTest('contains function test true', {|[1,2,3]->contains(3, {x,y | $x == $y})}, 'org.finos.legend.engine.plan.dependencies.util.Library.contains(java.util.Arrays.asList(1L, 2L, 3L), 3L, (Long x, Long y) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, y))', javaBoolean())
->assert('%s == true')
->addTest('contains function test false', {|1->contains(5, {x,y | $x == $y})}, 'org.finos.legend.engine.plan.dependencies.util.Library.contains(1L, 5L, (Long x, Long y) -> x == y)', javaBoolean())
->addTest('contains function test false', {|1->contains(5, {x,y | $x == $y})}, 'org.finos.legend.engine.plan.dependencies.util.Library.contains(1L, 5L, (Long x, Long y) -> org.finos.legend.engine.plan.dependencies.util.Library.equals(x, y))', javaBoolean())
->assert('%s == false')
->addTest('in test true', {|3->in([1,2,3])}, 'java.util.Arrays.asList(1L, 2L, 3L).contains(3L)', javaBoolean())
->assert('%s == true')
Expand Down

0 comments on commit dd86e40

Please sign in to comment.