-
Notifications
You must be signed in to change notification settings - Fork 6
/
snooze-quick-find-test.ss
99 lines (82 loc) · 3.92 KB
/
snooze-quick-find-test.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#lang scheme/base
(require srfi/26/cut
(planet untyped/unlib:3/gen)
"snooze-api.ss"
"test-base.ss"
"core/core.ss"
"sql/sql.ss")
; Tests ----------------------------------------
; course
(define-values (jon garfield odie c1 c2 c3 c4 c5)
(values #f #f #f #f #f #f #f #f))
; test-suite
(define snooze-quick-find-tests
(test-suite "snooze-quick-find-tests"
#:before
(lambda ()
(recreate-test-tables)
(set! jon (save! (make-person "Jone")))
(set! garfield (save! (make-pet jon "Garfield")))
(set! odie (save! (make-pet jon "Odie")))
(save! (make-pet #f "TC"))
(set! c1 (save! (make-course 'course1 "Course 1" 1 0.1 #f (string->time-tai "2001-01-01 01:01:01") #f)))
(set! c2 (save! (make-course 'course2 "Course 2" 2 0.2 #t (string->time-tai "2002-02-02 02:02:02") #f)))
(set! c3 (save! (make-course 'course3 "Course 3" 3 0.3 #f (string->time-tai "2003-03-03 03:03:03") #f)))
(set! c4 (save! (make-course 'course4 "Course 4" 4 0.4 #t (string->time-tai "2004-04-04 04:04:04") #f)))
(set! c5 (save! (make-course 'course5 "Course 5" 5 0.5 #f (string->time-tai "2005-05-05 05:05:05") #f))))
#:after
drop-all-tables
(test-case "find-count #:active?"
(check-equal? (find-count-courses #:active? #t) 2)
(check-equal? (find-count-courses #:active? #f) 3))
(test-case "find-count #:owner"
(check-equal? (find-count-pets #:owner jon) 2)
(check-equal? (find-count-pets #:owner jon
#:order (sql-list (asc pet.name))
#:group (sql-list pet.name))
1))
(test-case "find-one #:guid"
(check-false (find-course #:guid #f))
(check-equal? (find-course #:guid c1) c1)
(check-equal? (find-course #:guid c2) c2))
(test-case "find-all #:active?"
(check-equal? (find-courses #:active? #t) (list c2 c4))
(check-equal? (find-courses #:active? #f) (list c1 c3 c5)))
(test-case "g:find #:active?"
(check-equal? (g:collect (g:courses #:active? #t)) (list c2 c4))
(check-equal? (g:collect (g:courses #:active? #f)) (list c1 c3 c5)))
(test-case "find-one #:active? and #:value"
(check-equal? (find-course #:active? #f #:value 1) c1)
(check-equal? (find-course #:active? #f #:value 2) #f)
(check-equal? (find-course #:active? #f #:value 3) c3)
(check-equal? (find-course #:active? #f #:value 4) #f)
(check-equal? (find-course #:active? #t #:value 1) #f)
(check-equal? (find-course #:active? #t #:value 2) c2)
(check-equal? (find-course #:active? #t #:value 3) #f)
(check-equal? (find-course #:active? #t #:value 4) c4))
(test-case "find-all #:limit and #:offset"
(check-equal? (find-courses #:limit 1) (list c1))
(check-equal? (find-courses #:limit 2) (list c1 c2))
(check-equal? (find-courses #:limit 2 #:offset 1) (list c2 c3)))
(test-case "find-all #:order"
(recreate-test-tables)
(let ([j (save! (make-person "j"))]
[d (save! (make-person "d"))]
[c (save! (make-person "c"))]
[g (save! (make-person "g"))]
[a (save! (make-person "a"))]
[b (save! (make-person "b"))]
[i (save! (make-person "i"))]
[h (save! (make-person "h"))]
[e (save! (make-person "e"))]
[f (save! (make-person "f"))])
(let ([people (find-people)])
(for ([x (in-list people)]
[y (in-list (cdr people))])
(check string<? (person-name x) (person-name y))))
(let ([people (find-people #:order (sql-list (desc person.name)))])
(for ([x (in-list people)]
[y (in-list (cdr people))])
(check string>? (person-name x) (person-name y))))))))
; Provide statements -----------------------------
(provide snooze-quick-find-tests)