From 2ea1a999a4f394f3e6cebab43d9c38001cf316a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sun, 9 Nov 2014 01:48:10 +0100 Subject: [PATCH] compiler.cfg.dependence.tests: unit tests for the dependence vocab --- .../cfg/dependence/dependence-tests.factor | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 basis/compiler/cfg/dependence/dependence-tests.factor diff --git a/basis/compiler/cfg/dependence/dependence-tests.factor b/basis/compiler/cfg/dependence/dependence-tests.factor new file mode 100644 index 0000000000..b9e9a67ae3 --- /dev/null +++ b/basis/compiler/cfg/dependence/dependence-tests.factor @@ -0,0 +1,55 @@ +USING: accessors arrays compiler.cfg.dependence compiler.cfg.instructions +kernel namespaces sequences tools.test ; +IN: compiler.cfg.dependence.tests + +{ + V{ + T{ node + { number 1 } + { insn T{ ##inc-r } } + { precedes H{ } } + { follows V{ } } + } + T{ node + { number 2 } + { insn T{ ##inc-d } } + { precedes H{ } } + { follows V{ } } + } + } +} [ + 0 node-number set-global + V{ T{ ##inc-r } T{ ##inc-d } } [ ] map dup + build-dependence-graph +] unit-test + +{ 0 } [ + T{ ##load-tagged } calculate-registers +] unit-test + +: 2node-tree ( -- tree ) + 2 iota [ node new swap >>number ] map first2 over attach-parent ; + +! 0 -> 1 -> 2 +: 3node-tree ( -- tree ) + 3 iota [ node new swap >>number ] map first3 + over attach-parent over attach-parent ; + +{ } [ 2node-tree 1array dup verify-parents ] unit-test + +[ + 2node-tree 1array { } verify-parents +] [ node-missing-parent? ] must-fail-with + + +{ 1 } [ 3node-tree children>> length ] unit-test + +{ 3 } [ 3node-tree flatten-tree length ] unit-test + +[ + { } 3node-tree 1array verify-children +] [ node-missing-children? ] must-fail-with + +[ + { } 3node-tree 1array verify-trees +] [ node-missing-children? ] must-fail-with