Created
January 10, 2023 16:33
-
-
Save drkameleon/3f69c236050636269ad40d868faeb156 to your computer and use it in GitHub Desktop.
Test sorting (in effect, test that sorting a Block and a Dictionary yields the same results; either in terms of the expected keys, or values)
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
labels: ["a", "b", "c", "d", "e", "f", "g", "h"] | |
items: ["uno", "dos", "tres", "Uno", "perversión", "ábaco", "abismo", "aberración"] | |
dic: function []-> #.raw flatten @[couple labels items] | |
revdic: function []-> #.raw flatten @[couple items labels] | |
verify: function [what][ | |
toDo: [sort] ++ what | |
bl: do toDo ++ [items] | |
checkValues?: true? attr 'values | |
prints ["▸ TESTING:" as.code toDo "for values:" upper to :string checkValues?] | |
di: do toDo ++ ((checkValues?)? -> [.values dic] -> [revdic]) | |
checkValues? ? [ | |
(bl = values di) ? [ | |
print color #green "-> OK" | |
] [ | |
print color #red "-> ERROR" | |
print ["\texpected:" bl] | |
print ["\tgot:" values di] | |
] | |
] [ | |
(bl = keys di) ? [ | |
print color #green "-> OK" | |
] [ | |
print color #red "-> ERROR" | |
print ["\texpected:" bl] | |
print ["\tgot:" keys di] | |
] | |
] | |
print "" | |
] | |
verifyAll: function [additional][ | |
verify additional | |
verify.values additional | |
print "" | |
] | |
print repeat "-" 90 | |
print ["test array:" items] | |
print ["test dictionary:" dic] | |
print repeat "-" 90 | |
print "" | |
verifyAll [] | |
verifyAll [.as: 'es] | |
verifyAll [.sensitive] | |
verifyAll [.sensitive.as: 'es] | |
verifyAll [.descending] | |
verifyAll [.descending.as: 'es] | |
verifyAll [.descending.sensitive] | |
verifyAll [.descending.sensitive.as: 'es] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: