You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

177 lines
3.3 KiB

#include "CppUTest/TestHarness.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTest/TestOutput.h"
#include "CppUTest/TestTestingFixture.h"
#include "mat.h"
#define TESTSIZE 4
int testMat [TESTSIZE][TESTSIZE];
int testVec [TESTSIZE];
TEST_GROUP(Matrix)
{
void setup()
{
int i = 1;
int j = 1;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
testMat[x][y] = i++;
}
testVec[x] = j++;
}
}
void teardown()
{
}
};
TEST(Matrix, vectorMultiply)
{
Mat<int, TESTSIZE> a = testMat;
Vec<int, TESTSIZE> v = testVec;
//Vec<int, TESTSIZE> b = a * v;
for (int x = 0; x <TESTSIZE ; x++)
{
int val = 0;
for (int y = 0; y <TESTSIZE ; y++)
{
val += testMat[x][y] * testVec[x];
}
//CHECK_EQUAL(val,b(x));
}
}
TEST(Matrix, scalarDivide)
{
Mat<int, TESTSIZE> a = testMat;
a = a / 5;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
int val = testMat[x][y] / 5;
CHECK_EQUAL(val,a(x,y));
}
}
}
TEST(Matrix, scalarSubstract)
{
Mat<int, TESTSIZE> a = testMat;
a = a - 5;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
int val = testMat[x][y] - 5;
CHECK_EQUAL(val,a(x,y));
}
}
}
TEST(Matrix, scalarAdd)
{
Mat<int, TESTSIZE> a = testMat;
a = a + 5;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
int val = testMat[x][y] + 5;
CHECK_EQUAL(val,a(x,y));
}
}
}
TEST(Matrix, scalarMultiply)
{
Mat<int, TESTSIZE> a = testMat;
a = a + 5;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
int val = testMat[x][y] + 5;
CHECK_EQUAL(val,a(x,y));
}
}
}
TEST(Matrix, setIndex)
{
Mat<int,TESTSIZE> a ;
Mat<int,TESTSIZE> b ;
int val = 1;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
a(x,y) = val;
CHECK_EQUAL(val,a(x,y));
val++;
}
}
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
CHECK_EQUAL(0,b(x,y));
}
}
b = a;
val = 1;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
a(x,y) = val;
CHECK_EQUAL(val,b(x,y));
val++;
}
}
}
TEST(Matrix, initAndSet)
{
Mat<int,TESTSIZE> a ;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
int val = (x+1)*TESTSIZE+y;
a(x,y) = val;
}
}
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
int val = (x+1)*TESTSIZE+y;
CHECK_EQUAL(val,a(x,y));
}
}
}
TEST(Matrix, initZeroed)
{
Mat<int,TESTSIZE> a ;
for (int x = 0; x <TESTSIZE ; x++)
{
for (int y = 0; y <TESTSIZE ; y++)
{
CHECK_EQUAL(0 , a(x,y) );
}
}
}