-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
63 lines (52 loc) · 2.35 KB
/
Copy pathtest.cpp
File metadata and controls
63 lines (52 loc) · 2.35 KB
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
/*-------------------------------------------------------------------------*\
Basic unit test for InputFile, typses and Timing files
// Developed by:
// - Ali Q Raeini <a.q.raeini@gmail.com> (2020-2022)
\*-------------------------------------------------------------------------*/
#include <fstream>
#include <iostream>
#include <vector>
#include <array>
#include <memory>
#include <assert.h>
#include "globals.h"
#include "InputFile.h"
#include "profilers.h"
//#include "SiRun.h"
#include "typses.h"
using namespace std;
int main() {
int nErrs=0; // number of errors, if any
#define TEST nErrs+=ensure
try {
const double small=1e-64;
Timing tim;
tim("Testing InputFile");
{ cout<<"Testing InputFile inp: { ";
InputFile inp;
inp.add("one", "1");
int oneInInputFile=0;
TEST( inp.lookup("one", oneInInputFile), "checking `addKeyword` data exist" );
TEST( oneInInputFile == 1, "getting data into an an already allocated integer" );
TEST( inp.getOr("one",2) == 1, "looking up an integer" );
TEST( inp.getOr("notthere",2) == 2, "setting default value for non-existing data" );
inp.add("dbl3_235", " 2 3 5." );
TEST( (mag(inp.getOr("dbl3_235",dbl3()))-30) < small, "getting data as dbl3" );
TEST( inp.getOr("dbl3_235",string()) == "2", "getting the first number as string" );
TEST( inp["dbl3_235"] == " 2 3 5.", "getting raw string data using operator [], not-recommended" );
} cout<<" }"<<endl;
tim("Testing vars<T>" );
{ cout<<"Testing vars<T> (dbls, ints, dbl3s): {";
array<int,6> oneto6= {1,2,3,4,5,6};
TEST( piece<int>(&oneto6[0],6).sum() == 3*7, "piece<int> construction and summation" );
TEST( abs(dbls({1.,2.,3.,4.,5.,6.}).sum()-3*7) < small, "dbl3 construction and summation" );
TEST( mag(dbl3s(5,dbl3(1,1,1)).sum()-dbl3(5,5,5))<small, "dbl3s construction and summation" );
} cout<<" }"<<endl;
tim("Testing Timing" );
TEST( tim.times.size()==2, "`Timing` data collection" ); // carefull when moving around, this can fail, last one will be added later
}
catch (std::exception &exc) { std::cerr << "\n\n Exception on processing: \n" << exc.what() << " Aborting! \n" << endl; return 1; }
catch (...) { std::cerr << "\n\n Unknown exception! \n Aborting! \n" << endl; return 1; }
if(nErrs) cout<<nErrs<<" fails."<<endl; else cout<<"All tests passed."<<endl;
return nErrs;
}