summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-01 01:06:09 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-01 01:06:41 -0400
commita2f9b42f27cda7b00084d8c7cfbcb7d7bcbc0c9f (patch)
tree20bc2d60ae6f32a4bf567924f6388d3187e11103
parent8ec9434a1a5e345077d6980e784d47f36483a224 (diff)
Several improvements to how tests are run.
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.
-rw-r--r--Makefile.am10
-rw-r--r--chess-test.el41
2 files changed, 32 insertions, 19 deletions
diff --git a/Makefile.am b/Makefile.am
index 5d0ce08..711161b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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)
diff --git a/chess-test.el b/chess-test.el
index de008a8..228fcfa 100644
--- a/chess-test.el
+++ b/chess-test.el
@@ -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)
@@ -41,18 +44,28 @@
;; 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)))))