-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittests.lisp
102 lines (85 loc) · 4.17 KB
/
unittests.lisp
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
99
100
101
102
(in-package #:vision)
;(use-package 'lisp-unit)
(read-image "/Users/reuben/img.png")
;(scan *edge*)
(lisp-unit:define-test addObject
(let ((layer (make-instance 'image-layer))
(object (make-instance 'image-object)))
(add-object object layer)
(lisp-unit:assert-true (= (length (objects layer)) 1))
(lisp-unit:assert-true (equal (parent-layer object) layer))))
(lisp-unit:define-test add-layer-to-stack
(let ((stack-obj (make-instance 'image-stack)))
(lisp-unit:assert-equal 'IMAGE-LAYER (type-of (add-layer (make-instance 'image-layer) stack-obj)))
(lisp-unit:assert-true (= (length (layers stack-obj)) 1))))
(lisp-unit:define-test for-loop-test
(let ((l '())
(x 0))
(loop-for x 0 5 #'< #'1+
(setf l (cons x l)))
(lisp-unit:assert-true (equal '(4 3 2 1 0) l))))
(lisp-unit:define-test coordinate-in-object-check-predicate
(let ((*image-stack* (make-instance 'image-stack))
(layer (make-instance 'image-layer)))
(add-layer layer *image-stack*)
(lisp-unit:assert-false (coordinate-in-any-object-p 10 10 layer ))
(add-object (dfs *edge* 56 5) layer)
(lisp-unit:assert-false (coordinate-in-any-object-p 10 10 layer))
(lisp-unit:assert-true (coordinate-in-any-object-p 58 10 layer))))
(lisp-unit:define-test image-scan-check-predicate
(let ((*image-stack* (make-instance 'image-stack))
(layer (make-instance 'image-layer)))
(add-layer layer *image-stack*)
(add-object (dfs *edge* 2 21) layer)
(add-object (dfs *edge* 821 17) layer)
(add-object (dfs *edge* 917 3) layer)
(lisp-unit:assert-false (should-perform-dfs-p *edge* 0 0)) ; low threshold level
(lisp-unit:assert-true (should-perform-dfs-p *edge* 58 10)) ; pixel has not been scanned and has is not on layer
(add-object (dfs *edge* 56 5) layer)
(lisp-unit:assert-false (should-perform-dfs-p *edge* 917 3))
(lisp-unit:assert-false (should-perform-dfs-p *edge* 55 6))
(lisp-unit:assert-false (should-perform-dfs-p *edge* 55 7))
(lisp-unit:assert-false (should-perform-dfs-p *edge* 822 17))
(lisp-unit:assert-false (should-perform-dfs-p *edge* 3 21))))
; (lisp-unit:assert-false (print (should-perform-dfs-p *edge* 2 21)))
; (lisp-unit:assert-false (should-perform-dfs-p *edge* 289 119)))) ; pixel is with in the bounding box of an object
;; 285 119
;285 122
;; (lisp-unit:define-test mergable-p-test
;; (let ((image-obj (dfs *edge* 21 13))
;; (image-obj-1 (dfs *edge* 22 16))
;; (image-obj-2 (dfs *edge* 56 5))
;; (image-obj-3 (dfs *edge* 56 5))
;; (image-obj-4 (dfs *edge* 62 8)))
;; ; (print (proper-ratio (length (pixel-list image-obj)) (length (pixel-list image-obj-1))))
;; (lisp-unit:assert-true (mergable-p image-obj image-obj-1))
;; (lisp-unit:assert-false (mergable-p image-obj-3 image-obj-4))
;; (print (proper-ratio (length (pixel-list image-obj-4)) (length (pixel-list image-obj-3))))
;; (lisp-unit:assert-false (mergable-p image-obj-1 image-obj-2))))
(lisp-unit:define-test proper-ratio-test
(let ((x 1)
(y 2))
(lisp-unit:assert-equal .5 (proper-ratio x y))
(lisp-unit:assert-equal .5 (proper-ratio y x))))
(lisp-unit:define-test find-image-object-test
(scan *edge*)
(let ((layer (first (last (layers *image-stack*)))))
(lisp-unit:assert-true (equal '(56 5) (origin-pixels (find-object-with-origin 56 5 layer))))
(lisp-unit:assert-false (find-object-with-origin 0 0 layer))))
(lisp-unit:define-test calc-width-test
(let* ((layer (first (last (layers *image-stack*))))
(object (find-object-with-origin 56 5 layer)))
(lisp-unit:assert-equal 5 (calc-image-object-width object))))
(lisp-unit:define-test calc-height-test
(let* ((layer (first (last (layers *image-stack*))))
(object (find-object-with-origin 56 5 layer)))
(lisp-unit:assert-equal 10 (calc-image-object-height object))))
(lisp-unit:define-test create-image-test
(let* ((layer (first (last (layers *image-stack*))))
(object (find-object-with-origin 56 5 layer))
(image-obj (create-image object *Edge*))
(image-obj1 (create-image nil nil)))
(lisp-unit:assert-equal 11 (imago:image-height image-obj))
(lisp-unit:assert-equal 6 (imago:image-width image-obj))
(lisp-unit:assert-equal nil image-obj1)))
;(lisp-unit:run-tests);