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

          Line data    Source code
       1             : /*
       2             :  * File:   TestIndBall2.cpp
       3             :  * Author: chung
       4             :  *
       5             :  * Created on Nov 3, 2015, 5:21:20 PM
       6             :  * 
       7             :  * ForBES is free software: you can redistribute it and/or modify
       8             :  * it under the terms of the GNU Lesser General Public License as published by
       9             :  * the Free Software Foundation, either version 3 of the License, or
      10             :  * (at your option) any later version.
      11             :  *  
      12             :  * ForBES is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      15             :  * GNU Lesser General Public License for more details.
      16             :  * 
      17             :  * You should have received a copy of the GNU Lesser General Public License
      18             :  * along with ForBES. If not, see <http://www.gnu.org/licenses/>.
      19             :  */
      20             : 
      21             : #include "TestIndBall2.h"
      22             : #include "IndBall2.h"
      23             : 
      24             : 
      25           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestIndBall2);
      26             : 
      27           3 : TestIndBall2::TestIndBall2() {
      28           3 : }
      29             : 
      30           6 : TestIndBall2::~TestIndBall2() {
      31           6 : }
      32             : 
      33           3 : void TestIndBall2::setUp() {
      34           3 : }
      35             : 
      36           3 : void TestIndBall2::tearDown() {
      37           3 : }
      38             : 
      39           1 : void TestIndBall2::testCallProx() {
      40           1 :     double rho = 1.1;
      41           1 :     size_t n = 3;
      42           1 :     Matrix c(n, 1);
      43           1 :     c[0] = 1.0;
      44           1 :     c[1] = -0.5;
      45           1 :     c[2] = 3.0;
      46             : 
      47           1 :     Function * indB2 = new IndBall2(rho, c);
      48             : 
      49           2 :     Matrix x(n, 1);
      50           1 :     x[0] = 1.5;
      51           1 :     x[1] = 1.2;
      52           1 :     x[2] = 2.0;
      53             : 
      54           2 :     Matrix prox(n, 1);
      55           1 :     int status = indB2 -> callProx(x, 1.0, prox);
      56           1 :     _ASSERT_EQ(ForBESUtils::STATUS_OK, status);
      57           1 :     const double tol = 1e-9;
      58           1 :     _ASSERT_NUM_EQ(1.270310252950645, prox[0], tol);
      59           1 :     _ASSERT_NUM_EQ(0.419054860032192, prox[1], tol);
      60           1 :     _ASSERT_NUM_EQ(2.459379494098711, prox[2], tol);
      61             : 
      62             :     double f_at_prox;
      63           1 :     status = indB2 -> callProx(x, 1.0, prox, f_at_prox);
      64           1 :     _ASSERT_EQ(ForBESUtils::STATUS_OK, status);
      65           1 :     _ASSERT_EQ(0.0, f_at_prox);
      66             : 
      67           2 :     delete indB2;
      68           1 : }
      69             : 
      70           1 : void TestIndBall2::testCategory() {
      71           1 :     Function * indB2 = new IndBall2();
      72           1 :     _ASSERT_NOT(indB2->category().defines_f());
      73           1 :     _ASSERT(indB2->category().defines_prox());
      74           1 :     _ASSERT_NOT(indB2->category().defines_conjugate());
      75           1 :     _ASSERT_NOT(indB2->category().defines_grad());
      76           1 :     delete indB2;
      77           1 : }
      78             : 
      79           1 : void TestIndBall2::testFail() {
      80             :     Function * indB2;
      81           1 :     double rho = -1.0;
      82           1 :     _ASSERT_EXCEPTION(indB2 = new IndBall2(rho), std::invalid_argument);
      83           4 : }

Generated by: LCOV version 1.10