Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
1009060d
Commit
1009060d
authored
Apr 15, 2010
by
reichenbach
Browse files
[ADD] Added a unit test for WTensorSym, unittests for WTensor* classes need more work though.
parent
1a3b55c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
213 additions
and
1 deletion
+213
-1
src/common/math/WTensorBase.h
src/common/math/WTensorBase.h
+12
-0
src/common/math/test/WTensorSym_test.h
src/common/math/test/WTensorSym_test.h
+200
-0
src/common/math/test/WTensor_test.h
src/common/math/test/WTensor_test.h
+1
-1
No files found.
src/common/math/WTensorBase.h
View file @
1009060d
...
...
@@ -759,6 +759,18 @@ WTensorBaseSym< order, dim, Data_T > const& WTensorBaseSym< order, dim, Data_T >
return
*
this
;
}
template
<
std
::
size_t
order
,
std
::
size_t
dim
,
typename
Data_T
>
std
::
size_t
WTensorBaseSym
<
order
,
dim
,
Data_T
>::
getDimension
()
const
{
return
dim
;
}
template
<
std
::
size_t
order
,
std
::
size_t
dim
,
typename
Data_T
>
std
::
size_t
WTensorBaseSym
<
order
,
dim
,
Data_T
>::
getOrder
()
const
{
return
order
;
}
template
<
std
::
size_t
order
,
std
::
size_t
dim
,
typename
Data_T
>
template
<
typename
Index_T
>
Data_T
const
&
WTensorBaseSym
<
order
,
dim
,
Data_T
>::
getAt
(
Index_T
const
*
const
pos
)
const
...
...
src/common/math/test/WTensorSym_test.h
0 → 100644
View file @
1009060d
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WTENSOR_TEST_H
#define WTENSOR_TEST_H
#include <string>
#include <vector>
#include <cxxtest/TestSuite.h>
#include "../WTensorSym.h"
/**
* Test class for the WTensorSym template.
*/
class
WTensorSymTest
:
public
CxxTest
::
TestSuite
{
public:
/**
* Test getDimension().
*/
void
testGetDimension
()
{
wmath
::
WTensorSym
<
1
,
1
>
w11
;
TS_ASSERT_EQUALS
(
w11
.
getDimension
(),
1
);
wmath
::
WTensorSym
<
2
,
4
>
w24
;
TS_ASSERT_EQUALS
(
w24
.
getDimension
(),
4
);
wmath
::
WTensorSym
<
3
,
5
>
w35
;
TS_ASSERT_EQUALS
(
w35
.
getDimension
(),
5
);
wmath
::
WTensorSym
<
4
,
3
>
w43
;
TS_ASSERT_EQUALS
(
w43
.
getDimension
(),
3
);
wmath
::
WTensorSym
<
5
,
1
>
w51
;
TS_ASSERT_EQUALS
(
w51
.
getDimension
(),
1
);
wmath
::
WTensorSym
<
6
,
2
>
w62
;
TS_ASSERT_EQUALS
(
w62
.
getDimension
(),
2
);
}
/**
* Test getOrder().
*/
void
testGetOrder
()
{
wmath
::
WTensorSym
<
1
,
1
>
w11
;
TS_ASSERT_EQUALS
(
w11
.
getOrder
(),
1
);
wmath
::
WTensorSym
<
2
,
4
>
w24
;
TS_ASSERT_EQUALS
(
w24
.
getOrder
(),
2
);
wmath
::
WTensorSym
<
3
,
5
>
w35
;
TS_ASSERT_EQUALS
(
w35
.
getOrder
(),
3
);
wmath
::
WTensorSym
<
4
,
3
>
w43
;
TS_ASSERT_EQUALS
(
w43
.
getOrder
(),
4
);
wmath
::
WTensorSym
<
5
,
1
>
w51
;
TS_ASSERT_EQUALS
(
w51
.
getOrder
(),
5
);
wmath
::
WTensorSym
<
6
,
2
>
w62
;
TS_ASSERT_EQUALS
(
w62
.
getOrder
(),
6
);
}
/**
* Test access operator ().
*/
void
testAccessOperator1
()
{
wmath
::
WTensorSym
<
3
,
2
>
w
;
w
(
0
,
0
,
0
)
=
2
;
w
(
0
,
0
,
1
)
=
3
;
w
(
0
,
1
,
0
)
=
0
;
w
(
0
,
1
,
1
)
=
5
;
w
(
1
,
0
,
0
)
=
2
;
w
(
1
,
0
,
1
)
=
1
;
w
(
1
,
1
,
0
)
=
8
;
w
(
1
,
1
,
1
)
=
10
;
TS_ASSERT_EQUALS
(
w
(
0
,
0
,
0
),
2
);
TS_ASSERT_EQUALS
(
w
(
0
,
0
,
1
),
2
);
TS_ASSERT_EQUALS
(
w
(
0
,
1
,
0
),
2
);
TS_ASSERT_EQUALS
(
w
(
0
,
1
,
1
),
8
);
TS_ASSERT_EQUALS
(
w
(
1
,
0
,
0
),
2
);
TS_ASSERT_EQUALS
(
w
(
1
,
0
,
1
),
8
);
TS_ASSERT_EQUALS
(
w
(
1
,
1
,
0
),
8
);
TS_ASSERT_EQUALS
(
w
(
1
,
1
,
1
),
10
);
}
/**
* Test access operator [].
*/
void
testAccessOperator2
()
{
std
::
vector
<
unsigned
int
>
v
(
3
,
0
);
wmath
::
WTensorSym
<
3
,
4
>
w
;
for
(
v
[
0
]
=
0
;
v
[
0
]
<
4
;
++
v
[
0
]
)
{
for
(
v
[
1
]
=
0
;
v
[
1
]
<
4
;
++
v
[
1
]
)
{
for
(
v
[
2
]
=
0
;
v
[
2
]
<
4
;
++
v
[
2
]
)
{
w
[
v
]
=
v
[
0
]
+
v
[
1
]
+
v
[
2
];
std
::
vector
<
unsigned
int
>
v0
=
v
;
std
::
sort
(
v0
.
begin
(),
v0
.
end
()
);
TS_ASSERT_EQUALS
(
w
[
v0
],
v
[
0
]
+
v
[
1
]
+
v
[
2
]
);
}
}
}
}
/**
* Test the standard constructor.
*/
void
testStandardConstructor
()
{
// create lots of tensors
wmath
::
WTensorSym
<
1
,
1
>
t11d
;
wmath
::
WTensorSym
<
1
,
2
>
t12d
;
wmath
::
WTensorSym
<
1
,
3
>
t13d
;
wmath
::
WTensorSym
<
1
,
4
>
t14d
;
wmath
::
WTensorSym
<
1
,
1
,
float
>
t11f
;
wmath
::
WTensorSym
<
1
,
2
,
int
>
t12i
;
wmath
::
WTensorSym
<
1
,
3
,
char
>
t13c
;
wmath
::
WTensorSym
<
1
,
4
,
std
::
string
>
t14s
;
wmath
::
WTensorSym
<
2
,
1
>
t21d
;
wmath
::
WTensorSym
<
2
,
2
>
t22d
;
wmath
::
WTensorSym
<
2
,
3
>
t23d
;
wmath
::
WTensorSym
<
2
,
4
>
t24d
;
wmath
::
WTensorSym
<
2
,
1
,
int
>
t21i
;
wmath
::
WTensorSym
<
2
,
2
,
char
>
t22c
;
wmath
::
WTensorSym
<
2
,
3
,
float
>
t23f
;
wmath
::
WTensorSym
<
2
,
4
,
float
>
t24f
;
wmath
::
WTensorSym
<
3
,
5
>
t35d
;
wmath
::
WTensorSym
<
4
,
3
>
t43d
;
wmath
::
WTensorSym
<
5
,
2
>
t52d
;
wmath
::
WTensorSym
<
6
,
3
>
t63d
;
TS_ASSERT_EQUALS
(
t35d
(
0
,
4
,
2
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
1
,
4
,
0
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
0
,
3
,
0
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
2
,
4
,
1
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
0
,
2
,
2
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
4
,
1
,
4
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
4
,
4
,
4
),
0.0
);
TS_ASSERT_EQUALS
(
t35d
(
3
,
4
,
3
),
0.0
);
TS_ASSERT_EQUALS
(
t11d
(
0
),
0.0
);
TS_ASSERT_EQUALS
(
t22d
(
0
,
1
),
0.0
);
}
/**
* Test copy constructor.
*/
void
testCopyConstructor
()
{
wmath
::
WTensorSym
<
2
,
3
>
w
;
w
(
0
,
1
)
=
2
;
w
(
2
,
1
)
=
0.456
;
wmath
::
WTensorSym
<
2
,
3
>
m
(
w
);
TS_ASSERT_EQUALS
(
m
(
1
,
0
),
2
);
TS_ASSERT_EQUALS
(
m
(
1
,
2
),
0.456
);
}
/**
* Test copy operator.
*/
void
testCopyOperator
()
{
wmath
::
WTensorSym
<
6
,
2
>
w
;
w
(
0
,
0
,
1
,
1
,
0
,
1
)
=
4.0
;
w
(
1
,
1
,
0
,
0
,
0
,
0
)
=
0.56
;
wmath
::
WTensorSym
<
6
,
2
>
m
;
{
m
=
w
;
TS_ASSERT_EQUALS
(
m
(
0
,
1
,
0
,
1
,
0
,
1
),
4.0
);
TS_ASSERT_EQUALS
(
m
(
1
,
0
,
0
,
0
,
1
,
0
),
0.56
);
TS_ASSERT_EQUALS
(
m
(
0
,
0
,
0
,
1
,
0
,
0
),
0.0
);
}
}
};
#endif // WTENSOR_TEST_H
src/common/math/test/WTensor_test.h
View file @
1009060d
...
...
@@ -34,7 +34,7 @@
/**
* Test class for the WTensor template.
*/
class
WTensor
_t
est
:
public
CxxTest
::
TestSuite
class
WTensor
T
est
:
public
CxxTest
::
TestSuite
{
public:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment