Test a function: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1: Line 1:
{{task|Testing}}{{omit from|BBC BASIC}}
{{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.
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}}==
=={{header|ACL2}}==
Line 196: Line 196:
assert(IsPalindrome("alice"));
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>
</lang>


Line 286: Line 275:
}
}
}</lang>
}</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}}==
=={{header|Crystal}}==
Line 434: Line 434:


</lang>
</lang>



=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 454: Line 453:
member x.Test02() =
member x.Test02() =
Assert.IsFalse(palindrome "hello")</lang>
Assert.IsFalse(palindrome "hello")</lang>



=={{header|Factor}}==
=={{header|Factor}}==
Line 689: Line 687:
}
}
}</lang>
}</lang>



=={{header|JavaScript}}==
=={{header|JavaScript}}==
Line 1,246: Line 1,243:
let _ =
let _ =
run_test_tt_main suite</lang>
run_test_tt_main suite</lang>




=={{header|Oforth}}==
=={{header|Oforth}}==
Line 1,359: Line 1,354:
Files=1, Tests=24, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.02 cusr 0.00 csys = 0.05 CPU)
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>
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}}==
=={{header|PicoLisp}}==
Line 1,412: Line 1,377:


:- end_tests(palindrome).</lang>
:- end_tests(palindrome).</lang>



=={{header|PureBasic}}==
=={{header|PureBasic}}==
Line 1,443: Line 1,407:
Assert(IsPalindrome(text1$), "Catching this would be a fail")
Assert(IsPalindrome(text1$), "Catching this would be a fail")
Assert(IsPalindrome(text2$), "Catching this is correct")</lang>
Assert(IsPalindrome(text2$), "Catching this is correct")</lang>



=={{header|Python}}==
=={{header|Python}}==
Line 1,597: Line 1,560:
(check-false (palindromb "potato")))
(check-false (palindromb "potato")))
</lang>
</lang>

=={{header|Raku}}==
(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}}==
=={{header|Retro}}==