Mercurial > hg > Gears > GearsAgda
annotate redBlackTreeTest.agda @ 542:ee65e69c9b62
puttree1 act
author | ryokka |
---|---|
date | Thu, 11 Jan 2018 17:38:13 +0900 |
parents | 429ece770187 |
children | 1595dd84fc3e |
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 | |
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 | |
17 putTree1 {n} {m} {a} {k} {si} {t} tree k1 value next with (root tree) | |
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 | 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 | |
542 | 41 test3 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero}) 1 1 |
42 $ \t -> putTree1 t 2 2 | |
43 $ \t -> putTree1 t 3 3 | |
44 $ \t -> putTree1 t 4 4 | |
45 $ \t -> getRedBlackTree t 4 | |
46 $ \t x -> check1 x 4 ≡ True | |
47 test3 = refl | |
48 | |
49 test31 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 | |
50 $ \t -> putTree1 t 2 2 | |
51 $ \t -> putTree1 t 3 3 | |
52 $ \t -> putTree1 t 4 4 | |
53 $ \t -> root t | |
537 | 54 |
540 | 55 -- test4 : putTree1 {_} {_} {ℕ} {ℕ} ( createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t -> putTree1 t 2 2 $ \t -> |
56 -- root t ≡ Just (record { key = 1; value = 1; left = Just (record { key = 2 ; value = 2 } ); right = Nothing} ) | |
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 | 60 -- test5 : Maybe (Node ℕ ℕ) |
541 | 61 test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 4 4 |
62 $ \t -> putTree1 t 6 6 | |
63 $ \t0 -> clearStack (nodeStack t0) | |
64 $ \s -> findNode1 t0 s (leafNode 3 3) ( root t0 ) | |
540 | 65 $ \t1 s n1 -> replaceNode t1 s n1 |
539 | 66 $ \t -> getRedBlackTree t 3 |
541 | 67 -- $ \t x -> SingleLinkedStack.top (stack s) |
540 | 68 -- $ \t x -> n1 |
541 | 69 $ \t x -> root t |
540 | 70 where |
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 | |
72 findNode1 t s n1 Nothing next = next t s n1 | |
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 | 78 |
79 test6 : Maybe (Node ℕ ℕ) | |
80 test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}) | |
81 | |
82 | |
83 test7 : Maybe (Node ℕ ℕ) | |
84 test7 = clearStack (nodeStack tree2) (\ s -> replaceNode tree2 s n2 (\ t -> root t)) | |
85 where | |
86 tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)} | |
87 k1 = 1 | |
88 n2 = leafNode 0 0 | |
89 value1 = 1 | |
90 | |
91 test8 : Maybe (Node ℕ ℕ) | |
92 test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 | |
93 $ \t -> putTree1 t 2 2 (\ t -> root t) |