File: gtestBaseFixture.h

package info (click to toggle)
zfp 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,744 kB
  • sloc: cpp: 20,656; ansic: 18,871; pascal: 1,231; f90: 907; python: 255; makefile: 183; sh: 79; fortran: 70
file content (149 lines) | stat: -rw-r--r-- 3,927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "gtest/gtest.h"

#include <cmath>
#include <tuple>
#include <type_traits>

// assumes a constants/<dim><type>.h is already included

class ArrayNdTestFixture : public ::testing::TestWithParam<int> {
protected:
  double getRate() { return std::ldexp(1.0, GetParam() + 3); }
};



typedef std::tuple<int,int,int> testConfig;

#define TEST_RATE zfp_mode_fixed_rate
#define TEST_PREC zfp_mode_fixed_precision
#define TEST_ACCU zfp_mode_fixed_accuracy
#define TEST_RVRS zfp_mode_reversible

#define TEST_INDEX_IMP 0
#define TEST_INDEX_VRB 1
#define TEST_INDEX_HY4 2
#define TEST_INDEX_HY8 3

#define TEST_INDEX_TYPE_IMP zfp::index::implicit
#define TEST_INDEX_TYPE_VRB zfp::index::verbatim
#define TEST_INDEX_TYPE_HY4 zfp::index::hybrid4
#define TEST_INDEX_TYPE_HY8 zfp::index::hybrid8

class CArrayNdTestFixture : public ::testing::TestWithParam<testConfig> {
protected:
  static double         getRate(int param)      { return std::ldexp(1.0, param + 3); }
  static unsigned int   getPrecision(int param) { return 1u << (param + 3); }
  static double         getTolerance(int param) { return std::ldexp(1.0, -(1u << param)); }

  // get(0): config mode selection
  // get(1): config mode value selection
  // get(2): block index type selection
  zfp_config getConfig()
  {
    zfp_config config;

    switch(std::get<0>(GetParam())) {
      case zfp_mode_fixed_rate:
      {
        //TODO: check with/without align?
        config = zfp_config_rate(getRate(std::get<1>(GetParam())), true);
        break;
      }
      case zfp_mode_fixed_precision:
      {
        config = zfp_config_precision(getPrecision(std::get<1>(GetParam())));
        break;
      }
      case zfp_mode_fixed_accuracy:
      {
        config = zfp_config_accuracy(getTolerance(std::get<1>(GetParam())));
        break;
      }
      case zfp_mode_reversible:
      {
        config = zfp_config_reversible();
        break;
      }
      case zfp_mode_expert:
      {
        //TODO: do we need this one?
        //config = zfp_config_expert(uint minbits, uint maxbits, uint maxprec, int minexp);
        //break;
      }
      default:
      {
        config = zfp_config_none();
        break;
      }
    }
    return config;
  }

public:
  struct PrintToStringParamName
  {
    static std::string IndexToStr(int idx)
    {
      switch (idx)
      {
        case TEST_INDEX_IMP:
        {
            return "Implicit";
        }
        case TEST_INDEX_VRB:
        {
            return "Verbatim";
        }
        case TEST_INDEX_HY4:
        {
            return "Hybrid4";
        }
        case TEST_INDEX_HY8:
        {
            return "Hybrid8";
        }
        default:
        {
            return "BadIdxType";
        }
      }
    }

    template <class ParamType>
    std::string operator()(const testing::TestParamInfo<ParamType>& info) const
    {
       std::stringstream out;
       switch(std::get<0>(info.param))
       {
          case zfp_mode_fixed_rate:
          {
             out << "Fixed_Rate_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param));
             break;
          }
          case zfp_mode_fixed_precision:
          {
             out << "Fixed_Precision_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param));
             break;
          }
          case zfp_mode_fixed_accuracy:
          {
             out << "Fixed_Accuracy_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param));
             break;
          }
          case zfp_mode_reversible:
          {
             out << "Reversible_idx" << IndexToStr(std::get<2>(info.param));
             break;
          }
          case zfp_mode_expert:
          {
             out << "Expert_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param));
             break;
          }
       }
       return out.str();
    }
  };

};