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

          Line data    Source code
       1             : /*
       2             :  * File:   TestIndProbSimplex.cpp
       3             :  * Author: Pantelis Sopasakis
       4             :  *
       5             :  * Created on Jan 15, 2016, 5:38:56 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 "TestIndProbSimplex.h"
      22             : #include "IndProbSimplex.h"
      23             : #include "MatrixFactory.h"
      24             : 
      25             : 
      26           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestIndProbSimplex);
      27             : 
      28           3 : TestIndProbSimplex::TestIndProbSimplex() {
      29           3 : }
      30             : 
      31           6 : TestIndProbSimplex::~TestIndProbSimplex() {
      32           6 : }
      33             : 
      34           3 : void TestIndProbSimplex::setUp() {
      35           3 : }
      36             : 
      37           3 : void TestIndProbSimplex::tearDown() {
      38           3 : }
      39             : 
      40           1 : void TestIndProbSimplex::testCallProx() {
      41           1 :     const size_t n = 10;
      42             : 
      43           1 :     Function * F = new IndProbSimplex();
      44             : 
      45             :     double x_vals[n] = {0.910569988523029, -0.300000000000000,
      46             :         -0.500000000000000, 0.813112813610761, 0.383306318625529, 0.617279232316449,
      47           1 :         0.575494859702814, 0.530051704765016, 0.275069755821935, 0.248628959661970};
      48             : 
      49           1 :     Matrix x(n, 1, x_vals);
      50           2 :     Matrix x_orig(x);
      51           2 :     Matrix prox(n, 1);
      52           1 :     _ASSERT(F->category().defines_prox());
      53           1 :     int status = F->callProx(x, 1.0, prox);
      54           1 :     _ASSERT(ForBESUtils::is_status_ok(status));
      55             : 
      56             :     double prox_expected_vals[n] = {0.421268268739415, 0, 0, 0.323811093827147, 0,
      57           1 :         0.127977512532836, 0.086193139919200, 0.040749984981402, 0, 0};
      58           2 :     Matrix prox_expected = MatrixFactory::ShallowVector(prox_expected_vals, n, 0);
      59             : 
      60           1 :     double f_at_prox = 2.0;
      61           1 :     status = F->callProx(x, 1.0, prox, f_at_prox);
      62           1 :     _ASSERT(ForBESUtils::is_status_ok(status));
      63           1 :     _ASSERT_NUM_EQ(0.0, f_at_prox, 1e-14);
      64           1 :     _ASSERT_EQ(prox_expected, prox);
      65           1 :     _ASSERT_EQ(x_orig, x);
      66           2 :     delete F;
      67             : 
      68           1 : }
      69             : 
      70           1 : void TestIndProbSimplex::testCallProxLarge() {
      71           1 :     std::srand(10);
      72           1 :     const size_t n = 5e5;
      73           1 :     Function * F = new IndProbSimplex();
      74           1 :     Matrix x = MatrixFactory::MakeRandomMatrix(n, 1, 0.0, 1.0);
      75           2 :     Matrix prox(n, 1);
      76             : 
      77           1 :     _ASSERT(F->category().defines_prox());
      78             : 
      79             :     //    clock_t start = clock();
      80           1 :     int status = F->callProx(x, 1.0, prox);
      81             :     //    clock_t end = clock();
      82             :     //    float elapsed_time_secs = static_cast<float>(end - start)*1000.0 / CLOCKS_PER_SEC;
      83           1 :     _ASSERT(ForBESUtils::is_status_ok(status));
      84             : 
      85             :     //    std::cout << "\ntime = " << elapsed_time_secs << std::endl;
      86           2 :     delete F;
      87           1 : }
      88             : 
      89           1 : void TestIndProbSimplex::testCategory() {
      90           1 :     Function * F = new IndProbSimplex();
      91           1 :     _ASSERT(F->category().defines_prox());
      92           1 :     _ASSERT(F->category().defines_f());
      93           1 :     _ASSERT_NOT(F->category().defines_grad());
      94           1 :     _ASSERT_NOT(F->category().defines_conjugate());
      95           1 :     _ASSERT_NOT(F->category().defines_conjugate_grad());
      96           1 :     _ASSERT_NOT(F->category().defines_hessian());
      97           1 :     _ASSERT_NOT(F->category().defines_hessian_conj());
      98           1 :     delete F;
      99           4 : }
     100             : 

Generated by: LCOV version 1.10