annotate redBlackTreeTest.agda @ 542:ee65e69c9b62

puttree1 act
author ryokka
date Thu, 11 Jan 2018 17:38:13 +0900
parents 429ece770187
children 1595dd84fc3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
1 module redBlackTreeTest where
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
2
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
3 open import RedBlackTree
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
4 open import stack
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
5 open import Level hiding (zero)
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
6
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
7 open import Data.Nat
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
8
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
9 open Tree
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
10 open Node
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
11 open RedBlackTree.RedBlackTree
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
12 open Stack
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
13
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
14 -- tests
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
15
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
16 putTree1 : {n m : Level } {a k si : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k si -> k -> a -> (RedBlackTree {n} {m} {t} a k si -> t) -> t
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
17 putTree1 {n} {m} {a} {k} {si} {t} tree k1 value next with (root tree)
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
18 ... | Nothing = next (record tree {root = Just (leafNode k1 value) })
538
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
19 ... | Just n2 = clearStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> replaceNode tree1 s n1 next))
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
20
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
21 open import Relation.Binary.PropositionalEquality
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
22 open import Relation.Binary.Core
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
23 open import Function
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
24
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
25
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
26 check1 : {m : Level } (n : Maybe (Node ℕ ℕ)) -> ℕ -> Bool {m}
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
27 check1 Nothing _ = False
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
28 check1 (Just n) x with Data.Nat.compare (value n) x
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
29 ... | equal _ = True
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
30 ... | _ = False
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
31
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
32 test1 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> getRedBlackTree t 1 ( \t x -> check1 x 1 ≡ True ))
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
33 test1 = refl
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
34
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
35 test2 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 (
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
36 \t -> putTree1 t 2 2 (
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
37 \t -> getRedBlackTree t 1 (
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
38 \t x -> check1 x 1 ≡ True )))
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
39 test2 = refl
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
40
542
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
41 test3 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero}) 1 1
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
42 $ \t -> putTree1 t 2 2
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
43 $ \t -> putTree1 t 3 3
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
44 $ \t -> putTree1 t 4 4
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
45 $ \t -> getRedBlackTree t 4
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
46 $ \t x -> check1 x 4 ≡ True
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
47 test3 = refl
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
48
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
49 test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
50 $ \t -> putTree1 t 2 2
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
51 $ \t -> putTree1 t 3 3
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
52 $ \t -> putTree1 t 4 4
ee65e69c9b62 puttree1 act
ryokka
parents: 541
diff changeset
53 $ \t -> root t
537
fffeaf0b0024 add stackTest redBlackTreeTest
ryokka
parents:
diff changeset
54
540
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
55 -- test4 : putTree1 {_} {_} {ℕ} {ℕ} ( createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t -> putTree1 t 2 2 $ \t ->
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
56 -- root t ≡ Just (record { key = 1; value = 1; left = Just (record { key = 2 ; value = 2 } ); right = Nothing} )
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
57 -- test4 = refl
538
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
58
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
59
540
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
60 -- test5 : Maybe (Node ℕ ℕ)
541
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 540
diff changeset
61 test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 4 4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 540
diff changeset
62 $ \t -> putTree1 t 6 6
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 540
diff changeset
63 $ \t0 -> clearStack (nodeStack t0)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 540
diff changeset
64 $ \s -> findNode1 t0 s (leafNode 3 3) ( root t0 )
540
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
65 $ \t1 s n1 -> replaceNode t1 s n1
539
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
66 $ \t -> getRedBlackTree t 3
541
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 540
diff changeset
67 -- $ \t x -> SingleLinkedStack.top (stack s)
540
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
68 -- $ \t x -> n1
541
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 540
diff changeset
69 $ \t x -> root t
540
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
70 where
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
71 findNode1 : {n m : Level } {a k si : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) si -> (Node a k) -> (Maybe (Node a k)) -> (RedBlackTree {n} {m} {t} a k si -> Stack (Node a k) si -> Node a k -> t) -> t
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
72 findNode1 t s n1 Nothing next = next t s n1
6a4830c5a514 testing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 539
diff changeset
73 findNode1 t s n1 ( Just n2 ) next = findNode t s n1 n2 next
538
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
74
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
75 -- test51 : putTree1 {_} {_} {ℕ} {ℕ} {_} {Maybe (Node ℕ ℕ)} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t ->
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
76 -- putTree1 t 2 2 $ \t -> putTree1 t 3 3 $ \t -> root t ≡ Just (record { key = 1; value = 1; left = Just (record { key = 2 ; value = 2 } ); right = Nothing} )
5c001e8ba0d5 add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents: 537
diff changeset
77 -- test51 = refl
539
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
78
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
79 test6 : Maybe (Node ℕ ℕ)
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
80 test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)})
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
81
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
82
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
83 test7 : Maybe (Node ℕ ℕ)
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
84 test7 = clearStack (nodeStack tree2) (\ s -> replaceNode tree2 s n2 (\ t -> root t))
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
85 where
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
86 tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
87 k1 = 1
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
88 n2 = leafNode 0 0
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
89 value1 = 1
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
90
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
91 test8 : Maybe (Node ℕ ℕ)
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
92 test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1
39d465c20e5a print contant tree. C-c C-n test.
ryokka
parents: 538
diff changeset
93 $ \t -> putTree1 t 2 2 (\ t -> root t)