aboutsummaryrefslogtreecommitdiff
path: root/test/union-find/test-quick-find.lisp
blob: f173ea6c838b53d0bdec3a9832bb68e7b8670472 (plain)
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
(load "../lisp-unit.lisp")
(defpackage :test-quick-find
  (:use :common-lisp
        :lisp-unit))

(in-package :test-quick-find)
(load "../../src/union-find/quick-find.lisp")

;;; Define tests
(define-test test-create-network
    (assert-equal 10 (length (create-network 10)))
  (assert-equalp #(0 1 2 3 4) (create-network 5)))

(define-test test-union_
    (let ((nw (create-network 10)))
      (setf nw (union_ nw 1 2))
      (setf nw (union_ nw 0 5))
      (assert-equal (aref nw 1) (aref nw 2))
      (assert-equal (aref nw 0) (aref nw 5))
      (assert-false (equal (aref nw 0) (aref nw 8)))
      (assert-false (equal (aref nw 0) (aref nw 2)))))

(define-test test-connected
    (let ((nw (create-network 10)))
      (setf nw (union_ nw 1 2))
      (setf nw (union_ nw 0 5))
      (assert-true (connected nw 1 2))
      (assert-true (connected nw 0 5))
      (assert-false (connected nw 0 8))
      (assert-false (connected nw 0 2))))

(define-test test-nunion__
    (let ((nw (create-network 10)))
      (nunion_ nw 1 2)
      (nunion_ nw 0 5)
      (assert-equal (aref nw 1) (aref nw 2))
      (assert-equal (aref nw 0) (aref nw 5))
      (assert-false (equal (aref nw 0) (aref nw 8)))
      (assert-false (equal (aref nw 0) (aref nw 2)))))

;; Run all tests
(setq *print-summary* t) ; Details tests locations when running tests
(run-tests :all)