summaryrefslogtreecommitdiff
path: root/chess-test.el
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 /chess-test.el
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.
Diffstat (limited to 'chess-test.el')
-rw-r--r--chess-test.el41
1 files changed, 27 insertions, 14 deletions
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)))))