Skip to content

Commit

Permalink
Add some tests for Vector.distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Apr 17, 2023
1 parent ff88018 commit 6302281
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/Tests/src/Data/Vector_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,23 @@ type_spec name alter = Test.group name <|
alter [1, 1.0, 2, 2.0] . distinct . should_equal [1, 2]
alter [] . distinct . should_equal []

Test.specify "should be able to handle distinct on different primitive values" <|
alter [1, "a"] . distinct . should_equal [1, "a"]
alter ["a", 1] . distinct . should_equal ["a", 1]
alter [Nothing, Nothing] . distinct . should_equal [Nothing]
alter [Number.nan, Number.nan] . distinct . to_text . should_equal ["NaN"]
alter [Nothing, Number.nan, Nothing, Number.nan] . distinct . to_text . should_equal ["Nothing", "NaN"]
alter [1, Nothing] . distinct . should_equal [1, Nothing]
alter [Nothing, 1, Nothing] . distinct . should_equal [Nothing, 1]
alter [1, Number.nan] . distinct . to_text . should_equal ["1", "NaN"]
alter [Number.nan, 1, Number.nan] . distinct . to_text . should_equal ["NaN", "1"]
alter [1, Number.nan, 1] . distinct . to_text . should_equal ["1", "NaN"]

Test.specify "should correctly handle distinct with types that have custom comparators" <|
alter [T.Value 1 2, T.Value 3 3, T.Value 1 2] . distinct . should_equal [T.Value 1 2, T.Value 3 3]
alter [T.Value 1 2, T.Value 3 3, T.Value 1 2, Nothing] . distinct . should_equal [T.Value 1 2, T.Value 3 3, Nothing]
alter [Nothing, T.Value 1 2, T.Value 3 3, T.Value 1 2, Nothing] . distinct . should_equal [Nothing, T.Value 1 2, T.Value 3 3]
alter [T.Value 1 2, Date.new hours=3] . distinct . should_equal [T.Value 1 2, Date.new hours=3]

Test.specify "should return a vector containing only unique elements up to some criteria" <|
alter [Pair.new 1 "a", Pair.new 2 "b", Pair.new 1 "c"] . distinct (on = _.first) . should_equal [Pair.new 1 "a", Pair.new 2 "b"]
Expand Down

0 comments on commit 6302281

Please sign in to comment.