Mercurial > hg > Members > Moririn
annotate redBlackTreeTest.agda @ 545:b180dc78abcf
add someTest
author | ryokka |
---|---|
date | Fri, 12 Jan 2018 18:30:05 +0900 |
parents | 4f692df9b3db |
children | b654ce34c894 |
rev | line source |
---|---|
537 | 1 module redBlackTreeTest where |
2 | |
3 open import RedBlackTree | |
4 open import stack | |
5 open import Level hiding (zero) | |
6 | |
7 open import Data.Nat | |
8 | |
9 open Tree | |
10 open Node | |
11 open RedBlackTree.RedBlackTree | |
12 open Stack | |
13 | |
14 -- tests | |
15 | |
543 | 16 putTree1 : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> k -> a -> (RedBlackTree {n} {m} {t} a k -> t) -> t |
17 putTree1 {n} {m} {a} {k} {t} tree k1 value next with (root tree) | |
537 | 18 ... | Nothing = next (record tree {root = Just (leafNode k1 value) }) |
543 | 19 ... | Just n2 = clearSingleLinkedStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> replaceNode tree1 s n1 next)) |
537 | 20 |
21 open import Relation.Binary.PropositionalEquality | |
22 open import Relation.Binary.Core | |
23 open import Function | |
24 | |
25 | |
26 check1 : {m : Level } (n : Maybe (Node ℕ ℕ)) -> ℕ -> Bool {m} | |
27 check1 Nothing _ = False | |
28 check1 (Just n) x with Data.Nat.compare (value n) x | |
29 ... | equal _ = True | |
30 ... | _ = False | |
31 | |
32 test1 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> getRedBlackTree t 1 ( \t x -> check1 x 1 ≡ True )) | |
33 test1 = refl | |
34 | |
35 test2 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( | |
36 \t -> putTree1 t 2 2 ( | |
37 \t -> getRedBlackTree t 1 ( | |
38 \t x -> check1 x 1 ≡ True ))) | |
39 test2 = refl | |
40 | |
545 | 41 open ≡-Reasoning |
542 | 42 test3 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero}) 1 1 |
43 $ \t -> putTree1 t 2 2 | |
44 $ \t -> putTree1 t 3 3 | |
544 | 45 $ \t -> putTree1 t 4 4 |
545 | 46 $ \t -> getRedBlackTree t 1 |
47 $ \t x -> check1 x 1 ≡ True | |
48 test3 = begin | |
49 check1 (Just (record {key = 1 ; value = 1 ; color = Black ; left = Nothing ; right = Just (leafNode 2 2)})) 1 | |
50 ≡⟨ refl ⟩ | |
51 True | |
52 ∎ | |
542 | 53 |
54 test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 | |
55 $ \t -> putTree1 t 2 2 | |
56 $ \t -> putTree1 t 3 3 | |
57 $ \t -> putTree1 t 4 4 | |
544 | 58 $ \t -> getRedBlackTree t 4 |
59 $ \t x -> x | |
538
5c001e8ba0d5
add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents:
537
diff
changeset
|
60 |
540 | 61 -- test5 : Maybe (Node ℕ ℕ) |
541 | 62 test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 4 4 |
63 $ \t -> putTree1 t 6 6 | |
543 | 64 $ \t0 -> clearSingleLinkedStack (nodeStack t0) |
541 | 65 $ \s -> findNode1 t0 s (leafNode 3 3) ( root t0 ) |
540 | 66 $ \t1 s n1 -> replaceNode t1 s n1 |
539 | 67 $ \t -> getRedBlackTree t 3 |
541 | 68 -- $ \t x -> SingleLinkedStack.top (stack s) |
540 | 69 -- $ \t x -> n1 |
541 | 70 $ \t x -> root t |
540 | 71 where |
543 | 72 findNode1 : {n m : Level } {a k : Set n} {t : Set m} -> RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> (Node a k) -> (Maybe (Node a k)) -> (RedBlackTree {n} {m} {t} a k -> SingleLinkedStack (Node a k) -> Node a k -> t) -> t |
540 | 73 findNode1 t s n1 Nothing next = next t s n1 |
74 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
|
75 |
5c001e8ba0d5
add redBlackTreeTest.agda test5,test51. but not work
ryokka
parents:
537
diff
changeset
|
76 -- 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
|
77 -- 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
|
78 -- test51 = refl |
539 | 79 |
80 test6 : Maybe (Node ℕ ℕ) | |
81 test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}) | |
82 | |
83 | |
84 test7 : Maybe (Node ℕ ℕ) | |
543 | 85 test7 = clearSingleLinkedStack (nodeStack tree2) (\ s -> replaceNode tree2 s n2 (\ t -> root t)) |
539 | 86 where |
87 tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)} | |
88 k1 = 1 | |
89 n2 = leafNode 0 0 | |
90 value1 = 1 | |
91 | |
92 test8 : Maybe (Node ℕ ℕ) | |
93 test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 | |
94 $ \t -> putTree1 t 2 2 (\ t -> root t) | |
544 | 95 |
96 | |
97 test9 : putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> getRedBlackTree t 1 ( \t x -> check1 x 1 ≡ True )) | |
98 test9 = refl | |
99 | |
100 test10 : putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( | |
101 \t -> putRedBlackTree t 2 2 ( | |
102 \t -> getRedBlackTree t 1 ( | |
103 \t x -> check1 x 1 ≡ True ))) | |
104 test10 = refl | |
105 | |
106 test11 = putRedBlackTree {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 | |
107 $ \t -> putRedBlackTree t 2 2 | |
108 $ \t -> putRedBlackTree t 3 3 | |
109 $ \t -> getRedBlackTree t 2 | |
110 $ \t x -> root t | |
545 | 111 |
112 | |
113 redBlackInSomeState :{ m : Level } (a : Set Level.zero) (n : Maybe (Node a ℕ)) {t : Set m} -> RedBlackTree {Level.zero} {m} {t} a ℕ | |
114 redBlackInSomeState {m} a n {t} = record { root = n ; nodeStack = emptySingleLinkedStack ; compare = compareℕ } | |
115 | |
116 putTest1 :{ m : Level } (n : Maybe (Node ℕ ℕ)) | |
117 -> (k : ℕ) (x : ℕ) | |
118 -> putTree1 {_} {_} {ℕ} {ℕ} (redBlackInSomeState {_} ℕ n {Set Level.zero}) k x | |
119 (\ t -> getRedBlackTree t k (\ t x1 -> check1 x1 x ≡ True)) | |
120 putTest1 n k x = {!!} | |
121 | |
122 -- begin | |
123 -- ? | |
124 -- ≡⟨ ? ⟩ | |
125 -- True | |
126 -- ∎ |