Skip to content

Commit 6e23a67

Browse files
author
allywarner
committed
Add Module Test
1 parent b0d56aa commit 6e23a67

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/Modules/Math/Tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SET(Modules_Math_Tests_SRCS
3838
SelectSubMatrixTests.cc
3939
AddKnownsToLinearSystemTests.cc
4040
PortCachingUnitTest.cc
41+
ComputePCAtest.cc
4142
)
4243

4344
#SET(Engine_Network_Tests_HEADERS
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2015 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
License for the specific language governing rights and limitations under
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
#include <Testing/ModuleTestBase/ModuleTestBase.h>
30+
#include <Modules/Math/ComputePCA.h>
31+
#include <Core/Datatypes/DenseColumnMatrix.h>
32+
#include <Core/Datatypes/DenseMatrix.h>
33+
#include <Testing/Utils/MatrixTestUtilities.h>
34+
35+
using namespace SCIRun;
36+
using namespace SCIRun::Modules::Math;
37+
using namespace SCIRun::Dataflow::Networks;
38+
using namespace SCIRun::Core::Datatypes;
39+
using namespace SCIRun::Testing;
40+
using namespace SCIRun::TestUtils;
41+
42+
class ComputePCAtest : public ModuleTest
43+
{
44+
};
45+
46+
TEST_F(ComputePCAtest, CheckInputNull)
47+
{
48+
auto pcaMod = makeModule("ComputePCA");
49+
MatrixHandle nullMatrix;
50+
stubPortNWithThisData(pcaMod, 0, nullMatrix);
51+
52+
EXPECT_THROW(pcaMod -> execute(), NullHandleOnPortException);
53+
}
54+
55+
TEST_F(ComputePCAtest, CheckInputColumn)
56+
{
57+
auto pcaMod = makeModule("ComputePCA");
58+
DenseColumnMatrixHandle columnInput(new DenseColumnMatrix(5));
59+
(*columnInput) << 1,2,3,4,5;
60+
stubPortNWithThisData(pcaMod, 0, columnInput);
61+
62+
EXPECT_NO_THROW(pcaMod -> execute());
63+
}
64+
65+
TEST_F(ComputePCAtest, CheckInputDense)
66+
{
67+
auto pcaMod = makeModule("ComputePCA");
68+
MatrixHandle denseMatrix = MAKE_DENSE_MATRIX_HANDLE((1,2,5,6)(3,4,7,9)(7,8,9,1)(2,3,5,9));
69+
stubPortNWithThisData(pcaMod, 0, denseMatrix);
70+
71+
EXPECT_NO_THROW(pcaMod -> execute());
72+
}
73+
74+
TEST_F(ComputePCAtest, CheckInputSparse)
75+
{
76+
auto pcaMod = makeModule("ComputePCA");
77+
MatrixHandle sparseMatrix = MAKE_SPARSE_MATRIX_HANDLE((0,0,0,0)(5,8,0,0)(0,0,3,0)(0,6,0,0));
78+
stubPortNWithThisData(pcaMod, 0, sparseMatrix);
79+
80+
EXPECT_NO_THROW(pcaMod -> execute());
81+
}
82+

0 commit comments

Comments
 (0)