LCOV - code coverage report
Current view: top level - unit-tests - read_mesh_test.cxx (source / functions) Hit Total Coverage
Test: code_coverage_filter.info Lines: 24 24 100.0 %
Date: 2024-03-28 16:04:17 Functions: 10 10 100.0 %
Branches: 40 76 52.6 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * @file: read_mesh_test.cxx
       3                 :            :  * @brief: unit tests to test mesh metrics read from .mesh and .vtk files
       4                 :            :  * Each test reads 9 colin27 mesh files, reports and compares the:
       5                 :            :  *   1. number of tetra
       6                 :            :  *   2. number of points
       7                 :            :  *   3. number of regions
       8                 :            :  *   4. x_min x_max
       9                 :            :  *   5. y_min y_max
      10                 :            :  *   6. z_min z_max
      11                 :            :  *   7. volumes of each tetra
      12                 :            :  * 
      13                 :            :  *      @author: Shuran Wang
      14                 :            :  *      @date: August 1, 2020
      15                 :            :  */
      16                 :            : 
      17                 :            : #include "gtest/gtest.h"
      18                 :            : #include "pdt_plan.h"
      19                 :            : #include "read_mesh.h"
      20                 :            : #include "test_common.h"
      21                 :            : 
      22                 :            : #define PARAMS_FILE "%s/unit-tests/input_params/test_params/mesh_read_params/tumor%u_test_params.xml"
      23                 :            : #define GOLDEN_FILE "%s/unit-tests/golden_results/mesh_metrics/Colin27_tagged_tumor_%u.txt"
      24                 :            : 
      25                 :            : #define NUM_TESTS 9
      26                 :            : #define BUF_SIZE 255
      27                 :            : 
      28 [ +  - ][ +  - ]:         32 : GTEST_TEST(FileReadTests, MeshReadTest)
         [ +  - ][ -  + ]
      29                 :            : {
      30         [ +  + ]:         40 :     for (unsigned int i = 1; i <= NUM_TESTS; i++) {
      31                 :            :         // construct full path name
      32                 :            :         char params_file[BUF_SIZE];
      33                 :         36 :         snprintf(params_file, BUF_SIZE, PARAMS_FILE, PDT_SPACE_SRC_DIR, i);
      34                 :            : 
      35                 :            :         // read mesh file
      36 [ +  - ][ +  - ]:         36 :         pdt_plan * plan = new pdt_plan(params_file);
                 [ +  - ]
      37                 :            : 
      38                 :            :         // set the parameters for plan to read the mesh
      39         [ +  - ]:         36 :         plan->read_mesh();
      40         [ +  - ]:         36 :         mesh * data = plan->get_mesh();
      41                 :            : 
      42                 :            :         // compute metrics
      43         [ +  - ]:         72 :         vector <double> metrics = compute_mesh_metrics(data);
      44                 :            :         
      45                 :            :         // read pre-computed metrics
      46                 :            :         char golden_file[BUF_SIZE];
      47                 :         36 :         snprintf(golden_file, BUF_SIZE, GOLDEN_FILE, PDT_SPACE_SRC_DIR, i);
      48 [ +  - ][ +  - ]:         72 :         vector <double> golden = readGoldenResult(golden_file);
      49                 :            : 
      50                 :            :         // compares and checks if error is less than 0.001%
      51 [ +  - ][ +  - ]:         36 :         compare_results (golden, metrics, 0.00001, "mesh");
         [ +  - ][ +  - ]
      52                 :            : 
      53                 :            :         // free memory
      54         [ +  - ]:         36 :         delete plan;
      55                 :            :     }
      56                 :          4 : }
      57                 :            : 
      58                 :            : #define VTK_PARAMS_FILE "%s/unit-tests/input_params/test_params/mesh_read_params/tumor%u_vtk_test_params.xml"
      59 [ +  - ][ +  - ]:         32 : GTEST_TEST(FileReadTests, VTKReadTest)
         [ +  - ][ -  + ]
      60                 :            : {
      61         [ +  + ]:         40 :     for (unsigned int i = 1; i <= NUM_TESTS; i++) {
      62                 :            :         // construct full path name
      63                 :            :         char params_file[BUF_SIZE];
      64                 :         36 :         snprintf(params_file, BUF_SIZE, VTK_PARAMS_FILE, PDT_SPACE_SRC_DIR, i);
      65                 :            : 
      66                 :            :         // read mesh file
      67 [ +  - ][ +  - ]:         36 :         pdt_plan * plan = new pdt_plan(params_file);
                 [ +  - ]
      68                 :            : 
      69                 :            :         // set the parameters for plan to read the mesh
      70         [ +  - ]:         36 :         plan->read_mesh();
      71         [ +  - ]:         36 :         mesh * data = plan->get_mesh();
      72                 :            : 
      73                 :            :         // compute metrics
      74         [ +  - ]:         72 :         vector <double> metrics = compute_mesh_metrics(data);
      75                 :            :         
      76                 :            :         // read pre-computed metrics
      77                 :            :         char golden_file[BUF_SIZE];
      78                 :         36 :         snprintf(golden_file, BUF_SIZE, GOLDEN_FILE, PDT_SPACE_SRC_DIR, i);
      79 [ +  - ][ +  - ]:         72 :         vector <double> golden = readGoldenResult(golden_file);
      80                 :            : 
      81                 :            :         // compares and checks if error is less than 0.001%
      82 [ +  - ][ +  - ]:         36 :         compare_results (golden, metrics, 0.00001, "vtk");
         [ +  - ][ +  - ]
      83                 :            : 
      84                 :            :         // free memory
      85         [ +  - ]:         36 :         delete plan;
      86                 :            :     }
      87 [ +  - ][ +  - ]:         20 : }

Generated by: LCOV version 1.12