]> code.delx.au - gnu-emacs-elpa/commitdiff
Several improvements to how tests are run.
authorJohn Wiegley <johnw@newartisans.com>
Mon, 1 Sep 2008 05:06:09 +0000 (01:06 -0400)
committerJohn Wiegley <johnw@newartisans.com>
Mon, 1 Sep 2008 05:06:41 +0000 (01:06 -0400)
First, if the user hasn't downloaded the monster test database, we just run a
simple test of 400 historical games.  Second, you can specify the variables
START and COUNT on the command line, for running just a part of the huge
database.

Makefile.am
chess-test.el

index 5d0ce089888aa54d116260895417fcdcc9804aa3..711161b880a31d9d2d9d8bf9fec19a1050412068 100644 (file)
@@ -67,12 +67,12 @@ chess-eco.fen: chess-eco.pos chess-eco.el
                chess-eco.pos chess-eco.fen
 
 TESTS   = chess-test
-DATABASE = test/largedb
-START   =
-FINISH  =
+DATABASE = $(shell test -r test/largedb.sg3 && echo test/largedb || echo test/historic.pgn)
+START   = $(shell test -r test/largedb.sg3 && perl -e 'print int(rand(4000000)), "\n";' || echo 1)
+COUNT   = 100000
 
-chess-test: Makefile
-       echo "$(EMACS) -batch -L $(srcdir) -l chess-test.el -f chess-test '$(DATABASE)' $(START) $(FINISH)" > $@
+chess-test:
+       echo "$(EMACS) -batch -L $(srcdir) -l chess-test.el -f chess-test '$(DATABASE)' $(START) $(COUNT); rm -f $(top_builddir)/chess-test" > $@
        chmod u+x $@
 
 TAGS: $(dist_lisp_LISP)
index de008a8ff3ed83183847e0ecc2e1f57a190a6c7d..228fcfa49661be94942c78ce62c98951b9a45ce4 100644 (file)
@@ -6,30 +6,33 @@
 (require 'chess-database)
 (require 'chess-game)
 
-(defun chess-test (&optional file start finish)
+(defun chess-test (&optional file start count)
   (unless file
     (setq file (nth 0 command-line-args-left)))
   (unless start
-    (setq start (string-to-number (nth 1 command-line-args-left))))
-  (unless finish
-    (setq finish (string-to-number (nth 2 command-line-args-left))))
+    (setq start (ignore-errors
+                 (string-to-number (nth 1 command-line-args-left)))))
+  (unless count
+    (setq count (ignore-errors
+                 (string-to-number (nth 2 command-line-args-left)))))
 
   (message "Opening chess database '%s'" file)
 
   (let ((database (chess-database-open file)))
     (if database
        (progn
-         (message "Running chess unit tests...")
+         (message "Running validation suite...")
          (condition-case err
-             (let* ((count (chess-database-count database))
+             (let* ((db-count (chess-database-count database))
                     (ply-count 0)
                     (index (if start
                                (max start 1)
                              1))
-                    (last-index (if finish
-                                    (min count finish)
-                                  count))
-                    (begin (current-time)))
+                    (last-index (if count
+                                    (min db-count (+ index count))
+                                  db-count))
+                    (begin (current-time))
+                    (read-count 0))
                (message "Testing legality of games in range [%d, %d):"
                         index last-index)
                (while (< index last-index)
                  ;; want to verify the final position and such.
                  (let ((game (chess-database-read database index)))
                    (when game
-                     (setq ply-count
+                     (setq read-count (1+ read-count)
+                           ply-count
                            (+ ply-count (length (chess-game-plies game))))
                      (if (= 0 (mod index 1000))
-                         (message "Read %d games: %d total plies (%.2f ply/sec)"
-                                  index ply-count
+                         (message "Read %d games (now at game %d): %d total plies (%.2f ply/sec)"
+                                  read-count index ply-count
                                   (/ (float ply-count)
                                      (float
                                       (time-to-seconds
                                        (subtract-time (current-time)
                                                       begin))))))))
                  (setq index (1+ index)))
-               (message "Running chess unit tests...done"))
+               (message "Read %d games (up to game %d): %d plies (%.2f ply/sec, %.2f seconds)"
+                        read-count index ply-count
+                        (/ (float ply-count)
+                           (float
+                            (time-to-seconds
+                             (subtract-time (current-time)
+                                            begin))))
+                        (time-to-seconds (subtract-time (current-time)
+                                                        begin)))
+               (message "Running validation suite...done"))
            (t
             (error "Failed to open chess database '%s'" file)))
          (chess-database-close database)))))