]> git.jsancho.org Git - bongodb.git/commitdiff
Testing
authorJavier Sancho <jsf@jsancho.org>
Sun, 7 Feb 2016 15:41:08 +0000 (16:41 +0100)
committerJavier Sancho <jsf@jsancho.org>
Sun, 7 Feb 2016 15:41:08 +0000 (16:41 +0100)
src/bongodb.scm
tests/sample.scm [new file with mode: 0644]

index c6b2571605ba23e3a9b4e1ef64a5796ea57760ba..3cffa48d5ce6f7280958a00d1abf04ece8acc50b 100644 (file)
@@ -1,4 +1,3 @@
-;;;
 ;;; BongoDB, an embedded document-based engine
 ;;; Copyright (C) 2016 by Javier Sancho Fernandez <jsf at jsancho dot org>
 ;;;
 ;;; BongoDB, an embedded document-based engine
 ;;; Copyright (C) 2016 by Javier Sancho Fernandez <jsf at jsancho dot org>
 ;;;
   #:use-module (ice-9 receive)
   #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-9)
   #:use-module (ice-9 receive)
   #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-9)
-  #:use-module (srfi srfi-9 gnu))
+  #:use-module (srfi srfi-9 gnu)
+  #:export (make-collection
+           collection?
+           count
+           insert
+           find))
 
 
 ;;; Collection Definition
 
 
 ;;; Collection Definition
 (define (make-collection)
   (make-collection-record vlist-null))
 
 (define (make-collection)
   (make-collection-record vlist-null))
 
+(define (count col)
+  (vlist-length (get-table col)))
+
 (set-record-type-printer! collection
   (lambda (record port)
     (format port
            "#<collection with ~a documents>"
 (set-record-type-printer! collection
   (lambda (record port)
     (format port
            "#<collection with ~a documents>"
-           (vlist-length (get-table record)))))
+           (count record))))
 
 
 ;;; Working with documents
 
 
 ;;; Working with documents
    (lambda (key value result) (assoc-set! result key value))
    '()
    vhash))
    (lambda (key value result) (assoc-set! result key value))
    '()
    vhash))
-
-
-;;; Testing
-
-(define (sample-test)
-  (let ((col (make-collection)))
-    (format #t "1 New collection: ~a~%" col)
-    (set! col (insert col '((a . 1) (b . 2)) '((a . 10) (b . 20)) '((a . 1) (b . "hello world"))))
-    (format #t "2 Insert 3 documents: ~a~%" col)
-    (format #t "3 Search (a . 1): ~a~%" (find col '((a . 1))))))
diff --git a/tests/sample.scm b/tests/sample.scm
new file mode 100644 (file)
index 0000000..047a751
--- /dev/null
@@ -0,0 +1,34 @@
+;;; BongoDB, an embedded document-based engine
+;;; Copyright (C) 2016 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program 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 General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+(use-modules (bongodb)
+            (srfi srfi-64))
+
+(test-begin "bongodb")
+
+; Definition
+(define col (make-collection))
+(test-assert (collection? col))
+
+; Insert
+(set! col (insert col '((a . 1) (b . 2)) '((a . 10) (b . 20)) '((a . 1) (b . "hello world"))))
+(test-eqv 3 (count col))
+
+; Search
+(test-eqv 2 (length (find col '((a . 1)))))
+
+(test-end "bongodb")