Exemplo n.º 1
0
def test_one_match_with_duplicates(context4):
    tree = NodeTree(context4)

    current_node = tree.next()
    while current_node:
        assert current_node.total_options == 2
        current_node = tree.next()
Exemplo n.º 2
0
def test_one_match_in_two_steps(context2):
    tree = NodeTree(context2)
    len_sentence = len(context2.get_sentence())

    node1 = tree.next()
    assert node1.state == NodeState.CHILD
    assert node1.segment.word == '......-...-..'
    assert node1.pos == 0
    len_before = node1.pos
    len_word = len(node1.segment)
    len_remaining = node1.nb_remaining
    assert len_before + len_word + len_remaining == len_sentence
    assert len(node1.options) == 1  # O
    assert node1.is_done is False

    node2 = tree.next()
    assert node2.state == NodeState.CHILD
    assert node2.segment.word == '---'
    assert node2.pos == 13
    len_before = node2.pos
    len_word = len(node2.segment)
    len_remaining = node2.nb_remaining
    assert len_before + len_word + len_remaining == len_sentence
    assert len(node2.options) == 0  # no more options
    assert node2.is_done

    assert tree.next() is None
Exemplo n.º 3
0
    def setUp(self):
        self.sample_tree = NodeTree()
        self.target_sm = [i for i in range(20)]
        random.shuffle(self.target_sm)

        # inserting here makes more sense for further testing
        for val in self.target_sm:
            self.sample_tree.insert(val)
Exemplo n.º 4
0
    def setUp(self):
        self.sample_tree = NodeTree()
        self.target_sm = []
        for i in range(5):
            for _ in range(i):
                self.target_sm.append(i)
        random.shuffle(self.target_sm)

        for val in self.target_sm:
            self.sample_tree.insert(val)
Exemplo n.º 5
0
def test_single_match_in_one_step(context1):
    tree = NodeTree(context1)
    node = tree.next()
    assert node.state == NodeState.CHILD
    assert node.segment.word == '......-...-..---'
    assert node.pos == 0
    len_sentence = len(context1.get_sentence())
    len_before = node.pos
    len_word = len(node.segment)
    len_remaining = node.nb_remaining
    assert len_before + len_word + len_remaining == len_sentence
    assert len(node.options) == 0  # no more options
    assert node.is_done

    assert tree.next() is None
Exemplo n.º 6
0
def test_root_node(context1):
    tree = NodeTree(context1)
    next_node = tree.root
    assert next_node.state == NodeState.ROOT
    assert next_node.pos == 0
    assert next_node.nb_remaining == len(context1.get_sentence())
    assert len(next_node.options) == 1  # HELLO
Exemplo n.º 7
0
def main():

    # Initialize object object and samples here ###########################
    # Test Object:
    sample_tree = NodeTree()

    # Test Sample:
    sample_input = []
    for i in range(5):
        for _ in range(i):
            sample_input.append(i)
    # random.shuffle(target_sm)

    for value in sample_input:
        sample_tree.insert(value)

    # Begin testing functions here ###########################################
    # Initial View:
    print(sample_tree.get_array())
Exemplo n.º 8
0
class NodeTreeTestWithDuplicates(NodeTreeTests):
    """
    Test class that inherits from the above 'base' class but uses a target with
    duplicate values.

    With the current implementation of NodeTree however, this is will not work.
    Probably more accurate to test distinct values.
    """

    def setUp(self):
        self.sample_tree = NodeTree()
        self.target_sm = []
        for i in range(5):
            for _ in range(i):
                self.target_sm.append(i)
        random.shuffle(self.target_sm)

        for val in self.target_sm:
            self.sample_tree.insert(val)


    def test_existing_values(self):
        super().test_existing_values()
Exemplo n.º 9
0
class NodeTreeTests(unittest.TestCase):
    """
    General testing base for testing insertion, removal, validity of random values.
    """

    def setUp(self):
        self.sample_tree = NodeTree()
        self.target_sm = [i for i in range(20)]
        random.shuffle(self.target_sm)

        # inserting here makes more sense for further testing
        for val in self.target_sm:
            self.sample_tree.insert(val)


    def test_existing_values(self):
        # check all values with get_array()
        self.assertEqual(sorted(self.target_sm), self.sample_tree.get_array())

        # check all values with has()
        for val in self.target_sm:
            self.assertTrue(self.sample_tree.has(val))

        # check has() works for an absurd value not in the tree
        self.assertFalse(self.sample_tree.has(100000000000000000000000))


    def test_remove_beginning(self):
        # remove values 0 to 4 from the tree
        for val in self.target_sm[:5]:
            self.sample_tree.remove(val)
            self.assertFalse(self.sample_tree.has(val))


    def test_remove_end(self):
        # remove values 5 to 9 from the tree
        for val in self.target_sm[-5:]:
            self.sample_tree.remove(val)
            self.assertFalse(self.sample_tree.has(val))


    def test_remove_random(self):
        # remove random value to test each type of remove
        val = random.randint(0, 10)
        self.sample_tree.remove(val)

        self.assertFalse(self.sample_tree.has(val))


    def test_remove_nonexist_val(self):
        self.assertFalse(self.sample_tree.remove(100000000000000000000000000))