Test a function: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1:
{{task|Testing}}{{omit from|BBC BASIC}}
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.
 
=={{header|ACL2}}==
Line 196:
assert(IsPalindrome("alice"));
}
</lang>
 
=={{header|Clojure}}==
<lang lisp>
(use 'clojure.test)
 
(deftest test-palindrome?
(is (= true (palindrome? "amanaplanacanalpanama")))
(is (= false (palindrome? "Test 1, 2, 3"))))
 
(run-tests)
</lang>
 
Line 286 ⟶ 275:
}
}</lang>
 
=={{header|Clojure}}==
<lang lisp>
(use 'clojure.test)
 
(deftest test-palindrome?
(is (= true (palindrome? "amanaplanacanalpanama")))
(is (= false (palindrome? "Test 1, 2, 3"))))
 
(run-tests)
</lang>
 
=={{header|Crystal}}==
Line 434:
 
</lang>
 
 
=={{header|F_Sharp|F#}}==
Line 454 ⟶ 453:
member x.Test02() =
Assert.IsFalse(palindrome "hello")</lang>
 
 
=={{header|Factor}}==
Line 689 ⟶ 687:
}
}</lang>
 
 
=={{header|JavaScript}}==
Line 1,246 ⟶ 1,243:
let _ =
run_test_tt_main suite</lang>
 
 
 
=={{header|Oforth}}==
Line 1,359 ⟶ 1,354:
Files=1, Tests=24, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.02 cusr 0.00 csys = 0.05 CPU)
Result: FAIL</pre>
 
=={{header|Perl 6}}==
<lang perl6>use Test;
 
sub palin( Str $string) { so $string.lc.comb(/\w/) eq $string.flip.lc.comb(/\w/) }
 
my %tests =
'A man, a plan, a canal: Panama.' => True,
'My dog has fleas' => False,
"Madam, I'm Adam." => True,
'1 on 1' => False,
'In girum imus nocte et consumimur igni' => True,
'' => True,
;
 
plan %tests.elems;
 
for %tests.kv -> $test, $expected-result {
is palin($test), $expected-result,
"\"$test\" is {$expected-result??''!!'not '}a palindrome.";
}</lang>
 
Output:
<pre>1..6
ok 1 - "1 on 1" is not a palindrome.
ok 2 - "My dog has fleas" is not a palindrome.
ok 3 - "A man, a plan, a canal: Panama." is a palindrome.
ok 4 - "" is a palindrome.
ok 5 - "Madam, I'm Adam." is a palindrome.
ok 6 - "In girum imus nocte et consumimur igni" is a palindrome.</pre>
 
=={{header|PicoLisp}}==
Line 1,412 ⟶ 1,377:
 
:- end_tests(palindrome).</lang>
 
 
=={{header|PureBasic}}==
Line 1,443 ⟶ 1,407:
Assert(IsPalindrome(text1$), "Catching this would be a fail")
Assert(IsPalindrome(text2$), "Catching this is correct")</lang>
 
 
=={{header|Python}}==
Line 1,597 ⟶ 1,560:
(check-false (palindromb "potato")))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>use Test;
 
sub palin( Str $string) { so $string.lc.comb(/\w/) eq $string.flip.lc.comb(/\w/) }
 
my %tests =
'A man, a plan, a canal: Panama.' => True,
'My dog has fleas' => False,
"Madam, I'm Adam." => True,
'1 on 1' => False,
'In girum imus nocte et consumimur igni' => True,
'' => True,
;
 
plan %tests.elems;
 
for %tests.kv -> $test, $expected-result {
is palin($test), $expected-result,
"\"$test\" is {$expected-result??''!!'not '}a palindrome.";
}</lang>
 
Output:
<pre>1..6
ok 1 - "1 on 1" is not a palindrome.
ok 2 - "My dog has fleas" is not a palindrome.
ok 3 - "A man, a plan, a canal: Panama." is a palindrome.
ok 4 - "" is a palindrome.
ok 5 - "Madam, I'm Adam." is a palindrome.
ok 6 - "In girum imus nocte et consumimur igni" is a palindrome.</pre>
 
=={{header|Retro}}==
10,333

edits