Example #1
0
    def test_constraints_and_basic(self):
        line_source = LineSource('localhost', 'node_0.log')
        effect = Clue(('Pear', 2), 'Pear, 2 times', 3000, line_source)
        clues_lists = [
            ([
                Clue(('Milk', 3), 'Milk, 3 times', 50, line_source),
                Clue(('Chocolate', 2), 'Chocolate, 2 times', 100, line_source),
                Clue(('Pear', 2), 'Pear, 2 times', 150, line_source)
            ], 1), ([
                Clue(('Pear', 2), 'Pear, 2 times', 1050, line_source),
                Clue(('Milk', 1), 'Milk, 1 times', 1100, line_source)
            ], 1)
        ]  # yapf: disable
        constraints = [{
            'clues_groups': [[0, 1], [1, 1], [2, 1]],
            'name': 'identical',
            'params': {}
        }, {
            'clues_groups': [[0, 2], [1, 2], [2, 2]],
            'name': 'identical',
            'params': {}
        }]
        causes = Verifier.constraints_and(clues_lists, effect, constraints,
                                          ConstraintManager())
        assert len(causes) == 1

        assert all(cause.constraints_linkage == InvestigationResult.AND
                   for cause in causes)
        assert causes[0].lines == [
            FrontInput.from_clue(Clue(
                ('Pear', 2), 'Pear, 2 times', 150, line_source)),
            FrontInput.from_clue(Clue(
                ('Pear', 2), 'Pear, 2 times', 1050, line_source))
        ]  # yapf: disable
Example #2
0
    def test_constraints_and_basic(self):
        line_source = LineSource('localhost', 'node_0.log')
        effect = Clue(('Pear', 2), 'Pear, 2 times', 3000, line_source)
        clues_lists = [
            ([
                Clue(('Milk', 3), 'Milk, 3 times', 50, line_source),
                Clue(('Chocolate', 2), 'Chocolate, 2 times', 100, line_source),
                Clue(('Pear', 2), 'Pear, 2 times', 150, line_source)
            ], 1), ([
                Clue(('Pear', 2), 'Pear, 2 times', 1050, line_source),
                Clue(('Milk', 1), 'Milk, 1 times', 1100, line_source)
            ], 1)
        ]  # yapf: disable
        constraints = [
            {
                'clues_groups': [[0, 1], [1, 1], [2, 1]],
                'name': 'identical',
                'params': {}
            }, {
                'clues_groups': [[0, 2], [1, 2], [2, 2]],
                'name': 'identical',
                'params': {}
            }
        ]
        causes = Verifier.constraints_and(clues_lists, effect, constraints, ConstraintManager())
        assert len(causes) == 1

        assert all(cause.constraints_linkage == InvestigationResult.AND for cause in causes)
        assert causes[0].lines == [
            FrontInput.from_clue(Clue(
                ('Pear', 2), 'Pear, 2 times', 150, line_source)),
            FrontInput.from_clue(Clue(
                ('Pear', 2), 'Pear, 2 times', 1050, line_source))
        ]  # yapf: disable
Example #3
0
    def test_constraints_and_verification_failed_when_or_succeeded(self):
        line_source = LineSource('localhost', 'node_0.log')
        effect = Clue(('Banana', 44), 'Banana, 44 times', 3000, line_source)
        clues_lists = [
            ([
                Clue(('Milk', 3), 'Milk, 3 times', 50, line_source),
                Clue(('Chocolate', 4), 'Chocolate, 4 times', 100, line_source),
                Clue(('Pear', 2), 'Pear, 2 times', 150, line_source)                # <- should be found (parser 1)
            ], 1), ([
                Clue(('Pineapple', 2), 'Pineapple, 2 times', 1050, line_source),    # <- should be found (parser 2)
                Clue(('Milk', 1), 'Milk, 1 times', 1100, line_source)
            ], 1)
        ]  # yapf: disable
        constraints = [
            {
                'clues_groups': [[0, 1], [1, 1], [2, 1]],
                'name': 'identical',
                'params': {}
            }, {
                'clues_groups': [[1, 2], [2, 2]],
                'name': 'identical',
                'params': {}
            }
        ]

        # testing 'and'
        causes = Verifier.constraints_and(clues_lists, effect, constraints, ConstraintManager())
        assert not causes

        # testing 'or'
        causes = Verifier.constraints_or(clues_lists, effect, constraints, ConstraintManager())
        assert len(causes) == 1

        assert all(cause.constraints_linkage == InvestigationResult.OR for cause in causes)
        assert causes[0].lines == [
            FrontInput.from_clue(Clue(
                ('Pear', 2), 'Pear, 2 times', 150, line_source)),
            FrontInput.from_clue(Clue(
                ('Pineapple', 2), 'Pineapple, 2 times', 1050, line_source))
        ]  # yapf: disable
        assert causes[0].constraints == [
            {
                'clues_groups': [[1, 2], [2, 2]],
                'name': 'identical',
                'params': {}
            }
        ]
Example #4
0
    def test_constraints_and_verification_failed_when_or_succeeded(self):
        line_source = LineSource('localhost', 'node_0.log')
        effect = Clue(('Banana', 44), 'Banana, 44 times', 3000, line_source)
        clues_lists = [
            ([
                Clue(('Milk', 3), 'Milk, 3 times', 50, line_source),
                Clue(('Chocolate', 4), 'Chocolate, 4 times', 100, line_source),
                Clue(('Pear', 2), 'Pear, 2 times', 150, line_source)                # <- should be found (parser 1)
            ], 1), ([
                Clue(('Pineapple', 2), 'Pineapple, 2 times', 1050, line_source),    # <- should be found (parser 2)
                Clue(('Milk', 1), 'Milk, 1 times', 1100, line_source)
            ], 1)
        ]  # yapf: disable
        constraints = [{
            'clues_groups': [[0, 1], [1, 1], [2, 1]],
            'name': 'identical',
            'params': {}
        }, {
            'clues_groups': [[1, 2], [2, 2]],
            'name': 'identical',
            'params': {}
        }]

        # testing 'and'
        causes = Verifier.constraints_and(clues_lists, effect, constraints,
                                          ConstraintManager())
        assert not causes

        # testing 'or'
        causes = Verifier.constraints_or(clues_lists, effect, constraints,
                                         ConstraintManager())
        assert len(causes) == 1

        assert all(cause.constraints_linkage == InvestigationResult.OR
                   for cause in causes)
        assert causes[0].lines == [
            FrontInput.from_clue(Clue(
                ('Pear', 2), 'Pear, 2 times', 150, line_source)),
            FrontInput.from_clue(Clue(
                ('Pineapple', 2), 'Pineapple, 2 times', 1050, line_source))
        ]  # yapf: disable
        assert causes[0].constraints == [{
            'clues_groups': [[1, 2], [2, 2]],
            'name': 'identical',
            'params': {}
        }]
Example #5
0
    def test_constraints_when_one_unmatched(self):
        line_source = LineSource('localhost', 'node_0.log')
        effect = Clue(('Banana', 2), 'Banana, 2 times', 3000, line_source)
        clues_lists = [
            ([
            ], 1), ([
                Clue(('Banana', 2), 'Banana, 2 times', 1050, line_source),
                Clue(('Milk', 1), 'Milk, 1 times', 1100, line_source)
            ], 1)
        ]  # yapf: disable
        constraints = [
            {
                'clues_groups': [[0, 1], [1, 1], [2, 1]],
                'name': 'identical',
                'params': {}
            }, {
                'clues_groups': [[0, 2], [2, 2]],
                'name': 'identical',
                'params': {}
            }
        ]

        # testing 'or'
        causes = Verifier.constraints_or(clues_lists, effect, constraints, ConstraintManager())
        assert len(causes) == 1

        assert all(cause.constraints_linkage == InvestigationResult.OR for cause in causes)
        assert causes[0].lines == [
            FrontInput.from_clue(Clue(
                ('Banana', 2), 'Banana, 2 times', 1050, line_source))
        ]  # yapf: disable
        assert causes[0].constraints == [
            {
                'clues_groups': [[0, 2], [2, 2]],
                'name': 'identical',
                'params': {}
            }
        ]

        # testing 'and'
        causes = Verifier.constraints_and(clues_lists, effect, constraints, ConstraintManager())
        assert not causes
Example #6
0
    def test_constraints_when_one_unmatched(self):
        line_source = LineSource('localhost', 'node_0.log')
        effect = Clue(('Banana', 2), 'Banana, 2 times', 3000, line_source)
        clues_lists = [
            ([
            ], 1), ([
                Clue(('Banana', 2), 'Banana, 2 times', 1050, line_source),
                Clue(('Milk', 1), 'Milk, 1 times', 1100, line_source)
            ], 1)
        ]  # yapf: disable
        constraints = [{
            'clues_groups': [[0, 1], [1, 1], [2, 1]],
            'name': 'identical',
            'params': {}
        }, {
            'clues_groups': [[0, 2], [2, 2]],
            'name': 'identical',
            'params': {}
        }]

        # testing 'or'
        causes = Verifier.constraints_or(clues_lists, effect, constraints,
                                         ConstraintManager())
        assert len(causes) == 1

        assert all(cause.constraints_linkage == InvestigationResult.OR
                   for cause in causes)
        assert causes[0].lines == [
            FrontInput.from_clue(Clue(
                ('Banana', 2), 'Banana, 2 times', 1050, line_source))
        ]  # yapf: disable
        assert causes[0].constraints == [{
            'clues_groups': [[0, 2], [2, 2]],
            'name': 'identical',
            'params': {}
        }]

        # testing 'and'
        causes = Verifier.constraints_and(clues_lists, effect, constraints,
                                          ConstraintManager())
        assert not causes