JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
get rest of unit tests using new(ish) api
authorJason Woofenden <jason@jasonwoof.com>
Mon, 25 Apr 2011 11:10:20 +0000 (07:10 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 25 Apr 2011 11:10:20 +0000 (07:10 -0400)
unit_tests/db.php
unit_tests/encode.php
unit_tests/format.php
unit_tests/misc.php

index f6b5325..569ed0e 100644 (file)
 
 require_once('code/wfpl/db.php');
 
-# returns number of errors
-function test_db_reposition() {
-       $table = 'reposition';
-       $errors = 0;
+function test_db_reposition($table = 'reposition') {
        db_delete($table);
        db_insert($table, 'ord', '2');
        $a = db_auto_id();
@@ -72,21 +69,18 @@ function test_db_reposition() {
                db_update($table, 'ord', $ord, 'where id=%i', $before[$src]);
                $after = db_get_column($table, 'id', 'order by ord');
                $ords = db_get_column($table, 'ord', 'order by ord');
-               if($before[$c1] != $after[0] || $before[$c2] != $after[1] || $before[$c3] != $after[2]) {
-                       message("db_reposition($before[$src], $dest) did: ($before[0]:$before_ords[0], $before[1]:$before_ords[1], $before[2]:$before_ords[2]) -> ($after[0]:$ords[0]), $after[1]:$ords[1], $after[2]:$ords[2])");
-                       $errors += 1;
+               $message = "db_reposition($before[$src], $dest) did: ($before[0]:$before_ords[0], $before[1]:$before_ords[1], $before[2]:$before_ords[2]) -> ($after[0]:$ords[0]), $after[1]:$ords[1], $after[2]:$ords[2])";
+               if($before[$c1] == $after[0] && $before[$c2] == $after[1] && $before[$c3] == $after[2]) {
+                       unit_test_passed($message);
+               } else {
+                       unit_test_failed($message);
                }
                $before = $after;
                $before_ords = $ords;
        }
-
-       return $errors;
 }
 
-# returns number of errors
 function db_unit_tests_main() {
        db_connect('test');
-       $errors = 0;
-       $errors += test_db_reposition();
-       return $errors;
+       test_db_reposition();
 }
index 615a898..3703c3e 100644 (file)
@@ -23,7 +23,6 @@
 
 require_once('code/wfpl/encode.php');
 
-# returns number of errors
 function _test_encode_pulled($field, $value, $correct) {
        unit_test_func('enc_pulled', $value, $field, $correct);
 }
index 9264418..2e6ecb6 100644 (file)
@@ -70,7 +70,6 @@ function _test_format_int($arg, $correct) {
        unit_test_func('format_decimal', $arg, $correct);
 }
 
-# returns number of errors
 function test_format_misc() {
        unit_test_func('format_caption', 'something', 'Something');
        unit_test_func('format_caption', 'two_words', 'Two Words');
index 0582649..1125ed1 100644 (file)
 
 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",
+               4, "4th",
+               5, "5th",
+               6, "6th",
+               7, "7th",
+               8, "8th",
+               9, "9th",
+               10, "10th",
+               11, "11th",
+               12, "12th",
+               13, "13th",
+               14, "14th",
+               15, "15th",
+               16, "16th",
+               17, "17th",
+               18, "18th",
+               19, "19th",
+               20, "20th",
+               21, "21st",
+               22, "22nd",
+               23, "23rd",
+               24, "24th",
+               25, "25th",
+               26, "26th",
+               27, "27th",
                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;
-               }
+               unit_test_func('ordinalize', $arg, $correct);
        }
-
-       return $errors;
 }
 
-# returns number of errors
 function misc_unit_tests_main() {
-       $errors = 0;
-       $errors += test_ordinalize();
-       return $errors;
+       test_ordinalize();
 }