summaryrefslogtreecommitdiff
path: root/lib/splay/tests/splay.t
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2026-03-27 08:48:05 +0100
committerSébastien Dailly <sebastien@dailly.me>2026-03-27 08:48:05 +0100
commit830e7c5d27d161b91402414e6ecd49f1ed818bfb (patch)
tree448864635d29b1ea66424cbb9e0816fbcf1e1907 /lib/splay/tests/splay.t
Initial commit
Diffstat (limited to 'lib/splay/tests/splay.t')
-rw-r--r--lib/splay/tests/splay.t93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/splay/tests/splay.t b/lib/splay/tests/splay.t
new file mode 100644
index 0000000..628ccaa
--- /dev/null
+++ b/lib/splay/tests/splay.t
@@ -0,0 +1,93 @@
+Tests for the splay tree. The tree representation used in the tests follow the
+dot syntax
+
+See https://en.wikipedia.org/wiki/Splay_tree
+
+
+The root is the latest inserted node:
+
+ $ tests -splay_tree \
+ > -add 5 \
+ > -add 3
+ digraph G {
+ leaf_0 [shape=point]
+ "3" -> leaf_0
+ "3" -> "5"
+ leaf_1 [shape=point]
+ "5" -> leaf_1
+ leaf_2 [shape=point]
+ "5" -> leaf_2
+ }
+
+ $ tests -splay_tree \
+ > -add 3 \
+ > -add 5
+ digraph G {
+ "5" -> "3"
+ leaf_0 [shape=point]
+ "3" -> leaf_0
+ leaf_1 [shape=point]
+ "3" -> leaf_1
+ leaf_2 [shape=point]
+ "5" -> leaf_2
+ }
+
+Collecting an element in the tree will push this node at the root:
+
+ $ tests -splay_tree \
+ > -add 1 \
+ > -add 2 \
+ > -add 3 \
+ > -get 2
+ digraph G {
+ "2" -> "1"
+ leaf_0 [shape=point]
+ "1" -> leaf_0
+ leaf_1 [shape=point]
+ "1" -> leaf_1
+ "2" -> "3"
+ leaf_2 [shape=point]
+ "3" -> leaf_2
+ leaf_3 [shape=point]
+ "3" -> leaf_3
+ }
+
+ $ tests -splay_tree \
+ > -add 1 \
+ > -add 2 \
+ > -add 3 \
+ > -add 4 \
+ > -get 1
+ digraph G {
+ leaf_0 [shape=point]
+ "1" -> leaf_0
+ "1" -> "3"
+ "3" -> "2"
+ leaf_1 [shape=point]
+ "2" -> leaf_1
+ leaf_2 [shape=point]
+ "2" -> leaf_2
+ "3" -> "4"
+ leaf_3 [shape=point]
+ "4" -> leaf_3
+ leaf_4 [shape=point]
+ "4" -> leaf_4
+ }
+
+Removing an element from the tree modify the structure
+
+ $ tests -splay_tree \
+ > -add 1 \
+ > -add 2 \
+ > -add 3 \
+ > -del 2
+ digraph G {
+ leaf_0 [shape=point]
+ "1" -> leaf_0
+ "1" -> "3"
+ leaf_1 [shape=point]
+ "3" -> leaf_1
+ leaf_2 [shape=point]
+ "3" -> leaf_2
+ }
+