LCOV - code coverage report
Current view: top level - Morpheus/test - Morpheus_Matrix_Tests.cpp (source / functions) Hit Total Coverage
Test: morpheus.info Lines: 21 28 75.0 %
Date: 2016-08-02 12:11:35 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Morpheus_Matrix_Tests.cpp
       3             :  *
       4             :  *  Created on: Jul 28, 2016
       5             :  *      Author: amklinv
       6             :  */
       7             : 
       8             : #include "Morpheus_Matrix.h"
       9             : #include <time.h>
      10             : #include <stdlib.h>
      11             : #include <iostream>
      12             : 
      13           1 : int main()
      14             : {
      15           1 :   bool testPassed = true;
      16             : 
      17             :   // Seed the random number generator
      18           1 :   srand(time(NULL));
      19             : 
      20             :   // Create a random matrix
      21           1 :   Morpheus::Matrix randMat(5,5);
      22           6 :   for(int r=0; r<5; r++)
      23             :   {
      24          30 :     for(int c=0; c<5; c++)
      25             :     {
      26          25 :       randMat(r,c) = rand();
      27             :     }
      28             :   }
      29             : 
      30             :   // Create an identity matrix
      31           1 :   Morpheus::Matrix eye(5,5);
      32           6 :   for(int r=0; r<5; r++)
      33             :   {
      34          30 :     for(int c=0; c<5; c++)
      35             :     {
      36          25 :       if(r == c)
      37           5 :         eye(r,c) = 1;
      38             :       else
      39          20 :         eye(r,c) = 0;
      40             :     }
      41             :   }
      42             : 
      43             :   // Multiply the two
      44           1 :   Morpheus::Matrix result(5,5);
      45           1 :   randMat.multiply(eye,result);
      46             : 
      47             :   // Assert that randMat is the same as the result
      48           1 :   if(!randMat.approxEqual(result,1e-10))
      49             :   {
      50           0 :     std::cout << "ERROR: The matrix product is incorrect\n";
      51           0 :     testPassed = false;
      52             :   }
      53             : 
      54           1 :   if(!eye.isSymmetric())
      55             :   {
      56           0 :     std::cout << "ERROR: The identity matrix should be symmetric\n";
      57           0 :     testPassed = false;
      58             :   }
      59             : 
      60           1 :   if(!eye.isUpperTriangular())
      61             :   {
      62           0 :     std::cout << "ERROR: The identity matrix should be upper triangular\n";
      63           0 :     testPassed = false;
      64             :   }
      65             : 
      66           1 :   if(testPassed)
      67           1 :     std::cout << "Matrix test: PASSED!\n";
      68             :   else
      69           0 :     std::cout << "Matrix test: FAILED!\n";
      70             : 
      71           3 : }

Generated by: LCOV version 1.12-4-g04a3c0e