Skip to content

Commit

Permalink
Update unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-copeland committed Jul 11, 2024
1 parent ed895f4 commit 601372e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 188 deletions.
2 changes: 1 addition & 1 deletion unit_tests/test_Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ TEST(MatrixSerialTest, Test_mult_Vector_pointer)
*
*/
CAROM::Vector *w;
w = asymmetric_matrix.mult(v);
w = asymmetric_matrix.mult(*v);
EXPECT_FALSE(w->distributed());
EXPECT_EQ(w->dim(), 2);
EXPECT_DOUBLE_EQ((*w)(0), 2.0);
Expand Down
243 changes: 56 additions & 187 deletions unit_tests/test_Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,75 +309,6 @@ TEST(VectorSerialTest, Test_inner_product_const_reference)
EXPECT_DOUBLE_EQ(y.inner_product(y), 169);
}

TEST(VectorSerialTest, Test_inner_product_const_pointer)
{
CAROM::Vector *v = new CAROM::Vector(2, false);
(*v)(0) = 1;
(*v)(1) = 1;
CAROM::Vector *w = new CAROM::Vector(2, false);
(*w)(0) = -1;
(*w)(1) = 1;
CAROM::Vector *x = new CAROM::Vector(2, false);
(*x)(0) = 3;
(*x)(1) = 4;
CAROM::Vector *y = new CAROM::Vector(2, false);
(*y)(0) = 5;
(*y)(1) = 12;

/* [ 1, 1]^{T} [ 1, 1] = 2 */
EXPECT_DOUBLE_EQ(v->inner_product(v), 2);

/* [ 1, 1]^{T} [-1, 1] = 0 */
EXPECT_DOUBLE_EQ(v->inner_product(w), 0);

/* [ 1, 1]^{T} [ 3, 4] = 7 */
EXPECT_DOUBLE_EQ(v->inner_product(x), 7);

/* [ 1, 1]^{T} [ 5, 12] = 17 */
EXPECT_DOUBLE_EQ(v->inner_product(y), 17);

/* [-1, 1]^{T} [ 1, 1] = 0 */
EXPECT_DOUBLE_EQ(w->inner_product(v), 0);

/* [-1, 1]^{T} [-1, 1] = 2 */
EXPECT_DOUBLE_EQ(w->inner_product(w), 2);

/* [-1, 1]^{T} [ 3, 4] = 1 */
EXPECT_DOUBLE_EQ(w->inner_product(x), 1);

/* [-1, 1]^{T} [ 5, 12] = 7 */
EXPECT_DOUBLE_EQ(w->inner_product(y), 7);

/* [ 3, 4]^{T} [ 1, 1] = 7 */
EXPECT_DOUBLE_EQ(x->inner_product(v), 7);

/* [ 3, 4]^{T} [-1, 1] = 1 */
EXPECT_DOUBLE_EQ(x->inner_product(w), 1);

/* [ 3, 4]^{T} [ 3, 4] = 25 */
EXPECT_DOUBLE_EQ(x->inner_product(x), 25);

/* [ 3, 4]^{T} [ 5, 12] = 63 */
EXPECT_DOUBLE_EQ(x->inner_product(y), 63);

/* [ 5, 12]^{T} [ 1, 1] = 17 */
EXPECT_DOUBLE_EQ(y->inner_product(v), 17);

/* [ 5, 12]^{T} [-1, 1] = 7 */
EXPECT_DOUBLE_EQ(y->inner_product(w), 7);

/* [ 5, 12]^{T} [ 3, 4] = 63 */
EXPECT_DOUBLE_EQ(y->inner_product(x), 63);

/* [ 5, 12]^{T} [ 5, 12] = 169 */
EXPECT_DOUBLE_EQ(y->inner_product(y), 169);

delete v;
delete w;
delete x;
delete y;
}

TEST(VectorSerialTest, Test_plus_const_reference)
{
CAROM::Vector v(2, false);
Expand All @@ -393,102 +324,41 @@ TEST(VectorSerialTest, Test_plus_const_reference)
y(0) = 5;
y(1) = 12;

CAROM::Vector *result;

/* ( 1, 1) + ( 1, 1) = ( 2, 2) */
result = v.plus(v);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 2);
EXPECT_DOUBLE_EQ((*result)(1), 2);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(v);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 2);
EXPECT_DOUBLE_EQ((*result)(1), 2);
}

