/* Test a function (Rosetta code) in Picat. """ Using a well known testing specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language. """ Note: Picat don't have a built-in test framework, but it's quite easy to write assert/assert_failure predicates (for both predicates and functions). This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go => % testing predicates (with call/1) S = "ablewasiereisawelba", assert("test1",$is_palindrome(S)), assert_failure("test2",$is_palindrome(S)), S := "un" ++ S, assert("test3",$is_palindrome(S)), assert_failure("test4",$is_palindrome(S)), % functions (with apply/1) assert("test5",$2+2, 4), assert_failure("test6",$2+2, 5), assert("test7",$member(1,1..10)), assert_failure("test8",$member(11,1..10)), nl. is_palindrome(S) => S2 = strip2(S), S2 = S2.reverse(). strip2(S) = [C : C in S.to_lowercase(), membchk(C, "abcdefghijklmnopqrstuvwxyz")]. assert(Name, A) => println(Name ++ ": " ++ cond(call(A), "ok", "not ok")). assert_failure(Name, A) => println(Name ++ ": " ++ cond(not call(A), "ok", "not ok")). assert(Name, A, Expected) => println(Name ++ ": " ++ cond(apply(A) == Expected, "ok", "not ok")). assert_failure(Name, A, Expected) => println(Name ++ ": " ++ cond(apply(A) != Expected , "ok", "not ok")).