diff options
Diffstat (limited to 'chess-test.el')
| -rw-r--r-- | chess-test.el | 41 |
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))))) |
