X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=unit_tests%2Fmisc.php;fp=unit_tests%2Fmisc.php;h=05826494362f13e38578b79a4ef9dcb6e52fd809;hb=4701b125596e7f9da31a9f0954f22b018a4994cf;hp=0000000000000000000000000000000000000000;hpb=b06120b7272f31b715fdec90f12e1a02956cdca2;p=wfpl.git diff --git a/unit_tests/misc.php b/unit_tests/misc.php new file mode 100644 index 0000000..0582649 --- /dev/null +++ b/unit_tests/misc.php @@ -0,0 +1,56 @@ +. + + +# This file contains tests for functions in code/wfpl/misc.php +# +# See code/wfpl/unit_tests.php for details on how to run or create tests + + +require_once('code/wfpl/misc.php'); + +# returns number of errors +function test_ordinalize() { + $errors = 0; + + $tests = array( + '', '', + 0, "0th", + 1, "1st", + 2, "2nd", + 3, "3rd", + 111, "111th", + "62", "62nd"); + for($i = 0; $i < count($tests); $i += 2) { + $arg = $tests[$i]; + $correct = $tests[$i + 1]; + $ret = ordinalize($arg); + if($ret !== $correct) { + message("ordinalize($arg) returned \"$ret\" instead of \"$correct\""); + $errors += 1; + } + } + + return $errors; +} + +# returns number of errors +function misc_unit_tests_main() { + $errors = 0; + $errors += test_ordinalize(); + return $errors; +}