test_CompactRealDftData.cxx
Go to the documentation of this file.
1 // test_CompactRealDftData.cxx
2 //
3 // David Adams
4 // April 2019
5 //
6 // Test CompactRealDftData.
7 
9 #include <string>
10 #include <iostream>
11 #include <fstream>
12 #include <sstream>
13 #include <vector>
14 #include <iomanip>
15 #include <cmath>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::ostringstream;
24 using std::ofstream;
25 using std::vector;
26 using std::setw;
27 using std::fixed;
28 
30 using Index = Dft::Index;
32 
33 //**********************************************************************
34 
35 int test_CompactRealDftData(bool useExistingFcl) {
36  const string myname = "test_RealDftData: ";
37 #ifdef NDEBUG
38  cout << myname << "NDEBUG must be off." << endl;
39  abort();
40 #endif
41  string line = "-----------------------------";
43 
44  cout << myname << line << endl;
45  cout << myname << "Create DFT." << endl;
46  FloatVector amps = { 5.0, 4.0, 3.0, 2.0, 1.0 };
47  FloatVector phas = { 0.0, 0.5, 1.0, 2.0, 4.0 };
48  Index namp = amps.size();
49  Index npha = phas.size();
50  Index nsam = namp + npha - 1;
51  assert( amps.size() == namp );
52  assert( phas.size() == npha );
53  cout << myname << "Sample length: " << nsam << endl;
54 
55  cout << myname << line << endl;
56  cout << myname << "Create invalid DFT objects." << endl;
57  FloatVector badvals = {11.1, 22.2};
58  Dft dftbad1(mynorm, amps, badvals);
59  assert ( ! dftbad1.size() );
60  Dft dftbad2(mynorm, badvals, phas);
61  assert ( ! dftbad2.size() );
62 
63  cout << myname << line << endl;
64  cout << myname << "Create DFT object with data." << endl;
65  Dft dft(mynorm, amps, phas);
66  cout << myname << " # samples: " << dft.size() << endl;
67  cout << myname << " Power: " << dft.power() << endl;
68  assert( dft.normalization().isValid() );
69  assert( dft.isValid() );
70  assert( dft.size() );
71  assert( dft.nCompact() == namp );
72  assert( dft.nAmplitude() == namp );
73  assert( dft.nPhase() == npha );
74  assert( dft.nSample() == nsam );
75  assert( dft.normalization().isStandard() );
76  assert( ! dft.normalization().isConsistent() );
77  assert( ! dft.normalization().isBin() );
78  assert( dft.normalization().isUnit() );
79  assert( ! dft.normalization().isPower() );
80 
81  // Copy data out.
82  cout << myname << line << endl;
83  cout << myname << "Copy data out." << endl;
84  FloatVector amps1, phas1;
85  dft.copyOut(amps1, phas1);
86  assert( dft.isValid() );
87  assert( dft.size() );
88  assert( dft.nCompact() == namp );
89  assert( dft.nAmplitude() == namp );
90  assert( dft.nPhase() == npha );
91  assert( dft.nSample() == nsam );
92  assert( amps1 == amps );
93  assert( phas1 == phas );
94 
95  // Move data out.
96  cout << myname << line << endl;
97  cout << myname << "Move data out." << endl;
98  FloatVector amps2, phas2;
99  dft.moveOut(amps2, phas2);
100  assert( ! dft.isValid() );
101  assert( dft.normalization().isValid() );
102  assert( dft.size() == 0 );
103  assert( dft.nCompact() == 0 );
104  assert( dft.nAmplitude() == 0 );
105  assert( dft.nPhase() == 0 );
106  assert( dft.nSample() == 0 );
107  assert( amps2 == amps );
108  assert( phas2 == phas );
109 
110  cout << myname << line << endl;
111  cout << myname << "Done." << endl;
112  return 0;
113 }
114 
115 //**********************************************************************
116 
117 int main(int argc, char* argv[]) {
118  bool useExistingFcl = false;
119  if ( argc > 1 ) {
120  string sarg(argv[1]);
121  if ( sarg == "-h" ) {
122  cout << "Usage: " << argv[0] << " [ARG]" << endl;
123  cout << " If ARG = true, existing FCL file is used." << endl;
124  return 0;
125  }
126  useExistingFcl = sarg == "true" || sarg == "1";
127  }
128  return test_CompactRealDftData(useExistingFcl);
129 }
130 
131 //**********************************************************************
std::string string
Definition: nybbler.cc:12
struct vector vector
unsigned int Index
int copyOut(FloatVector &amps, FloatVector &phas) const
int main(int argc, char *argv[])
virtual bool isValid() const
Definition: RealDftData.h:42
int test_CompactRealDftData(bool useExistingFcl)
Index size() const
Definition: RealDftData.h:35
Index nCompact() const override
Index nAmplitude() const
unsigned int Index
Definition: RealDftData.h:25
F power() const
Definition: RealDftData.h:95
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Index nSample() const override
std::vector< F > FloatVector
void line(double t, double *p, double &x, double &y, double &z)
const Norm & normalization() const override
Dft::FloatVector FloatVector
int moveOut(FloatVector &amps, FloatVector &phas)
QTextStream & endl(QTextStream &s)