Mercurial > hg > Gears > GearsAgda
view redBlackTreeTest.agda @ 540:6a4830c5a514
testing
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 11 Jan 2018 11:55:22 +0900 |
parents | 39d465c20e5a |
children | 429ece770187 |
line wrap: on
line source
module redBlackTreeTest where open import RedBlackTree open import stack open import Level hiding (zero) open import Data.Nat open Tree open Node open RedBlackTree.RedBlackTree open Stack -- tests 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 putTree1 {n} {m} {a} {k} {si} {t} tree k1 value next with (root tree) ... | Nothing = next (record tree {root = Just (leafNode k1 value) }) ... | Just n2 = clearStack (nodeStack tree) (\ s -> findNode tree s (leafNode k1 value) n2 (\ tree1 s n1 -> replaceNode tree1 s n1 next)) open import Relation.Binary.PropositionalEquality open import Relation.Binary.Core open import Function check1 : {m : Level } (n : Maybe (Node ℕ ℕ)) -> ℕ -> Bool {m} check1 Nothing _ = False check1 (Just n) x with Data.Nat.compare (value n) x ... | equal _ = True ... | _ = False test1 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> getRedBlackTree t 1 ( \t x -> check1 x 1 ≡ True )) test1 = refl test2 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 ( \t -> putTree1 t 2 2 ( \t -> getRedBlackTree t 1 ( \t x -> check1 x 1 ≡ True ))) test2 = refl test3 : putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t -> putTree1 t 2 2 $ \t -> getRedBlackTree t 2 $ \t x -> check1 x 2 ≡ True test3 = refl -- test4 : putTree1 {_} {_} {ℕ} {ℕ} ( createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t -> putTree1 t 2 2 $ \t -> -- root t ≡ Just (record { key = 1; value = 1; left = Just (record { key = 2 ; value = 2 } ); right = Nothing} ) -- test4 = refl -- test5 : Maybe (Node ℕ ℕ) test5 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ ) 1 1 $ \t -> putTree1 t 2 2 -- $ \t -> putTree1 t 3 3 $ \t -> clearStack (nodeStack t) $ \s -> findNode1 t s (leafNode 3 3) ( root t ) $ \t1 s n1 -> replaceNode t1 s n1 $ \t -> getRedBlackTree t 3 $ \t x -> SingleLinkedStack.top (stack s) -- $ \t x -> n1 -- $ \t x -> root t1 where 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 findNode1 t s n1 Nothing next = next t s n1 findNode1 t s n1 ( Just n2 ) next = findNode t s n1 n2 next -- test51 : putTree1 {_} {_} {ℕ} {ℕ} {_} {Maybe (Node ℕ ℕ)} (createEmptyRedBlackTreeℕ ℕ {Set Level.zero} ) 1 1 $ \t -> -- 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} ) -- test51 = refl test6 : Maybe (Node ℕ ℕ) test6 = root (createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)}) test7 : Maybe (Node ℕ ℕ) test7 = clearStack (nodeStack tree2) (\ s -> replaceNode tree2 s n2 (\ t -> root t)) where tree2 = createEmptyRedBlackTreeℕ {_} ℕ {Maybe (Node ℕ ℕ)} k1 = 1 n2 = leafNode 0 0 value1 = 1 test8 : Maybe (Node ℕ ℕ) test8 = putTree1 {_} {_} {ℕ} {ℕ} (createEmptyRedBlackTreeℕ ℕ) 1 1 $ \t -> putTree1 t 2 2 (\ t -> root t)