store-tests.ss
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  ClassicJava: an implementation of the ClassicJava programming language
;;  store-tests.ss: tests for the store module.
;;  Copyright (C) 2005  Richard Cobbe
;;
;;  This library is free software; you can redistribute it and/or modify it
;;  under the terms of the GNU Lesser General Public License as published by
;;  the Free Software Foundation; either version 2.1 of the License, or (at
;;  your option) any later version.
;;
;;  This library is distributed in the hope that it will be useful, but WITHOUT
;;  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
;;  License for more details.
;;
;;  You should have received a copy of the GNU Lesser General Public License
;;  along with this library; if not, write to the Free Software Foundation,
;;  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(module store-tests mzscheme

  (require "test.ss"
           "store.ss"
           (planet "test.ss" ("schematics" "schemeunit.plt" 1 1))
           (planet "util.ss" ("schematics" "schemeunit.plt" 1 1)))

  (provide store-tests)

  (define store-tests
   (make-test-suite "store ADT tests"
     (make-test-case "deref empty store"
       (assert-false (store-ref empty-store 3 (lambda () #f))))

     (make-test-case "allocate into empty store"
       (mv-assert equal?
                  (store-alloc empty-store 'foo)
                  0
                  (store [0 'foo])))

     (make-test-case "allocate into bigger store"
       (mv-assert equal?
                  (store-alloc (store [0 'foo] [1 'bar]) 'baz)
                  2
                  (store [2 'baz] [0 'foo] [1 'bar])))

     (make-test-case "deref from full store"
       (assert-eq? (store-ref (store [0 'foo] [1 'bar]) 1) 'bar))

     (make-test-case "deref bogus address"
       (assert-false (store-ref (store [0 'foo] [1 'bar]) 3 (lambda () #f))))

     (make-test-case "deref bogus address; default fk"
       (assert-exn exn:fail:contract?
                   (lambda () (store-ref (store [0 'foo] [1 'bar]) 3))))

     (make-test-case "update existing address"
       (assert-equal? (store-update (store [0 'foo] [1 'bar]) 1 'quux)
                      (store [0 'foo] [1 'quux])))

     (make-test-case "update bogus address"
       (assert-exn exn:fail:contract?
                   (lambda ()
                     (store-update (store [0 'foo] [1 'bar]) 3 'quux)))))))