67 lines
1.1 KiB
Factor
67 lines
1.1 KiB
Factor
USING: assocs kernel tools.test trees trees.cb trees.cb.private trees.private ;
|
|
IN: trees.cb.tests
|
|
|
|
: 4tree ( -- tree )
|
|
CB{ { 0 0 } { 1 1 } { 2 2 } { 3 3 } } clone ;
|
|
|
|
! Insertion into an empty tree
|
|
{ CB{ { 0 0 } } } [
|
|
0 0 <cb> [ set-at ] keep
|
|
] unit-test
|
|
|
|
! Double inserts
|
|
! single leaf
|
|
{
|
|
CB{ { 0 0 } }
|
|
} [
|
|
0 0 <cb> [ set-at ] keep
|
|
0 0 rot [ set-at ] keep
|
|
] unit-test
|
|
|
|
! left leaf
|
|
{
|
|
CB{ { 0 0 } { 1 1 } }
|
|
} [
|
|
CB{ { 0 0 } { 1 1 } }
|
|
0 0 rot [ set-at ] keep
|
|
] unit-test
|
|
|
|
! right leaf
|
|
{
|
|
CB{ { 0 0 } { 1 1 } }
|
|
} [
|
|
CB{ { 0 0 } { 1 1 } }
|
|
1 1 rot [ set-at ] keep
|
|
] unit-test
|
|
|
|
! Splits
|
|
! Insertion into a leaf-node resulting in splitting
|
|
{
|
|
CB{ { 0 0 } { 1 1 } }
|
|
} [
|
|
0 0 <cb> [ set-at ] keep
|
|
1 1 rot [ set-at ] keep
|
|
] unit-test
|
|
|
|
! Splitting at the root
|
|
{
|
|
CB{ { 0 0 } { 1 1 } { 2 2 } { 3 3 } { 4 4 } }
|
|
} [
|
|
CB{ { 0 0 } { 1 1 } { 2 2 } { 3 3 } }
|
|
4 4 rot [ set-at ] keep
|
|
] unit-test
|
|
|
|
! Collision
|
|
{
|
|
CB{ { B{ 110 } f } }
|
|
} [
|
|
CB{ { f f } }
|
|
f B{ 110 } rot [ set-at ] keep
|
|
] unit-test
|
|
|
|
! Colliding trees are still not equal
|
|
{ f } [
|
|
CB{ { f f } }
|
|
CB{ { B{ 110 } f } } =
|
|
] unit-test
|