MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_Exp_OP_ADD

Function test_Exp_OP_ADD

tests/unit/test_algebraic_expression.c:597–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595}
596
597void test_Exp_OP_ADD() {
598 // Exp = A + B
599 RG_Matrix A;
600 RG_Matrix B;
601 RG_Matrix res;
602 GrB_Matrix expected;
603
604 // A
605 // 1 1
606 // 0 0
607 RG_Matrix_new(&A, GrB_BOOL, 2, 2);
608 RG_Matrix_setElement_BOOL(A, 0, 0);
609 RG_Matrix_setElement_BOOL(A, 0, 1);
610
611 // B
612 // 0 1
613 // 1 1
614 RG_Matrix_new(&B, GrB_BOOL, 2, 2);
615 RG_Matrix_setElement_BOOL(B, 0, 1);
616 RG_Matrix_setElement_BOOL(B, 1, 0);
617 RG_Matrix_setElement_BOOL(B, 1, 1);
618
619 // expected
620 // 1 1
621 // 1 1
622 GrB_Matrix_new(&expected, GrB_BOOL, 2, 2);
623 GrB_Matrix_setElement_BOOL(expected, true, 0, 0);
624 GrB_Matrix_setElement_BOOL(expected, true, 0, 1);
625 GrB_Matrix_setElement_BOOL(expected, true, 1, 0);
626 GrB_Matrix_setElement_BOOL(expected, true, 1, 1);
627
628 rax *matrices = raxNew();
629 raxInsert(matrices, (unsigned char *)"A", strlen("A"), A, NULL);
630 raxInsert(matrices, (unsigned char *)"B", strlen("B"), B, NULL);
631 AlgebraicExpression *exp = AlgebraicExpression_FromString("A+B", matrices);
632
633 // Matrix used for intermidate computations of AlgebraicExpression_Eval
634 // but also contains the result of expression evaluation.
635 RG_Matrix_new(&res, GrB_BOOL, 2, 2);
636 AlgebraicExpression_Eval(exp, res);
637
638 // Using the A matrix described above,
639 // A + B = C.
640 TEST_ASSERT(_compare_matrices(expected, res));
641
642 raxFree(matrices);
643 RG_Matrix_free(&A);
644 RG_Matrix_free(&B);
645 RG_Matrix_free(&res);
646 GrB_Matrix_free(&expected);
647 AlgebraicExpression_Free(exp);
648}
649
650void test_Exp_OP_MUL() {
651 // Exp = A * I

Callers

nothing calls this directly

Calls 9

RG_Matrix_newFunction · 0.85
GrB_Matrix_newFunction · 0.85
AlgebraicExpression_EvalFunction · 0.85
_compare_matricesFunction · 0.85
RG_Matrix_freeFunction · 0.85
GrB_Matrix_freeFunction · 0.85
AlgebraicExpression_FreeFunction · 0.85

Tested by

no test coverage detected