Test a function: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Added Odin variant) |
||
Line 1,537: | Line 1,537: | ||
let _ = |
let _ = |
||
run_test_tt_main suite</syntaxhighlight> |
run_test_tt_main suite</syntaxhighlight> |
||
=={{header|Odin}}== |
|||
<syntaxhighlight lang="odin">// To run execute: odin test Test_a_function.odin -file |
|||
package main |
|||
import "core:testing" |
|||
import "core:strings" |
|||
is_palindrome :: proc(s: string) -> bool { |
|||
return s == strings.reverse(s) |
|||
} |
|||
@(test) |
|||
test_is_palindrome :: proc(t: ^testing.T) { |
|||
palindromes := []string{"", "a", "aa", "aba", "racecar"} |
|||
for i in palindromes { |
|||
if !is_palindrome(i) { |
|||
testing.errorf(t, "is_palindrome returned false on palindrome %s", i) |
|||
} |
|||
} |
|||
non_palindromes := []string{"ab", "abaa", "aaba", "abcdba"} |
|||
for i in non_palindromes { |
|||
if is_palindrome(i) { |
|||
testing.errorf(t, "is_palindrome returned true on non-palindrome %s", i) |
|||
} |
|||
} |
|||
}</syntaxhighlight> |
|||
=={{header|Oforth}}== |
=={{header|Oforth}}== |