Skip to content

Commit

Permalink
Multi value == is not transitive
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 12, 2024
1 parent 77619ab commit 91987ca
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions test/Base_Tests/src/Semantic/Multi_Value_Convert_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ add_specs suite_builder =
uv.u . should_equal "u"
uv.v . should_equal 3.14

Test.expect_panic No_Such_Method <| uv.a
Test.expect_panic No_Such_Method <| uv.b
Test.expect_panic No_Such_Method <| uv.c
Test.expect_panic No_Such_Method <| uv.a
Test.expect_panic No_Such_Method <| uv.b
Test.expect_panic No_Such_Method <| uv.c
Test.expect_panic Type_Error (uv:A)
Test.expect_panic Type_Error (uv:B)
Test.expect_panic Type_Error (uv:C)
Expand Down Expand Up @@ -84,6 +84,47 @@ add_specs suite_builder =
_ -> "what?"
c1 . should_equal "c"

suite_builder.group "Equals and hash" group_builder->
group_builder.specify "Dictionary with value and multi value" <|
pi = 3.14
a = pi : A
b = pi : B
c = pi : C
abc = pi : A&B&C
downcast_a = abc : A
downcast_ab = abc : A&B
downcast_ba = abc : B&A
downcast_b = abc : B
downcast_c = abc : C

Ordering.compare a b . catch Any e->
e.should_equal (Standard.Base.Errors.Common.Incomparable_Values.Error a b)

Ordering.compare a downcast_a . should_equal Ordering.Equal
Ordering.compare a downcast_ab . should_equal Ordering.Equal
Ordering.compare a abc . should_equal Ordering.Equal

Ordering.compare a downcast_ba . should_equal Ordering.Equal
Ordering.compare downcast_ba b . should_equal Ordering.Equal
# if a == downcast_ba && downcast_ba == b then # due to transitivity
# Ordering.compare a b . should_equal Ordering.Equal

dict = Dictionary.empty
. insert a "A"
. insert b "B"
. insert c "C"
. insert downcast_a "A_"
. insert downcast_b "B_"
. insert downcast_c "C_"
. insert abc "Multi"

# dict . get a . should_equal "A" # sometimes it is A and sometimes it is Multi
# dict . get b . should_equal "B"
# dict . get c . should_equal "C" # sometimes it is C and sometimes it is Multi
dict . get downcast_a . should_equal "Multi"
dict . get downcast_b . should_equal "Multi"
dict . get downcast_c . should_equal "Multi"
dict . get abc . should_equal "Multi"

main filter=Nothing =
suite = Test.build suite_builder->
Expand Down

0 comments on commit 91987ca

Please sign in to comment.