From bec893c0b609224111a32f8008a7473987b3784c Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Mon, 24 Aug 2020 17:06:11 -0600 Subject: [PATCH] added stochastic test to ensure that the tree-equality check is working correctly; and apparently it can return equality when none exists, this is a bug we need to fix --- python_arborist.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/python_arborist.py b/python_arborist.py index c7ed80d..7215938 100644 --- a/python_arborist.py +++ b/python_arborist.py @@ -12,6 +12,9 @@ from typing import List, Dict, Tuple, Optional from combinatorial_LR_parser import MasterStateMachine +import random + + import CFGBoltzmann class TreeNode: @@ -380,6 +383,7 @@ top_bit = (1<<16) def deserializer(serialized_array, last_idx_written): + random_triggered = False list_of_nodes = [] physical_to_logical = {} physical_idx = 0 @@ -416,6 +420,14 @@ def deserializer(serialized_array, last_idx_written): print("") print("") + if (random.randint(0,10) == 0): + false_element = random.choices(list_of_nonterminals + list_of_terminals)[0] + + if (false_element != new_element): + print("RANDOM TRIGGERED! EXPECT FALSE RESULT!", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + random_triggered = True + new_element = false_element + new_node = TreeNode(new_element, subnodes_array) list_of_nodes.append(new_node) @@ -424,14 +436,14 @@ def deserializer(serialized_array, last_idx_written): physical_idx += 2 + number_subnodes logical_idx += 1 print("physical to logical mapping is", physical_to_logical) - return new_node + return (new_node, random_triggered) -parser_output_tree = deserializer(serialized_tree_final, 30) +(parser_output_tree, random_trig) = deserializer(serialized_tree_final, 30) walk_the_tree(parser_output_tree,0) @@ -455,4 +467,5 @@ def are_trees_equal(tree_one_root, tree_two_root): # returns True if equal, Fals for idx, elem in enumerate(tree_one_root.subnodes): return are_trees_equal(elem, tree_two_root.subnodes[idx]) -print("ARE TREES EQUAL???", are_trees_equal(bgen[1], parser_output_tree)) \ No newline at end of file +print("WAS RANDOM TRIGGERED??", random_trig) +print("ARE TREES EQUAL???", are_trees_equal(bgen[1], parser_output_tree)) -- GitLab