Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80685329
test_ccoord_operations.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 2, 02:13
Size
4 KB
Mime Type
text/x-c
Expires
Wed, Sep 4, 02:13 (2 d)
Engine
blob
Format
Raw Data
Handle
20423122
Attached To
rMUSPECTRE µSpectre
test_ccoord_operations.cc
View Options
/**
* @file test_ccoord_operations.cc
*
* @author Till Junge <till.junge@altermail.ch>
*
* @date 03 Dec 2017
*
* @brief tests for cell coordinate operations
*
* Copyright © 2017 Till Junge
*
* µSpectre is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3, or (at
* your option) any later version.
*
* µSpectre 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <iostream>
#include "common/common.hh"
#include "common/ccoord_operations.hh"
#include "tests/test_goodies.hh"
#include "tests.hh"
namespace
muSpectre
{
BOOST_AUTO_TEST_SUITE
(
ccoords_operations
);
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
test_cube
,
Fix
,
testGoodies
::
dimlist
,
Fix
)
{
constexpr
auto
dim
{
Fix
::
dim
};
using
Ccoord
=
Ccoord_t
<
dim
>
;
constexpr
Dim_t
size
{
5
};
constexpr
Ccoord
cube
=
CcoordOps
::
get_cube
<
dim
>
(
size
);
Ccoord
ref_cube
;
for
(
Dim_t
i
=
0
;
i
<
dim
;
++
i
)
{
ref_cube
[
i
]
=
size
;
}
BOOST_CHECK_EQUAL_COLLECTIONS
(
ref_cube
.
begin
(),
ref_cube
.
end
(),
cube
.
begin
(),
cube
.
end
());
}
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
test_hermitian
,
Fix
,
testGoodies
::
dimlist
,
Fix
)
{
constexpr
auto
dim
{
Fix
::
dim
};
using
Ccoord
=
Ccoord_t
<
dim
>
;
constexpr
Dim_t
size
{
5
};
constexpr
Ccoord
cube
=
CcoordOps
::
get_cube
<
dim
>
(
size
);
constexpr
Ccoord
herm
=
CcoordOps
::
get_hermitian_sizes
(
cube
);
Ccoord
ref_cube
=
cube
;
ref_cube
.
back
()
=
(
cube
.
back
()
+
1
)
/
2
;
BOOST_CHECK_EQUAL_COLLECTIONS
(
ref_cube
.
begin
(),
ref_cube
.
end
(),
herm
.
begin
(),
herm
.
end
());
}
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
test_size
,
Fix
,
testGoodies
::
dimlist
,
Fix
)
{
constexpr
auto
dim
{
Fix
::
dim
};
using
Ccoord
=
Ccoord_t
<
dim
>
;
constexpr
Dim_t
size
{
5
};
constexpr
Ccoord
cube
=
CcoordOps
::
get_cube
<
dim
>
(
size
);
BOOST_CHECK_EQUAL
(
CcoordOps
::
get_size
(
cube
),
ipow
(
size
,
dim
));
}
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
test_stride_size
,
Fix
,
testGoodies
::
dimlist
,
Fix
)
{
constexpr
auto
dim
{
Fix
::
dim
};
using
Ccoord
=
Ccoord_t
<
dim
>
;
constexpr
Dim_t
size
{
5
};
constexpr
Ccoord
cube
=
CcoordOps
::
get_cube
<
dim
>
(
size
);
constexpr
Ccoord
stride
=
CcoordOps
::
get_default_strides
(
cube
);
BOOST_CHECK_EQUAL
(
CcoordOps
::
get_size_from_strides
(
cube
,
stride
),
ipow
(
size
,
dim
));
}
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
test_index
,
Fix
,
testGoodies
::
dimlist
,
Fix
)
{
constexpr
auto
dim
{
Fix
::
dim
};
using
Ccoord
=
Ccoord_t
<
dim
>
;
testGoodies
::
RandRange
<
Dim_t
>
rng
;
Ccoord
sizes
{};
for
(
Dim_t
i
{
0
};
i
<
dim
;
++
i
)
{
sizes
[
i
]
=
rng
.
randval
(
2
,
5
);
}
Ccoord
stride
=
CcoordOps
::
get_default_strides
(
sizes
);
const
size_t
nb_pix
{
CcoordOps
::
get_size
(
sizes
)};
for
(
size_t
i
{
0
};
i
<
nb_pix
;
++
i
)
{
BOOST_CHECK_EQUAL
(
i
,
CcoordOps
::
get_index_from_strides
(
stride
,
CcoordOps
::
get_ccoord
(
sizes
,
i
)));
}
}
BOOST_AUTO_TEST_CASE
(
vector_test
)
{
constexpr
Ccoord_t
<
threeD
>
c3
{
1
,
2
,
3
};
constexpr
Ccoord_t
<
twoD
>
c2
{
c3
[
0
],
c3
[
1
]};
constexpr
Rcoord_t
<
threeD
>
s3
{
1.3
,
2.8
,
5.7
};
constexpr
Rcoord_t
<
twoD
>
s2
{
s3
[
0
],
s3
[
1
]};
Eigen
::
Matrix
<
Real
,
twoD
,
1
>
v2
;
v2
<<
s3
[
0
],
s3
[
1
];
Eigen
::
Matrix
<
Real
,
threeD
,
1
>
v3
;
v3
<<
s3
[
0
],
s3
[
1
],
s3
[
2
];
auto
vec2
{
CcoordOps
::
get_vector
(
c2
,
v2
(
1
))};
auto
vec3
{
CcoordOps
::
get_vector
(
c3
,
v3
(
1
))};
for
(
Dim_t
i
=
0
;
i
<
twoD
;
++
i
)
{
BOOST_CHECK_EQUAL
(
c2
[
i
]
*
v2
(
1
),
vec2
[
i
]);
}
for
(
Dim_t
i
=
0
;
i
<
threeD
;
++
i
)
{
BOOST_CHECK_EQUAL
(
c3
[
i
]
*
v3
(
1
),
vec3
[
i
]);
}
vec2
=
CcoordOps
::
get_vector
(
c2
,
v2
);
vec3
=
CcoordOps
::
get_vector
(
c3
,
v3
);
for
(
Dim_t
i
=
0
;
i
<
twoD
;
++
i
)
{
BOOST_CHECK_EQUAL
(
c2
[
i
]
*
v2
(
i
),
vec2
[
i
]);
BOOST_CHECK_EQUAL
(
vec2
[
i
],
CcoordOps
::
get_vector
(
c2
,
s2
)[
i
]);
}
for
(
Dim_t
i
=
0
;
i
<
threeD
;
++
i
)
{
BOOST_CHECK_EQUAL
(
c3
[
i
]
*
v3
(
i
),
vec3
[
i
]);
BOOST_CHECK_EQUAL
(
vec3
[
i
],
CcoordOps
::
get_vector
(
c3
,
s3
)[
i
]);
}
}
BOOST_AUTO_TEST_SUITE_END
();
}
// muSpectre
Event Timeline
Log In to Comment