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

          Line data    Source code
       1             : /*
       2             :  * Morpheus_Vector_addScaleTest.cpp
       3             :  *
       4             :  *  Created on: Jul 28, 2016
       5             :  *      Author: amklinv
       6             :  */
       7             : 
       8             : #include "Morpheus_Vector.h"
       9             : #include <cmath>
      10             : #include <iostream>
      11             : #include <stdlib.h>
      12             : #include <time.h>
      13             : 
      14           1 : int main()
      15             : {
      16           1 :   bool testPassed = true;
      17           1 :   int numEntries = 10;
      18             : 
      19             :   // Seed the random number generator
      20           1 :   srand(time(NULL));
      21             : 
      22             :   // Create three vectors, all with 10 entries
      23           1 :   Morpheus::Vector vecA(numEntries);
      24           1 :   Morpheus::Vector vecB(numEntries);
      25           1 :   Morpheus::Vector vecC(numEntries);
      26             : 
      27             :   // Set the entries in vecA
      28             :   // Each entry is random
      29          11 :   for(int i=0; i<numEntries; i++) {
      30          10 :     vecA[i] = rand();
      31             :   }
      32             : 
      33             :   // Copy the entries of vecA to vecB
      34          11 :   for(int i=0; i<numEntries; i++) {
      35          10 :     vecB[i] = vecA[i];
      36             :   }
      37             : 
      38             :   // Scale vecB by -1
      39           1 :   vecB.scale(-1);
      40             : 
      41             :   // Compute vecC = vecA + vecB
      42           1 :   vecA.add(vecB, vecC);
      43             : 
      44             :   // vecC should be all 0s, so its norm should be too
      45           1 :   double norm2 = vecC.norm2();
      46             : 
      47           1 :   if(norm2 > 1e-10)
      48             :   {
      49           0 :     std::cout << "ERROR: C must be 0\n";
      50           0 :     testPassed = false;
      51             :   }
      52             : 
      53           1 :   if(testPassed)
      54           1 :     std::cout << "Add/scale test: PASSED!\n";
      55             :   else
      56           0 :     std::cout << "Add/scale test: FAILED!\n";
      57           3 : }

Generated by: LCOV version 1.12-4-g04a3c0e