-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d0f132
commit 972da1b
Showing
9 changed files
with
122 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from Standard.Base import all | ||
|
||
import Standard.Base.Data.Ordering.Comparator | ||
from Standard.Base.Data.Text.Text_Ordering as Text_Ordering_Module import Text_Ordering | ||
|
||
import Standard.Test | ||
|
||
polyglot java import java.lang.ClassCastException | ||
|
||
# === Test Resources === | ||
|
||
type Ord number | ||
|
||
Ord.compare_to : Ord -> Ordering | ||
Ord.compare_to that = that.number.compare_to this.number | ||
|
||
type No_Ord number | ||
|
||
# Tests | ||
|
||
spec = Test.group "Object Comparator" <| | ||
handle_classcast = Panic.catch ClassCastException handler=(Error.throw Vector.Incomparable_Values_Error) | ||
default_comparator a b = handle_classcast <| Comparator.new.compare a b | ||
case_insensitive a b = handle_classcast <| Comparator.for_text_ordering (Text_Ordering False Case_Insensitive) . compare a b | ||
|
||
Test.specify "can compare numbers" <| | ||
((default_comparator 1 2) < 0) . should_equal True | ||
((default_comparator 1 1.2) < 0) . should_equal True | ||
((default_comparator 1 1) == 0) . should_equal True | ||
|
||
Test.specify "can compare booleans" <| | ||
((default_comparator True False) > 0) . should_equal True | ||
((default_comparator True True) == 0) . should_equal True | ||
((default_comparator False False) == 0) . should_equal True | ||
|
||
Test.specify "can compare Nothing and it ends up as lowest value" <| | ||
((default_comparator 1 Nothing) > 0) . should_equal True | ||
((default_comparator Nothing 1.235) < 0) . should_equal True | ||
((default_comparator True Nothing) > 0) . should_equal True | ||
((default_comparator Nothing False) < 0) . should_equal True | ||
((default_comparator "A" Nothing) > 0) . should_equal True | ||
((default_comparator Nothing "ZSA") < 0) . should_equal True | ||
((default_comparator Nothing Nothing) == 0) . should_equal True | ||
|
||
Test.specify "can compare Text with Enso standard defaults" <| | ||
((default_comparator "A" "a") < 0) . should_equal True | ||
((default_comparator "ABBA" "ABBA") == 0) . should_equal True | ||
((default_comparator '\u00E9' '\u0065\u{301}') == 0) . should_equal True | ||
|
||
Test.specify "can compare Text with case-insensitive comparisons" <| | ||
((case_insensitive "A" "a") == 0) . should_equal True | ||
((case_insensitive "ABBA" "abba") == 0) . should_equal True | ||
((case_insensitive '\u00E9' '\u0065\u{301}') == 0) . should_equal True | ||
|
||
Test.specify "can compare custom types" <| | ||
((default_comparator (Ord 1) (Ord 0)) < 0) . should_equal True | ||
((default_comparator (Ord 1) (Ord 1)) == 0) . should_equal True | ||
|
||
Test.specify "should fail gracefully for incomparable items" <| | ||
(default_comparator 1 True).should_fail_with Vector.Incomparable_Values_Error | ||
(default_comparator (No_Ord 1) (No_Ord 2)).should_fail_with Vector.Incomparable_Values_Error | ||
|
||
main = Test.Suite.run_main here.spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters