LCOV - code coverage report
Current view: top level - source/tests - TestQuadraticOperator.cpp (source / functions) Hit Total Coverage
Test: LibForBES Unit Tests Lines: 33 33 100.0 %
Date: 2016-04-18 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * File:   TestQuadraticOperator.cpp
       3             :  * Author: Pantelis Sopasakis
       4             :  *
       5             :  * Created on Jul 24, 2015, 8:52:27 PM
       6             :  */
       7             : 
       8             : #include "TestQuadraticOperator.h"
       9             : 
      10             : 
      11             : 
      12           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestQuadraticOperator);
      13             : 
      14           1 : TestQuadraticOperator::TestQuadraticOperator() {
      15           1 : }
      16             : 
      17           2 : TestQuadraticOperator::~TestQuadraticOperator() {
      18           2 : }
      19             : 
      20           1 : void TestQuadraticOperator::setUp() {
      21           1 : }
      22             : 
      23           1 : void TestQuadraticOperator::tearDown() {
      24           1 : }
      25             : 
      26           1 : void TestQuadraticOperator::testCall() {
      27           1 :     size_t n = 10;
      28             : 
      29           1 :     Matrix Q = MatrixFactory::MakeRandomMatrix(n, n, 0.0, 10.0, Matrix::MATRIX_DENSE);
      30           2 :     Matrix x = MatrixFactory::MakeRandomMatrix(n, 1, 0.0, 10.0, Matrix::MATRIX_DENSE);
      31             : 
      32           1 :     LinearOperator *T = new MatrixOperator(Q);
      33             : 
      34           1 :     Function *F = new QuadraticOperator(*T);    
      35           1 :     Function *F2 = new Quadratic(Q);
      36             : 
      37             :     double fval, fval2, fval3;
      38           1 :     const double tol = 1e-8;
      39             :     
      40           2 :     Matrix grad, grad2;
      41             :     
      42           1 :     _ASSERT_EQ(ForBESUtils::STATUS_OK, F->call(x, fval, grad));
      43           1 :     _ASSERT_EQ(ForBESUtils::STATUS_OK, F2->call(x, fval2, grad2));
      44           1 :     _ASSERT_EQ(ForBESUtils::STATUS_OK, F->call(x, fval3));    
      45           1 :     _ASSERT_NUM_EQ(fval, fval2, tol);
      46           1 :     _ASSERT_NUM_EQ(fval2, fval3, tol);
      47           1 :     _ASSERT_NOT(grad2.isEmpty());
      48           1 :     _ASSERT_NOT(grad.isEmpty());
      49           1 :     _ASSERT(grad.isColumnVector());
      50           1 :     _ASSERT(grad2.isColumnVector());
      51           1 :     _ASSERT_EQ(n, grad.getNrows());
      52           1 :     _ASSERT_EQ(grad, grad2);
      53             :        
      54             : 
      55           1 :     _ASSERT_OK(delete T);
      56           1 :     _ASSERT_OK(delete F);
      57           2 :     _ASSERT_OK(delete F2);
      58           4 : }

Generated by: LCOV version 1.10