-
Notifications
You must be signed in to change notification settings - Fork 3
/
test1.lisp
59 lines (52 loc) · 2.09 KB
/
test1.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
#++(ql:quickload '(binpack-test))
(defpackage #:binpack-test
(:use :cl :parachute #:binpack-test/common)
(:local-nicknames (:a :alexandria-2)
(:b :binpack)
(:bc :binpack/common)))
(in-package #:binpack-test)
(define-test binpack)
(defvar *tmp*)
(define-test (binpack packing1)
;; test evenly subdivided rects of various sizes
(loop for i in '(2 16 256)
do (loop for j in '(2 16 256)
do (loop for k in '(1 2 3 8)
for rects = (even-cuts i j k)
do (setf *tmp* rects)
(multiple-value-bind (pack ww hh)
(b:pack rects i j)
(in-bounds pack i j)
(valid-packing pack)
(true (<= ww i))
(true (<= hh j)))))))
(define-test (binpack packing2)
;; test some random packings
(let ((w 256)
(h 256)
(c 32))
(loop for d in '(3 4 5 8)
for a = 0
do (loop for i below c
for rects = (random-cuts w h d i)
do (setf *tmp* rects)
(multiple-value-bind (pack maxw maxh)
(b:auto-pack rects )
(true (valid-packing pack))
(multiple-value-bind (pw ph)
(bc::rects-bounds pack)
(unless (< (* pw ph)
(* 1.2 (* w h)))
(format t "~&packed into ~s x ~s (~s > ~s ~s)~%"
pw ph (* pw ph)
(* w h)
(float (/ (* pw ph) (* w h)))
))
(incf a (float (/ (* pw ph) (* w h))))
(true (< (* pw ph)
(* 1.6 (* w h)))))
))
(format t "~s: a = ~s ~s~%" d a (/ a c))
(true (< (/ a c) 1.13)))))
#++
(time (test 'binpack))