1 |
jgs |
102 |
// $Id$ |
2 |
jgs |
82 |
/* |
3 |
|
|
***************************************************************************** |
4 |
|
|
* * |
5 |
|
|
* COPYRIGHT ACcESS - All Rights Reserved * |
6 |
|
|
* * |
7 |
|
|
* This software is the property of ACcESS. No part of this code * |
8 |
|
|
* may be copied in any form or by any means without the expressed written * |
9 |
|
|
* consent of ACcESS. Copying, use or modification of this software * |
10 |
|
|
* by any unauthorised person is illegal unless that person has a software * |
11 |
|
|
* license agreement with ACcESS. * |
12 |
|
|
* * |
13 |
|
|
***************************************************************************** |
14 |
|
|
*/ |
15 |
|
|
#include "escript/Data/DataAlgorithm.h" |
16 |
|
|
#include "DataAlgorithmAdapterTestCase.h" |
17 |
|
|
|
18 |
|
|
#include <iostream> |
19 |
|
|
#include <algorithm> |
20 |
|
|
#include <math.h> |
21 |
|
|
#include <limits> |
22 |
|
|
|
23 |
|
|
using namespace CppUnitTest; |
24 |
|
|
using namespace std; |
25 |
|
|
using namespace escript; |
26 |
|
|
|
27 |
|
|
void DataAlgorithmAdapterTestCase::setUp() { |
28 |
|
|
// |
29 |
|
|
// This is called before each test is run |
30 |
|
|
|
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
void DataAlgorithmAdapterTestCase::tearDown() { |
34 |
|
|
// |
35 |
|
|
// This is called after each test has been run |
36 |
|
|
|
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
void DataAlgorithmAdapterTestCase::testAll() { |
40 |
jgs |
102 |
|
41 |
jgs |
82 |
cout << endl; |
42 |
jgs |
102 |
|
43 |
jgs |
106 |
cout << "\tSize: " << sizeof(DataAlgorithmAdapter<FMin>) << endl; |
44 |
|
|
|
45 |
jgs |
102 |
cout << "\tTesting FMax." << endl; |
46 |
jgs |
106 |
DataAlgorithmAdapter<FMax> sup(numeric_limits<double>::min()); |
47 |
|
|
sup.resetResult(); |
48 |
|
|
sup(1); |
49 |
|
|
sup(2); |
50 |
|
|
sup(14); |
51 |
|
|
sup(3); |
52 |
|
|
assert(sup.getResult()==14); |
53 |
jgs |
102 |
|
54 |
|
|
cout << "\tTesting AbsMax." << endl; |
55 |
|
|
DataAlgorithmAdapter<AbsMax> Lsup(0); |
56 |
jgs |
106 |
Lsup.resetResult(); |
57 |
jgs |
82 |
Lsup(-2); |
58 |
|
|
Lsup(2); |
59 |
|
|
Lsup(5); |
60 |
jgs |
102 |
Lsup(-10); |
61 |
|
|
assert(Lsup.getResult()==10); |
62 |
|
|
|
63 |
|
|
cout << "\tTesting FMin." << endl; |
64 |
jgs |
82 |
DataAlgorithmAdapter<FMin> inf(numeric_limits<double>::max()); |
65 |
jgs |
106 |
inf.resetResult(); |
66 |
jgs |
82 |
inf(1); |
67 |
jgs |
102 |
inf(12); |
68 |
jgs |
82 |
inf(2); |
69 |
jgs |
102 |
inf(99); |
70 |
|
|
assert(inf.getResult()==1); |
71 |
|
|
|
72 |
jgs |
106 |
cout << "\tTesting Length." << endl; |
73 |
|
|
DataAlgorithmAdapter<Length> length(0); |
74 |
|
|
length.resetResult(); |
75 |
|
|
length(2); |
76 |
|
|
length(4); |
77 |
|
|
length(6); |
78 |
|
|
length(8); |
79 |
|
|
assert(length.getResult()==std::sqrt(120.0)); |
80 |
|
|
length.resetResult(); |
81 |
|
|
length(1.5); |
82 |
|
|
length(2.5); |
83 |
|
|
length(3.5); |
84 |
|
|
length(4.5); |
85 |
|
|
assert(length.getResult()==std::sqrt(41.0)); |
86 |
jgs |
102 |
|
87 |
jgs |
106 |
cout << "\tTesting Trace." << endl; |
88 |
|
|
DataAlgorithmAdapter<Trace> trace(0); |
89 |
|
|
trace.resetResult(); |
90 |
|
|
trace(1); |
91 |
|
|
trace(2); |
92 |
|
|
trace(3); |
93 |
|
|
trace(4); |
94 |
|
|
trace(5); |
95 |
|
|
assert(trace.getResult()==15); |
96 |
|
|
trace.resetResult(); |
97 |
|
|
trace(1.5); |
98 |
|
|
trace(2.5); |
99 |
|
|
trace(3.5); |
100 |
|
|
trace(4.5); |
101 |
|
|
trace(5.5); |
102 |
|
|
assert(trace.getResult()==17.5); |
103 |
|
|
|
104 |
jgs |
82 |
} |
105 |
|
|
|
106 |
|
|
TestSuite* DataAlgorithmAdapterTestCase::suite () |
107 |
|
|
{ |
108 |
|
|
// |
109 |
|
|
// create the suite of tests to perform. |
110 |
|
|
TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase"); |
111 |
|
|
|
112 |
|
|
testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll)); |
113 |
|
|
return testSuite; |
114 |
|
|
} |
115 |
|
|
|