JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added ordinalize() and tests for it
[wfpl.git] / unit_tests / misc.php
1 <?php
2
3 #  Copyright (C) 2009 Jason Woofenden
4 #
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 # This file contains tests for functions in code/wfpl/misc.php
20 #
21 # See code/wfpl/unit_tests.php for details on how to run or create tests
22
23
24 require_once('code/wfpl/misc.php');
25
26 # returns number of errors
27 function test_ordinalize() {
28         $errors = 0;
29
30         $tests = array(
31                 '', '',
32                 0, "0th",
33                 1, "1st",
34                 2, "2nd",
35                 3, "3rd",
36                 111, "111th",
37                 "62", "62nd");
38         for($i = 0; $i < count($tests); $i += 2) {
39                 $arg = $tests[$i];
40                 $correct = $tests[$i + 1];
41                 $ret = ordinalize($arg);
42                 if($ret !== $correct) {
43                         message("ordinalize($arg) returned \"$ret\" instead of \"$correct\"");
44                         $errors += 1;
45                 }
46         }
47
48         return $errors;
49 }
50
51 # returns number of errors
52 function misc_unit_tests_main() {
53         $errors = 0;
54         $errors += test_ordinalize();
55         return $errors;
56 }