Browse Source

Changes to unit testing

enhancement_3
Trevor Irons 7 years ago
parent
commit
22f62c9a38

+ 15
- 0
LemmaCore/include/ASCIIParser.h View File

@@ -43,6 +43,18 @@ class ASCIIParser : public LemmaObject {
43 43
      */
44 44
     static std::shared_ptr< ASCIIParser >  NewSP();
45 45
 
46
+    /**
47
+     *  Constructs an object from a YAML serialization
48
+     *  @return a std::shared_ptr of type ASCIIParser
49
+     */
50
+    static std::shared_ptr< ASCIIParser >  DeSerialize( const YAML::Node& node );
51
+
52
+    /**
53
+     *  Uses YAML to serialize this object.
54
+     *  @return a YAML::Node
55
+     */
56
+    YAML::Node Serialize() const;
57
+
46 58
     // ====================  OPERATORS     =======================
47 59
 
48 60
     // ====================  OPERATIONS    =======================
@@ -113,6 +125,9 @@ class ASCIIParser : public LemmaObject {
113 125
     /** Default protected constructor, use New */
114 126
     ASCIIParser ( );
115 127
 
128
+    /** Constructor using YAML::Node */
129
+    ASCIIParser ( const YAML::Node& node );
130
+
116 131
     /** Default protected destructor, use Delete */
117 132
     ~ASCIIParser ();
118 133
 

+ 16
- 6
LemmaCore/include/CubicSplineInterpolator.h View File

@@ -71,6 +71,16 @@ class CubicSplineInterpolator : public LemmaObject {
71 71
      */
72 72
     static std::shared_ptr<CubicSplineInterpolator> NewSP();
73 73
 
74
+    /**
75
+     *  Uses YAML to serialize this object.
76
+     *  @return a YAML::Node
77
+     */
78
+    YAML::Node Serialize() const;
79
+
80
+    /**
81
+     *   Constructs an object from a YAML::Node.
82
+     */
83
+    static std::shared_ptr< CubicSplineInterpolator > DeSerialize(const YAML::Node& node);
74 84
 
75 85
     // ====================  OPERATORS     =======================
76 86
 
@@ -143,6 +153,9 @@ class CubicSplineInterpolator : public LemmaObject {
143 153
     /** Default protected constructor, use New */
144 154
     CubicSplineInterpolator ( );
145 155
 
156
+    /** Protected DeDerializing constructor, use factory DeSerialize  method*/
157
+    CubicSplineInterpolator (const YAML::Node& node);
158
+
146 159
     /** Default protected destructor, smart pointers auto delete */
147 160
     ~CubicSplineInterpolator ();
148 161
 
@@ -154,12 +167,6 @@ class CubicSplineInterpolator : public LemmaObject {
154 167
 
155 168
     // ====================  OPERATIONS    =======================
156 169
 
157
-    /**
158
-        Performs spline fitting.
159
-     */
160
-    //void Spline() {
161
-    // }
162
-
163 170
     /** Finds the interval of knots in spline to use for integration.
164 171
      */
165 172
     int Interval(const Real& x);
@@ -182,3 +189,6 @@ class CubicSplineInterpolator : public LemmaObject {
182 189
 }		// -----  end of Lemma  name  -----
183 190
 
184 191
 #endif   // ----- #ifndef CUBICSPLINEINTERPOLATOR_INC  -----
192
+
193
+/* vim: set tabstop=4 expandtab: */
194
+/* vim: set filetype=cpp: */

+ 21
- 42
LemmaCore/include/RectilinearGrid.h View File

@@ -44,6 +44,17 @@ namespace Lemma {
44 44
              */
45 45
             static std::shared_ptr<RectilinearGrid> NewSP();
46 46
 
47
+            /**
48
+             *  Uses YAML to serialize this object.
49
+             *  @return a YAML::Node
50
+             */
51
+            YAML::Node Serialize() const;
52
+
53
+            /**
54
+             *   Constructs an object from a YAML::Node.
55
+             */
56
+            static std::shared_ptr< RectilinearGrid > DeSerialize(const YAML::Node& node);
57
+
47 58
             // ====================  OPERATORS     =======================
48 59
 
49 60
             // ====================  OPERATIONS    =======================
@@ -150,10 +161,13 @@ namespace Lemma {
150 161
 
151 162
             // ====================  LIFECYCLE     =======================
152 163
 
153
-            /// Default protected constructor.
164
+            /** Default protected constructor. */
154 165
             RectilinearGrid ( );
155 166
 
156
-            /// Default protected constructor.
167
+            /** Protected DeDerializing constructor, use factory DeSerialize  method*/
168
+            RectilinearGrid (const YAML::Node& node);
169
+
170
+            /** Default protected constructor. */
157 171
             ~RectilinearGrid ();
158 172
 
159 173
             // ====================  DATA MEMBERS  =========================
@@ -185,51 +199,16 @@ namespace Lemma {
185 199
             /// Cell spacing in the z dimension
186 200
             VectorXr dz;
187 201
 
188
-/*          @todo find a good way to store models that works with portions threadprivate
189
-            /// Container holding Vectors of Real data at centre of cell.
190
-            std::vector<VectorXr>   RealCellData;
191
-
192
-            /// Container holding names of Real data
193
-            std::vector<std::string> RealCellDataNames;
194
-
195
-            /// Container holding Vectors of Real data on edges.
196
-            std::vector<VectorXr>   RealEdgeData;
197
-
198
-            /// Container holding names of Real data on edges
199
-            std::vector<std::string> RealEdgeDataNames;
200
-
201
-            /// Container holding Vectors of Complex data on edges.
202
-            std::vector<VectorXcr>   ComplexEdgeData;
203
-
204
-            /// Container holding names of Real data on edges
205
-            std::vector<std::string> ComplexEdgeDataNames;
206
-
207
-            /// Container holding Vectors of Real properties.
208
-            std::vector<VectorXr>   RealCellProperties;
209
-
210
-            /// Container holding names of Real cell properties
211
-            std::vector<std::string> RealCellPropertyNames;
212
-
213
-            /// Container holding Vectors of Real data.
214
-            std::vector<VectorXcr>   ComplexCellData;
215
-
216
-            /// Container holding names of Real data
217
-            std::vector<std::string> ComplexCellDataNames;
218
-
219
-            /// Container holding Vectors of Complex properties.
220
-            std::vector<VectorXcr>   ComplexCellProperties;
221
-
222
-            /// Container holding names of Real cell properties
223
-            std::vector<std::string> ComplexCellPropertyNames;
224
-*/
225 202
         private:
226 203
 
227
-
228
-        /** ASCII string representation of the class name */
229
-        static constexpr auto CName = "RectilinearGrid";
204
+            /** ASCII string representation of the class name */
205
+            static constexpr auto CName = "RectilinearGrid";
230 206
 
231 207
     }; // -----  end of class  RectilinearGrid  -----
232 208
 
233 209
 }		// -----  end of Lemma  name  -----
234 210
 
235 211
 #endif   // ----- #ifndef RECTILINEARGRID_INC  -----
212
+
213
+/* vim: set tabstop=4 expandtab: */
214
+/* vim: set filetype=cpp: */

+ 34
- 0
LemmaCore/src/ASCIIParser.cpp View File

@@ -54,6 +54,30 @@ namespace Lemma {
54 54
 
55 55
     //--------------------------------------------------------------------------------------
56 56
     //       Class:  ASCIIParser
57
+    //      Method:  Serialize
58
+    //--------------------------------------------------------------------------------------
59
+    YAML::Node  ASCIIParser::Serialize (  ) const {
60
+        YAML::Node node = LemmaObject::Serialize();;
61
+        node.SetTag( GetName() );
62
+        node["CommentString"] = CommentString;
63
+        node["BufferSize"] = BufferSize;
64
+        return node;
65
+    }		// -----  end of method ASCIIParser::Serialize  -----
66
+
67
+    //--------------------------------------------------------------------------------------
68
+    //       Class:  ASCIIParser
69
+    //      Method:  DeSerialize
70
+    //--------------------------------------------------------------------------------------
71
+    std::shared_ptr<ASCIIParser> ASCIIParser::DeSerialize ( const YAML::Node& node  ) {
72
+        if (node.Tag() != "ASCIIParser") {
73
+            throw  DeSerializeTypeMismatch( "ASCIIParser", node.Tag());
74
+        }
75
+        std::shared_ptr<ASCIIParser> Object(new  ASCIIParser(node), LemmaObjectDeleter() );
76
+        return Object ;
77
+    }		// -----  end of method ASCIIParser::DeSerialize  -----
78
+
79
+    //--------------------------------------------------------------------------------------
80
+    //       Class:  ASCIIParser
57 81
     //      Method:  ~ASCIIParser
58 82
     // Description:  destructor (protected)
59 83
     //--------------------------------------------------------------------------------------
@@ -63,6 +87,16 @@ namespace Lemma {
63 87
 
64 88
     //--------------------------------------------------------------------------------------
65 89
     //       Class:  ASCIIParser
90
+    //      Method:  ASCIIParser
91
+    // Description:  DeSerializing constructor (protected)
92
+    //--------------------------------------------------------------------------------------
93
+    ASCIIParser::ASCIIParser (const YAML::Node& node) : LemmaObject(node) {
94
+        this->CommentString = node["CommentString"].as<std::string>();
95
+        this->BufferSize = node["BufferSize"].as<int>();
96
+    }  // -----  end of method ASCIIParser::ASCIIParser  (constructor)  -----
97
+
98
+    //--------------------------------------------------------------------------------------
99
+    //       Class:  ASCIIParser
66 100
     //      Method:  Release
67 101
     // Description:  destructor (protected)
68 102
     //--------------------------------------------------------------------------------------

+ 33
- 0
LemmaCore/src/CubicSplineInterpolator.cpp View File

@@ -44,6 +44,13 @@ namespace Lemma {
44 44
 
45 45
     }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
46 46
 
47
+    //--------------------------------------------------------------------------------------
48
+    //       Class:  CubicSplineInterpolator
49
+    //      Method:  CubicSplineInterpolator
50
+    // Description:  DeSerializing constructor (protected)
51
+    //--------------------------------------------------------------------------------------
52
+    CubicSplineInterpolator::CubicSplineInterpolator (const YAML::Node& node) : LemmaObject(node) {
53
+    }  // -----  end of method CubicSplineInterpolator::CubicSplineInterpolator  (constructor)  -----
47 54
 
48 55
     //--------------------------------------------------------------------------------------
49 56
     //       Class:  CubicSplineInterpolator
@@ -57,6 +64,29 @@ namespace Lemma {
57 64
 
58 65
     //--------------------------------------------------------------------------------------
59 66
     //       Class:  CubicSplineInterpolator
67
+    //      Method:  Serialize
68
+    //--------------------------------------------------------------------------------------
69
+    YAML::Node  CubicSplineInterpolator::Serialize (  ) const {
70
+        YAML::Node node = LemmaObject::Serialize();;
71
+        node.SetTag( GetName() );
72
+        // FILL IN CLASS SPECIFICS HERE
73
+        return node;
74
+    }		// -----  end of method CubicSplineInterpolator::Serialize  -----
75
+
76
+    //--------------------------------------------------------------------------------------
77
+    //       Class:  CubicSplineInterpolator
78
+    //      Method:  DeSerialize
79
+    //--------------------------------------------------------------------------------------
80
+    std::shared_ptr<CubicSplineInterpolator> CubicSplineInterpolator::DeSerialize ( const YAML::Node& node  ) {
81
+        if (node.Tag() != "CubicSplineInterpolator") {
82
+            throw  DeSerializeTypeMismatch( "CubicSplineInterpolator", node.Tag());
83
+        }
84
+        std::shared_ptr<CubicSplineInterpolator> Object(new  CubicSplineInterpolator(node), LemmaObjectDeleter() );
85
+        return Object ;
86
+    }
87
+
88
+    //--------------------------------------------------------------------------------------
89
+    //       Class:  CubicSplineInterpolator
60 90
     //      Method:  ~CubicSplineInterpolator
61 91
     // Description:  destructor (protected)
62 92
     //--------------------------------------------------------------------------------------
@@ -320,3 +350,6 @@ namespace Lemma {
320 350
 
321 351
 
322 352
 }		// -----  end of Lemma  name  -----
353
+
354
+/* vim: set tabstop=4 expandtab: */
355
+/* vim: set filetype=cpp: */

+ 3
- 0
LemmaCore/src/RectilinearGrid.cpp View File

@@ -174,3 +174,6 @@ namespace Lemma {
174 174
     }		// -----  end of method RectilinearGrid::GetDz  -----
175 175
 
176 176
 }		// -----  end of Lemma  name  -----
177
+
178
+/* vim: set tabstop=4 expandtab: */
179
+/* vim: set filetype=cpp: */

+ 18
- 11
LemmaCore/testing/SerializeCheck.h View File

@@ -34,18 +34,25 @@ class MyTestSuite : public CxxTest::TestSuite
34 34
         TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
35 35
     }
36 36
 
37
+
38
+    void testCubicSplineInterpolator(void)
39
+    {
40
+        auto Obj = CubicSplineInterpolator::NewSP();
41
+        YAML::Node node = Obj->Serialize();
42
+        auto Obj2 = CubicSplineInterpolator::DeSerialize(node);
43
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
44
+    }
45
+
46
+    void testRectilinearGrid( void )
47
+    {
48
+        auto Obj = RectilinearGrid::NewSP();
49
+        YAML::Node node = Obj->Serialize();
50
+        auto Obj2 = RectilinearGrid::DeSerialize(node);
51
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
52
+    }
53
+
37 54
 // /*
38
-//     void testCubicSplineInterpolator(void)
39
-//     {
40
-//         auto Obj = CubicSplineInterpolator::NewSP();
41
-//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("CubicSplineInterpolator") );
42
-//     }
43
-//
44
-//     void testRectilinearGrid( void )
45
-//     {
46
-//         auto Obj = RectilinearGrid::NewSP();
47
-//         TS_ASSERT_EQUALS( Obj->GetName(), std::string("RectilinearGrid") );
48
-//     }
55
+
49 56
 //
50 57
 //     void testRectilinearGridReader( void )
51 58
 //     {

Loading…
Cancel
Save