Beispiel #1
0
    def test_logical_or(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        comparison_expression_left = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL, tpl_exp, const_exp)
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)
        comparison_expression_right = ComparisonExpression(
            ExpressionType.COMPARE_GREATER, tpl_exp, const_exp)
        logical_expr = LogicalExpression(ExpressionType.LOGICAL_OR,
                                         comparison_expression_left,
                                         comparison_expression_right)

        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(2, 2 * np.ones((1, 1)), None)
        frame_3 = Frame(3, 3 * np.ones((1, 1)), None)
        input_batch = FrameBatch(frames=[
            frame_1,
            frame_2,
            frame_3,
        ],
                                 info=None)

        expected_value = [[True], [True], [True]]
        output_value = logical_expr.evaluate(input_batch)
        self.assertEqual(expected_value, output_value)
Beispiel #2
0
    def test_logical_or(self):
        const_exp1 = ConstantValueExpression(1)
        const_exp2 = ConstantValueExpression(1)

        comparison_expression_left = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL,
            const_exp1,
            const_exp2
        )
        const_exp1 = ConstantValueExpression(1)
        const_exp2 = ConstantValueExpression(2)
        comparison_expression_right = ComparisonExpression(
            ExpressionType.COMPARE_GREATER,
            const_exp1,
            const_exp2
        )
        logical_expr = LogicalExpression(
            ExpressionType.LOGICAL_OR,
            comparison_expression_left,
            comparison_expression_right
        )
        self.assertEqual(
            [True],
            logical_expr.evaluate(None).frames[0].tolist()
        )
Beispiel #3
0
    def test_short_circuiting_or_partial(self):
        # tests whether right-hand side is partially executed with or
        tup_val_exp_l = TupleValueExpression(col_name=0)
        tup_val_exp_r = TupleValueExpression(col_name=1)

        comp_exp_l = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL,
            tup_val_exp_l,
            tup_val_exp_r
        )
        comp_exp_r = Mock(spec=ComparisonExpression)
        comp_exp_r.evaluate = Mock(return_value=Mock(frames=[[True], [False]]))

        logical_exp = LogicalExpression(
            ExpressionType.LOGICAL_OR,
            comp_exp_l,
            comp_exp_r
        )

        tuples = Batch(pd.DataFrame(
            {0: [1, 2, 3, 4], 1: [5, 6, 3, 4]}))
        self.assertEqual(
            [True, False, True, True],
            logical_exp.evaluate(tuples).frames[0].tolist()
        )
        comp_exp_r.evaluate.assert_called_once_with(tuples, mask=[0, 1])
Beispiel #4
0
    def test_short_circuiting_or_complete(self):
        # tests whether right-hand side is bypassed completely with or
        tup_val_exp_l = TupleValueExpression(col_name=0)
        tup_val_exp_r = TupleValueExpression(col_name=1)

        comp_exp_l = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL,
            tup_val_exp_l,
            tup_val_exp_r
        )
        comp_exp_r = Mock(spec=ComparisonExpression)

        logical_exp = LogicalExpression(
            ExpressionType.LOGICAL_OR,
            comp_exp_l,
            comp_exp_r
        )

        tuples = Batch(pd.DataFrame(
            {0: [1, 2, 3], 1: [1, 2, 3]}))
        self.assertEqual(
            [True, True, True],
            logical_exp.evaluate(tuples).frames[0].tolist()
        )
        comp_exp_r.evaluate.assert_not_called()
Beispiel #5
0
    def test_logical_not(self):
        const_exp1 = ConstantValueExpression(0)
        const_exp2 = ConstantValueExpression(1)

        comparison_expression_right = ComparisonExpression(
            ExpressionType.COMPARE_GREATER, const_exp1, const_exp2)
        logical_expr = LogicalExpression(ExpressionType.LOGICAL_NOT, None,
                                         comparison_expression_right)
        self.assertEqual([True], logical_expr.evaluate(None))
Beispiel #6
0
    def test_logical_not(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        comparison_expression_right = ComparisonExpression(
            ExpressionType.COMPARE_GREATER, tpl_exp, const_exp)
        logical_expr = LogicalExpression(ExpressionType.LOGICAL_NOT, None,
                                         comparison_expression_right)
        tuple1 = [[1], 2, 3]
        self.assertEqual([True], logical_expr.evaluate(tuple1, None))