eschulte pushed a commit to branch go in repository elpa. commit 0580b00a3d1228d9b48e22789f20cc5b86c7123b Author: Eric Schulte <eric.schu...@gmx.com> Date: Tue May 22 11:05:31 2012 -0400
passing all tests --- sgf-board.el | 6 +++- sgf-tests.el | 82 +++++++++++++++++++++++++++------------------------------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/sgf-board.el b/sgf-board.el index a8d639e..caf6360 100644 --- a/sgf-board.el +++ b/sgf-board.el @@ -140,11 +140,15 @@ (set (make-local-variable 'sgf-sgf) game) (set (make-local-variable 'sgf-index) '(0)) ;; TODO: this shouldn't be required - (unless (tree-equal sgf-index '(0)) (setq sgf-index '(0))) + (unless (tree-equal sgf-index '(0)) + (setq sgf-index '(0)) + (setf (car sgf-index) 0)) (let* ((root (sgf-ref sgf-sgf sgf-index)) (name (or (aget root :GN) (aget root :EV))) (size (or (aget root :S) (aget root :SZ) + (unless (tree-equal sgf-index '(0)) + (error "sgf: bad index %S" sgf-index)) (error "sgf: game has no associated size")))) (when name (rename-buffer name 'unique)) (set (make-local-variable 'sgf-board) (make-board size)) diff --git a/sgf-tests.el b/sgf-tests.el index 47a48d3..d1e3a8c 100644 --- a/sgf-tests.el +++ b/sgf-tests.el @@ -122,6 +122,7 @@ `(let* ((sgf (sgf2el-file-to-el ,file)) (buffer (display-sgf sgf))) (unwind-protect (with-current-buffer buffer ,@body) + (set-default 'sgf-index '(0)) (should (kill-buffer buffer))))) (def-edebug-spec parse-many (file body)) @@ -138,47 +139,40 @@ (should (= points-length (length (assoc :points (sgf-ref sgf '(0))))))))) -;; (ert-deftest sgf-neighbors () -;; (let ((board (make-board 19))) -;; (should (= 2 (length (neighbors board 0)))) -;; (should (= 2 (length (neighbors board (length board))))) -;; (should (= 4 (length (neighbors board (/ (length board) 2))))) -;; (should (= 3 (length (neighbors board 1)))))) - -;; (ert-deftest sgf-singl-stone-capture () -;; (flet ((counts () (cons (stones-for local-board :b) -;; (stones-for local-board :w)))) -;; (with-sgf-file "sgf-files/1-capture.sgf" -;; (right 3) (should (tree-equal (counts) '(2 . 0)))))) - -;; (ert-deftest sgf-remove-dead-stone-ko () -;; (flet ((counts () (cons (stones-for local-board :b) -;; (stones-for local-board :w)))) -;; (with-sgf-file "sgf-files/ko.sgf" -;; (should (tree-equal (counts) '(0 . 0))) (right 1) -;; (should (tree-equal (counts) '(1 . 0))) (right 1) -;; (should (tree-equal (counts) '(1 . 1))) (right 1) -;; (should (tree-equal (counts) '(2 . 1))) (right 1) -;; (should (tree-equal (counts) '(2 . 2))) (right 1) -;; (should (tree-equal (counts) '(3 . 2))) (right 1) -;; (should (tree-equal (counts) '(2 . 3))) (right 1) -;; (should (tree-equal (counts) '(3 . 2))) (right 1) -;; (should (tree-equal (counts) '(2 . 3)))))) - -;; (ert-deftest sgf-two-stone-capture () -;; (flet ((counts () (cons (stones-for local-board :b) -;; (stones-for local-board :w)))) -;; (with-sgf-file "sgf-files/2-capture.sgf" -;; (right 8) (should (tree-equal (counts) '(6 . 0)))))) - -;; (ert-deftest sgf-parse-empty-properties () -;; (with-sgf-file "sgf-files/w-empty-properties.sgf" -;; (should (remove-if-not (lambda (prop) -;; (let ((val (cdr prop))) -;; (and (sequencep val) (= 0 (length val))))) -;; (car sgf))))) - -;; (ert-deftest sgf-paren-matching () -;; (let ((str "(a (b) [c \\] ) ] d)")) -;; (should (= (closing-paren str) (length str))) -;; (should (= (closing-paren str 3) 6)))) +(ert-deftest sgf-neighbors () + (let ((board (make-board 19))) + (should (= 2 (length (neighbors board 0)))) + (should (= 2 (length (neighbors board (length board))))) + (should (= 4 (length (neighbors board (/ (length board) 2))))) + (should (= 3 (length (neighbors board 1)))))) + +(defun stone-counts () + (cons (stones-for sgf-board :B) + (stones-for sgf-board :W))) + +(ert-deftest sgf-singl-stone-capture () + (with-sgf-file "sgf-files/1-capture.sgf" + (right 3) (should (tree-equal (stone-counts) '(2 . 0))))) + +(ert-deftest sgf-remove-dead-stone-ko () + (with-sgf-file "sgf-files/ko.sgf" + (should (tree-equal (stone-counts) '(0 . 0))) (right 1) + (should (tree-equal (stone-counts) '(1 . 0))) (right 1) + (should (tree-equal (stone-counts) '(1 . 1))) (right 1) + (should (tree-equal (stone-counts) '(2 . 1))) (right 1) + (should (tree-equal (stone-counts) '(2 . 2))) (right 1) + (should (tree-equal (stone-counts) '(3 . 2))) (right 1) + (should (tree-equal (stone-counts) '(2 . 3))) (right 1) + (should (tree-equal (stone-counts) '(3 . 2))) (right 1) + (should (tree-equal (stone-counts) '(2 . 3))))) + +(ert-deftest sgf-two-stone-capture () + (with-sgf-file "sgf-files/2-capture.sgf" + (right 8) (should (tree-equal (stone-counts) '(6 . 0))))) + +(ert-deftest sgf-parse-empty-properties () + (with-sgf-file "sgf-files/w-empty-properties.sgf" + (should (remove-if-not (lambda (prop) + (let ((val (cdr prop))) + (and (sequencep val) (= 0 (length val))))) + (car sgf)))))