/* ( 1, 1) + (-1, 1) = ( 0, 2) */
result = v.plus(w);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 0);
EXPECT_DOUBLE_EQ((*result)(1), 2);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(w);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 0);
EXPECT_DOUBLE_EQ((*result)(1), 2);
}

/* ( 1, 1) + ( 3, 4) = ( 4, 5) */
result = v.plus(x);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 4);
EXPECT_DOUBLE_EQ((*result)(1), 5);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(x);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 4);
EXPECT_DOUBLE_EQ((*result)(1), 5);
}

/* ( 1, 1) + ( 5, 12) = ( 6, 13) */
result = v.plus(y);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 6);
EXPECT_DOUBLE_EQ((*result)(1), 13);
delete result;
result = NULL;
}

TEST(VectorSerialTest, Test_plus_const_pointer)
{
CAROM::Vector *v = new CAROM::Vector(2, false);
(*v)(0) = 1;
(*v)(1) = 1;
CAROM::Vector *w = new CAROM::Vector(2, false);
(*w)(0) = -1;
(*w)(1) = 1;
CAROM::Vector *x = new CAROM::Vector(2, false);
(*x)(0) = 3;
(*x)(1) = 4;
CAROM::Vector *y = new CAROM::Vector(2, false);
(*y)(0) = 5;
(*y)(1) = 12;

CAROM::Vector *result;

/* ( 1, 1) + ( 1, 1) = ( 2, 2) */
result = v->plus(v);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 2);
EXPECT_DOUBLE_EQ((*result)(1), 2);
delete result;
result = NULL;

/* ( 1, 1) + (-1, 1) = ( 0, 2) */
result = v->plus(w);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 0);
EXPECT_DOUBLE_EQ((*result)(1), 2);
delete result;
result = NULL;

/* ( 1, 1) + ( 3, 4) = ( 4, 5) */
result = v->plus(x);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 4);
EXPECT_DOUBLE_EQ((*result)(1), 5);
delete result;
result = NULL;

/* ( 1, 1) + ( 5, 12) = ( 6, 13) */
result = v->plus(y);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 6);
EXPECT_DOUBLE_EQ((*result)(1), 13);
delete result;
result = NULL;

delete v;
delete w;
delete x;
delete y;
{
std::unique_ptr<CAROM::Vector> result = v.plus(y);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 6);
EXPECT_DOUBLE_EQ((*result)(1), 13);
}
}

/* TODO([email protected]): Test cases where pointer already allocated */
Expand All @@ -513,43 +383,42 @@ TEST(VectorSerialTest, Test_plus_const_reference_pointer)
CAROM::Vector::plus tries to assign to that memory, resulting in a
segfault.
*/
CAROM::Vector *result = NULL;

/* ( 1, 1) + ( 1, 1) = ( 2, 2) */
v.plus(v, result);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 2);
EXPECT_DOUBLE_EQ((*result)(1), 2);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(v);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 2);
EXPECT_DOUBLE_EQ((*result)(1), 2);
}

/* ( 1, 1) + (-1, 1) = ( 0, 2) */
v.plus(w, result);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 0);
EXPECT_DOUBLE_EQ((*result)(1), 2);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(w);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 0);
EXPECT_DOUBLE_EQ((*result)(1), 2);
}

/* ( 1, 1) + ( 3, 4) = ( 4, 5) */
v.plus(x, result);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 4);
EXPECT_DOUBLE_EQ((*result)(1), 5);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(x);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 4);
EXPECT_DOUBLE_EQ((*result)(1), 5);
}

/* ( 1, 1) + ( 5, 12) = ( 6, 13) */
v.plus(y, result);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 6);
EXPECT_DOUBLE_EQ((*result)(1), 13);
delete result;
result = NULL;
{
std::unique_ptr<CAROM::Vector> result = v.plus(y);
EXPECT_FALSE(result->distributed());
EXPECT_EQ(result->dim(), 2);
EXPECT_DOUBLE_EQ((*result)(0), 6);
EXPECT_DOUBLE_EQ((*result)(1), 13);
}
}

/*
Expand Down

0 comments on commit 601372e

Please sign in to comment.