(use-modules (srfi srfi-64)
             ((coords-operations) #:prefix cm:))

(test-begin "coords-operations-test")


;; todo: write tests for: index->board-coords
;; todo: make caught exceptions more specific
(test-group
 "index->coords-test"
 #;(test-error [[test-name] error-type] test-expr)
 (test-error "index out of bounds" #t
             (cm:index->coords 81 9 9))
 (test-error "index out of bounds" #t
             (cm:index->coords 81 10 8))
 (test-error "index out of bounds" #t
             (cm:index->coords 80 8 10))
 (test-error "index out of bounds" #t
             (cm:index->coords 6 3 2))
 (test-error "index out of bounds" #t
             (cm:index->coords 7 3 2))
 (test-error "index out of bounds" #t
             (cm:index->coords 1 1 1))
 (test-error "negative number of rows" #t
             (cm:index->coords 81 -1 9))
 (test-error "negative number of cols" #t
             (cm:index->coords 81 9 -1))
 (test-error "negative number of rows and cols" #t
             (cm:index->coords 81 -4 -4))
 (test-error "negative index" #t
             (cm:index->coords -70 9 9))

 (test-equal (cm:index->coords 0 1 1) (cons 0 0))
 (test-equal (cm:index->coords 40 9 9) (cons 4 4))
 (test-equal (cm:index->coords 999 10 100) (cons 9 99))
 (test-equal (cm:index->coords 14 5 4) (cons 3 2))
 (test-equal (cm:index->coords 543 55 10) (cons 54 3))
 (test-equal (cm:index->coords 74 10 10) (cons 7 4)))

(test-group
 "coords->index-test"
 (test-error "index out of bounds" #t (cm:coords->index 8 7 8 8))
 (test-error "index out of bounds" #t (cm:coords->index 7 8 8 8))
 (test-error "index out of bounds" #t (cm:coords->index 8 8 8 8))
 (test-error "index out of bounds" #t (cm:coords->index 0 -1 8 8))
 (test-error "index out of bounds" #t (cm:coords->index -1 0 8 8))
 (test-equal (cm:coords->index 7 7 8 8) 63)
 (test-equal (cm:coords->index 6 7 8 8) 55)
 (test-equal (cm:coords->index 4 3 9 9) 39)
 (test-equal (cm:coords->index 3 6 7 7) 27)
 (test-equal (cm:coords->index 0 0 10 9) 0)
 (test-equal (cm:coords->index 0 1 9 10) 1)
 (test-equal (cm:coords->index 1 0 9 10) 10))

(test-end "coords-operations-test")
