Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87843654
Matrix_Vector_Tests.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Oct 15, 07:11
Size
3 KB
Mime Type
text/x-c
Expires
Thu, Oct 17, 07:11 (2 d)
Engine
blob
Format
Raw Data
Handle
21664362
Attached To
R7934 PCSC_project
Matrix_Vector_Tests.cpp
View Options
//
// Created by choitel on 12/13/18.
//
#include <gtest/gtest.h>
#include <io.hpp>
#include "LinSys.hpp"
using testing::Eq;
namespace {
class Matrix_Test : public testing::Test {
protected:
// You can remove any or all of the following functions if its body
// is empty.
Matrix_Test() {
// You can do set-up work for each test here.
}
~Matrix_Test() override {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
void SetUp() override {
// Code here will be called immediately after the constructor (right
// before each test).
int size=3;
Matrix A(size);
A(1,1)=25;A(1,2)=15;A(1,3)=-5;
A(2,1)=15;A(2,2)=18;A(2,3)=2;
A(3,1)=-5;A(3,2)=2;A(3,3)=11;
Matrix B(size);
B(1,1)=3;B(1,2)=2;B(1,3)=3;
B(2,1)=4;B(2,2)=1;B(2,3)=2;
B(3,1)=3;B(3,2)=2;B(3,3)=7;
Matrix C(size);
C(1,1)=6;C(1,2)=4;C(1,3)=6;
C(2,1)=8;C(2,2)=2;C(2,3)=4;
C(3,1)=6;C(3,2)=4;C(3,3)=14;
}
void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
}
// Objects declared here can be used by all tests in the test case for Foo.
};
}
TEST_F(Matrix_Test, Sum_of_Matrix) {
int size=3;
Matrix A(size);
A(1,1)=3;A(1,2)=2;A(1,3)=3;
A(2,1)=4;A(2,2)=1;A(2,3)=2;
A(3,1)=3;A(3,2)=2;A(3,3)=7;
Matrix B(size);
B(1,1)=3;B(1,2)=2;B(1,3)=3;
B(2,1)=4;B(2,2)=1;B(2,3)=2;
B(3,1)=3;B(3,2)=2;B(3,3)=7;
Matrix C(size);
C(1,1)=6;C(1,2)=4;C(1,3)=6;
C(2,1)=8;C(2,2)=2;C(2,3)=4;
C(3,1)=6;C(3,2)=4;C(3,3)=14;
Matrix Sum(size,size);
Sum = A + B;
for(int i=1;i<=size;i++){
for(int j=1;j<=size;j++){
ASSERT_EQ(C(i,j),Sum(i,j));
}
}
}
TEST_F(Matrix_Test, Sum_Vector){
int size=3;
Vector a(size);
a(1)=1; a(2)=1; a(3)=3;
Vector b(size);
b(1)=2; b(2)=4; b(3)=5;
Vector c(size);
c(1) = 3; c(2)=5; c(3)=8;
Vector Sum(size);
Sum = a + b;
for (int i=1;i<=size;++i){
ASSERT_EQ(c(i),Sum(i));
}
}
TEST_F(Matrix_Test, Product_matrix){
int size=3;
Matrix A(size);
A(1,1)=3;A(1,2)=2;A(1,3)=3;
A(2,1)=4;A(2,2)=1;A(2,3)=2;
A(3,1)=3;A(3,2)=2;A(3,3)=7;
Matrix B(size);
B(1,1)=3;B(1,2)=2;B(1,3)=3;
B(2,1)=4;B(2,2)=1;B(2,3)=2;
B(3,1)=3;B(3,2)=2;B(3,3)=7;
Matrix C(size);
C(1,1)=26;C(1,2)=14;C(1,3)=34;
C(2,1)=22;C(2,2)=13;C(2,3)=28;
C(3,1)=38;C(3,2)=22;C(3,3)=62;
Matrix product(size,size);
product = A*B;
for(int i=1;i<=size;i++){
for(int j=1;j<=size;j++){
ASSERT_EQ(C(i,j),product(i,j));
}
}
}
TEST_F(Matrix_Test, Access_index){
int size=3;
Matrix C(size);
C(1,1)=6;C(1,2)=4;C(1,3)=6;
C(2,1)=8;C(2,2)=2;C(2,3)=4;
C(3,1)=6;C(3,2)=4;C(3,3)=14;
for(int i=1;i<=size;i++){
for(int j=1;j<=size;j++){
// EXPECT_THROW(C(0,0), );
}
}
}
Event Timeline
Log In to Comment