]> mj.ucw.cz Git - eval.git/commitdiff
Added unit tests for io and tokenizer modules.
authorMartin Mares <mj@ucw.cz>
Sun, 18 Nov 2007 19:00:46 +0000 (20:00 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 18 Nov 2007 19:00:46 +0000 (20:00 +0100)
judge/Makefile
judge/io.t [new file with mode: 0644]
judge/test-tok.c
judge/token.t [new file with mode: 0644]

index c9ddb07b3e9451d57c91b339a8fe2521a153b476..ccb9838e585e7a2591f9a61267e0ec4db7a25bdc 100644 (file)
@@ -13,8 +13,16 @@ judge-tok: LDLIBS+=-lm
 judge-shuff: judge-shuff.o $(JLIB)
 filter-cmt: filter-cmt.o $(JLIB)
 
+tests: $(addsuffix .test,io token)
+io.test: test-io
+token.test: test-tok
+
+%.test: %.t tester
+       ./tester $<
+
 clean::
        rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core`
        rm -f test-io test-tok judge-tok filter-cmt
+       rm -rf tmp
 
 .PHONY: all clean distclean
diff --git a/judge/io.t b/judge/io.t
new file mode 100644 (file)
index 0000000..ed9f46a
--- /dev/null
@@ -0,0 +1,7 @@
+# Test cases for io.c
+
+Run:   ./test-io
+In:    abc
+       def
+Out:   abc
+       def
index 92303bb06b8c202b8cbac100f9db2093198fc5f5..8927e05f95710c9501749dcdd19f06b5f86d8394 100644 (file)
@@ -1,26 +1,47 @@
 #include <stdio.h>
+#include <string.h>
+#include <getopt.h>
 
 #include "judge.h"
 
-int main(void)
+int main(int argc, char **argv)
 {
   struct stream *i = sopen_fd("stdin", 0);
 
   struct tokenizer t;
   tok_init(&t, i);
-  // t.maxtoken = 1000;
-  t.flags = TF_REPORT_LINES;
+
+  int opt, verbose = 0;
+  while ((opt = getopt(argc, argv, "lsv")) >= 0)
+    switch (opt)
+      {
+      case 'l':
+       t.flags = TF_REPORT_LINES;
+       break;
+      case 's':
+       t.maxsize = 16;
+       break;
+      case 'v':
+       verbose++;
+       break;
+      default:
+       return 42;
+      }
+
   char *tok;
   while (tok = get_token(&t))
     {
       printf("<%s>", tok);
 #define T(f, type, fmt) { type x; if (to_##f(&t, &x)) printf(" = " #f " " fmt, x); }
-      T(int, int, "%d");
-      T(uint, unsigned int, "%u");
-      T(long, long int, "%ld");
-      T(ulong, unsigned long int, "%lu");
-      T(double, double, "%f");
-      T(long_double, long double, "%Lf");
+      if (verbose)
+       {
+         T(int, int, "%d");
+         T(uint, unsigned int, "%u");
+         T(long, long int, "%ld");
+         T(ulong, unsigned long int, "%lu");
+         T(double, double, "%f");
+         T(long_double, long double, "%Lf");
+       }
 #undef T
       putchar('\n');
     }
diff --git a/judge/token.t b/judge/token.t
new file mode 100644 (file)
index 0000000..4f4aa2e
--- /dev/null
@@ -0,0 +1,98 @@
+# Test cases for token.c
+# BEWARE: This file contains strange spacing (trailing spaces etc.), which is vital.
+# Please edit carefully.
+
+# A simple test case with several spaces
+Name:  std
+Run:   ./test-tok
+In:       abc   
+       10  20   30
+Out:   <abc>
+       <10>
+       <20>
+       <30>
+
+# The same test case in line mode
+Name:  std-l
+Run:   ./test-tok -l
+In:       abc   
+       10  20   30
+Out:   <abc>
+       <>
+       <10>
+       <20>
+       <30>
+       <>
+
+# An unterminated line
+Name:  unterm
+Run:   tr -d '\n' | ./test-tok
+In:    abc
+Out:   <abc>
+
+# An unterminated line in line mode
+Name:  unterm-l
+Run:   tr -d '\n' | ./test-tok -l
+In:    abc
+Out:   <abc>
+
+# Small token size limit, but fits
+Name:  big1
+Run:   ./test-tok -s
+In:    abcdefghijklmnop
+Out:   <abcdefghijklmnop>
+
+# Small token size limit, does not fit
+Name:  big2
+Run:   ./test-tok -s
+In:    abcdefghijklmnopq
+Exit:  1
+
+# Testing parsers
+Name:  parse1
+Run:   ./test-tok -vl
+In:    abcdef
+       0 5 -5
+Out:   <abcdef>
+       <>
+       <0> = int 0 = uint 0 = long 0 = ulong 0 = double 0.000000 = long_double 0.000000
+       <5> = int 5 = uint 5 = long 5 = ulong 5 = double 5.000000 = long_double 5.000000
+       <-5> = int -5 = long -5 = double -5.000000 = long_double -5.000000
+       <>
+
+# More parsing: integer extremes
+Name:  parse2
+Run:   ./test-tok -v
+In:    -2147483647 2147483647
+       -2147483648 2147483648
+       -4294967295 4294967295
+       -4294967296 4294967296
+Out:   <-2147483647> = int -2147483647 = long -2147483647 = double -2147483647.000000 = long_double -2147483647.000000
+       <2147483647> = int 2147483647 = uint 2147483647 = long 2147483647 = ulong 2147483647 = double 2147483647.000000 = long_double 2147483647.000000
+       <-2147483648> = int -2147483648 = long -2147483648 = double -2147483648.000000 = long_double -2147483648.000000
+       <2147483648> = uint 2147483648 = ulong 2147483648 = double 2147483648.000000 = long_double 2147483648.000000
+       <-4294967295> = double -4294967295.000000 = long_double -4294967295.000000
+       <4294967295> = uint 4294967295 = ulong 4294967295 = double 4294967295.000000 = long_double 4294967295.000000
+       <-4294967296> = double -4294967296.000000 = long_double -4294967296.000000
+       <4294967296> = double 4294967296.000000 = long_double 4294967296.000000
+
+# More parsing: floating point numbers
+Name:  parse3
+In:    1000000000
+       0. .0 .
+       0 +0 -0
+       +5 -5
+       +1e+5 -1e-5
+       1e+99999
+Out:   <1000000000> = int 1000000000 = uint 1000000000 = long 1000000000 = ulong 1000000000 = double 1000000000.000000 = long_double 1000000000.000000
+       <0.> = double 0.000000 = long_double 0.000000
+       <.0> = double 0.000000 = long_double 0.000000
+       <.>
+       <0> = int 0 = uint 0 = long 0 = ulong 0 = double 0.000000 = long_double 0.000000
+       <+0> = int 0 = uint 0 = long 0 = ulong 0 = double 0.000000 = long_double 0.000000
+       <-0> = int 0 = long 0 = double -0.000000 = long_double -0.000000
+       <+5> = int 5 = uint 5 = long 5 = ulong 5 = double 5.000000 = long_double 5.000000
+       <-5> = int -5 = long -5 = double -5.000000 = long_double -5.000000
+       <+1e+5> = double 100000.000000 = long_double 100000.000000
+       <-1e-5> = double -0.000010 = long_double -0.000010
+       <1e+99999>