Skip to content

Instantly share code, notes, and snippets.

@drkameleon
Created January 10, 2023 16:33
Show Gist options
  • Save drkameleon/3f69c236050636269ad40d868faeb156 to your computer and use it in GitHub Desktop.
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)
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]
@drkameleon
Copy link
Author

Output:

------------------------------------------------------------------------------------------
test array: [uno dos tres Uno perversión ábaco abismo aberración] 
test dictionary: [a:uno b:dos c:tres d:Uno e:perversión f:ábaco g:abismo h:aberración] 
------------------------------------------------------------------------------------------

▸ TESTING: [sort] for values: FALSE -> OK

▸ TESTING: [sort] for values: TRUE -> OK


▸ TESTING: [sort .as: 'es] for values: FALSE -> OK

▸ TESTING: [sort .as: 'es] for values: TRUE -> OK


▸ TESTING: [sort .sensitive] for values: FALSE -> OK

▸ TESTING: [sort .sensitive] for values: TRUE -> OK


▸ TESTING: [sort .sensitive .as: 'es] for values: FALSE -> OK

▸ TESTING: [sort .sensitive .as: 'es] for values: TRUE -> OK


▸ TESTING: [sort .descending] for values: FALSE -> OK

▸ TESTING: [sort .descending] for values: TRUE -> OK


▸ TESTING: [sort .descending .as: 'es] for values: FALSE -> OK

▸ TESTING: [sort .descending .as: 'es] for values: TRUE -> OK


▸ TESTING: [sort .descending .sensitive] for values: FALSE -> OK

▸ TESTING: [sort .descending .sensitive] for values: TRUE -> OK


▸ TESTING: [sort .descending .sensitive .as: 'es] for values: FALSE -> OK

▸ TESTING: [sort .descending .sensitive .as: 'es] for values: TRUE -> OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment