Browse Source

Added new unit test

enhancement_3
Trevor Irons 8 years ago
parent
commit
14bf1fdc00
1 changed files with 71 additions and 0 deletions
  1. 71
    0
      Modules/FDEM1D/testing/SerializeCheck.h

+ 71
- 0
Modules/FDEM1D/testing/SerializeCheck.h View File

@@ -0,0 +1,71 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      10/30/2016 10:07:46 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+#include <cxxtest/TestSuite.h>
21
+#include <FDEM1D>
22
+#include <random>
23
+
24
+using namespace Lemma;
25
+
26
+class MyTestSuite : public CxxTest::TestSuite
27
+{
28
+    public:
29
+
30
+    void testLayeredEarthEM( void )
31
+    {
32
+        std::random_device rd;
33
+        std::mt19937 gen(rd());
34
+
35
+        // up to 11 layers
36
+        std::discrete_distribution<> d({0,0,0,10,10,10,10,10,10,10,10,10,10});
37
+        int nl = d(gen);
38
+
39
+        // for Reals
40
+        std::uniform_real_distribution<> dis(1e-2, 1);
41
+
42
+        // conductivity
43
+        VectorXcr con = VectorXcr(nl);
44
+        VectorXr thick = VectorXr(nl-2);
45
+        con(0) = 0;
46
+        for ( int i=1; i<nl; ++i ) {
47
+            con(i) = Complex(dis(gen), dis(gen));
48
+        }
49
+
50
+        for ( int i=0; i<nl-2; ++i ) {
51
+            thick(i) = dis(gen);
52
+        }
53
+
54
+        auto Obj = LayeredEarthEM::NewSP();
55
+           Obj->SetNumberOfLayers(nl);
56
+           Obj->SetLayerConductivity(con);
57
+           Obj->SetLayerThickness(thick);
58
+
59
+        YAML::Node node = Obj->Serialize();
60
+        auto Obj2 = LayeredEarthEM::DeSerialize(node);
61
+
62
+        // TODO assert if two layers throw error with set thickness
63
+
64
+        TS_ASSERT_EQUALS( Obj->GetName(), Obj2->GetName() );
65
+        TS_ASSERT_EQUALS( Obj->GetNumberOfLayers(), Obj2->GetNumberOfLayers() );
66
+        TS_ASSERT_LESS_THAN( std::abs((Obj->GetLayerConductivity() - Obj2->GetLayerConductivity()).array().sum()), 1e-16 );
67
+        TS_ASSERT_LESS_THAN( std::abs((Obj->GetLayerThickness() - Obj2->GetLayerThickness()).array().sum()), 1e-16 );
68
+    }
69
+
70
+};
71
+

Loading…
Cancel
Save