示例#1
0
    def test_comparison_compare_neq(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_NEQ, tpl_exp,
                                        const_exp)

        # checking not equal
        tuple1 = [2, 2, 3]
        self.assertEqual(True, cmpr_exp.evaluate(tuple1, None))

        tuple1 = [3, 2, 3]
        self.assertEqual(True, cmpr_exp.evaluate(tuple1, None))
示例#2
0
    def test_comparison_compare_leq(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(2)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_LEQ, tpl_exp,
                                        const_exp)

        # checking lesser
        tuple1 = [1, 2, 3]
        self.assertEqual(True, cmpr_exp.evaluate(tuple1, None))
        # checking equal
        tuple2 = [2, 2, 3]
        self.assertEqual(True, cmpr_exp.evaluate(tuple2, None))
示例#3
0
    def test_comparison_compare_geq(self):
        const_exp1 = ConstantValueExpression(1)
        const_exp2 = ConstantValueExpression(1)
        const_exp3 = ConstantValueExpression(0)

        cmpr_exp1 = ComparisonExpression(ExpressionType.COMPARE_GEQ,
                                         const_exp1, const_exp2)

        cmpr_exp2 = ComparisonExpression(ExpressionType.COMPARE_GEQ,
                                         const_exp1, const_exp3)
        # checking equal
        self.assertEqual([True], cmpr_exp1.evaluate(None).frames[0].tolist())
        # checking greater equal
        self.assertEqual([True], cmpr_exp2.evaluate(None).frames[0].tolist())
示例#4
0
    def test_comparison_compare_contains(self):
        const_exp1 = ConstantValueExpression([1, 2], ColumnType.NDARRAY)
        const_exp2 = ConstantValueExpression([1, 5], ColumnType.NDARRAY)
        const_exp3 = ConstantValueExpression([1, 2, 3, 4], ColumnType.NDARRAY)

        cmpr_exp1 = ComparisonExpression(ExpressionType.COMPARE_CONTAINS,
                                         const_exp3, const_exp1)

        self.assertEqual([True], cmpr_exp1.evaluate(None).frames[0].tolist())

        cmpr_exp2 = ComparisonExpression(ExpressionType.COMPARE_CONTAINS,
                                         const_exp3, const_exp2)

        self.assertEqual([False], cmpr_exp2.evaluate(None).frames[0].tolist())
示例#5
0
    def test_comparison_compare_geq(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        cmpr_exp = ComparisonExpression(
            ExpressionType.COMPARE_GEQ,
            tpl_exp,
            const_exp
        )

        # checking greater x>=1
        tuple1 = [[2], 2, 3]
        self.assertEqual([True], cmpr_exp.evaluate(tuple1, None))
        # checking equal
        tuple2 = [[1], 2, 3]
        self.assertEqual([True], cmpr_exp.evaluate(tuple2, None))
示例#6
0
    def test_comparison_compare_lesser(self):
        const_exp1 = ConstantValueExpression(0)
        const_exp2 = ConstantValueExpression(2)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_LESSER,
                                        const_exp1, const_exp2)
        self.assertEqual([True], cmpr_exp.evaluate(None).frames[0].tolist())
示例#7
0
    def test_comparison_compare_lesser(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(2)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_LESSER, tpl_exp,
                                        const_exp)
        tuple1 = [1, 2, 3]
        self.assertEqual(True, cmpr_exp.evaluate(tuple1, None))
示例#8
0
    def test_comparison_compare_greater(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_GREATER,
                                        tpl_exp, const_exp)
        tuple1 = [2, 1, 1]
        self.assertEqual(True, cmpr_exp.evaluate(tuple1, None))
示例#9
0
    def test_comparison_compare_equal(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_EQUAL, tpl_exp,
                                        const_exp)
        # ToDo implement a generic tuple class
        # to fetch the tuple from table
        tuple1 = [1, 2, 3]
        self.assertEqual(True, cmpr_exp.evaluate(tuple1, None))
示例#10
0
    def test_comparison_compare_greater(self):
        const_exp1 = ConstantValueExpression(1)
        const_exp2 = ConstantValueExpression(0)

        cmpr_exp = ComparisonExpression(
            ExpressionType.COMPARE_GREATER,
            const_exp1,
            const_exp2
        )
        self.assertEqual([True], cmpr_exp.evaluate(None))
示例#11
0
    def test_comparison_compare_leq(self):
        const_exp1 = ConstantValueExpression(0)
        const_exp2 = ConstantValueExpression(2)
        const_exp3 = ConstantValueExpression(2)

        cmpr_exp1 = ComparisonExpression(
            ExpressionType.COMPARE_LEQ,
            const_exp1,
            const_exp2
        )

        cmpr_exp2 = ComparisonExpression(
            ExpressionType.COMPARE_LEQ,
            const_exp2,
            const_exp3
        )

        # checking lesser
        self.assertEqual([True], cmpr_exp1.evaluate(None))
        # checking equal
        self.assertEqual([True], cmpr_exp2.evaluate(None))
示例#12
0
    def test_compare_doesnt_broadcast_when_rhs_is_list(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression([1])

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_EQUAL, tpl_exp,
                                        const_exp)

        compare = type("compare", (), {
            "value": 1,
            "__eq__": lambda s, x: s.value == x
        })
        tuple1 = [[compare()], 2, 3]
        self.assertEqual([True], cmpr_exp.evaluate(tuple1, None))
示例#13
0
    def test_func_expr_with_cmpr_and_const_expr_should_work(self):
        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(1, 2 * np.ones((1, 1)), None)
        outcome_1 = Prediction(frame_1, ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(frame_1, ["bus"], [0.6])

        func = FunctionExpression(lambda x: [outcome_1, outcome_2])
        value_expr = ConstantValueExpression("car")
        expression_tree = ComparisonExpression(ExpressionType.COMPARE_EQUAL,
                                               func, value_expr)

        batch = FrameBatch(frames=[frame_1, frame_2])

        self.assertEqual([True, False], expression_tree.evaluate(batch))
示例#14
0
    def test_comparison_compare_equal(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(1)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_EQUAL, tpl_exp,
                                        const_exp)
        # ToDo implement a generic tuple class
        # to fetch the tuple from table
        compare = type("compare", (BasePrediction, ), {
            "value": 1,
            "__eq__": lambda s, x: s.value == x
        })
        tuple1 = [[compare()], 2, 3]
        self.assertEqual([True], cmpr_exp.evaluate(tuple1, None))
示例#15
0
    def test_func_expr_with_cmpr_and_const_expr_should_work(self):
        frames = create_dataframe(2)
        outcome_1 = Outcome(pd.DataFrame(
            {'labels': ["car", "bus"], 'scores': [0.5, 0.6]}), 'labels')
        outcome_2 = Outcome(pd.DataFrame(
            {'labels': ["bus"], 'scores': [0.6]}), 'labels')

        func = FunctionExpression(lambda x: [outcome_1, outcome_2])
        value_expr = ConstantValueExpression("car")
        expression_tree = ComparisonExpression(ExpressionType.COMPARE_EQUAL,
                                               func,
                                               value_expr)

        batch = Batch(frames=frames)

        self.assertEqual([True, False], expression_tree.evaluate(batch))
示例#16
0
    def test_comparison_compare_leq(self):
        tpl_exp = TupleValueExpression(0)
        const_exp = ConstantValueExpression(2)

        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_LEQ, tpl_exp,
                                        const_exp)

        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], [False]]
        output_value = cmpr_exp.evaluate(input_batch)
        self.assertEqual(expected_value, output_value)