Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
a0e3d2a6
Commit
a0e3d2a6
authored
Dec 23, 2012
by
Davis King
Browse files
Added unit tests for matrix iterators.
parent
ee4e7aea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
dlib/test/matrix4.cpp
dlib/test/matrix4.cpp
+82
-0
No files found.
dlib/test/matrix4.cpp
View file @
a0e3d2a6
...
@@ -934,6 +934,87 @@ namespace
...
@@ -934,6 +934,87 @@ namespace
}
}
}
}
template
<
typename
T
>
std
::
vector
<
int
>
tovect1
(
const
T
&
m
)
{
std
::
vector
<
int
>
temp
;
for
(
typename
T
::
const_iterator
i
=
m
.
begin
();
i
!=
m
.
end
();
++
i
)
{
temp
.
push_back
(
*
i
);
}
return
temp
;
}
template
<
typename
T
>
std
::
vector
<
int
>
tovect2
(
const
T
&
m
)
{
std
::
vector
<
int
>
temp
;
for
(
typename
T
::
const_iterator
i
=
m
.
begin
();
i
!=
m
.
end
();
i
++
)
{
temp
.
push_back
(
*
i
);
}
return
temp
;
}
template
<
typename
T
>
std
::
vector
<
int
>
tovect3
(
const
T
&
m_
)
{
matrix
<
int
>
m
(
m_
);
std
::
vector
<
int
>
temp
;
for
(
matrix
<
int
>::
iterator
i
=
m
.
begin
();
i
!=
m
.
end
();
++
i
)
{
temp
.
push_back
(
*
i
);
}
return
temp
;
}
template
<
typename
T
>
std
::
vector
<
int
>
tovect4
(
const
T
&
m_
)
{
matrix
<
int
>
m
(
m_
);
std
::
vector
<
int
>
temp
;
for
(
matrix
<
int
>::
iterator
i
=
m
.
begin
();
i
!=
m
.
end
();
i
++
)
{
temp
.
push_back
(
*
i
);
}
return
temp
;
}
void
test_iterators
()
{
matrix
<
int
>
m
(
3
,
2
);
m
=
1
,
2
,
3
,
4
,
5
,
6
;
std
::
vector
<
int
>
v1
=
tovect1
(
m
);
std
::
vector
<
int
>
v2
=
tovect2
(
m
);
std
::
vector
<
int
>
v3
=
tovect3
(
m
);
std
::
vector
<
int
>
v4
=
tovect4
(
m
);
std
::
vector
<
int
>
v5
=
tovect1
(
m
+
m
);
std
::
vector
<
int
>
v6
=
tovect2
(
m
+
m
);
std
::
vector
<
int
>
v7
=
tovect3
(
m
+
m
);
std
::
vector
<
int
>
v8
=
tovect4
(
m
+
m
);
std
::
vector
<
int
>
a1
,
a2
;
for
(
int
i
=
1
;
i
<=
6
;
++
i
)
{
a1
.
push_back
(
i
);
a2
.
push_back
(
i
*
2
);
}
DLIB_TEST
(
max
(
abs
(
mat
(
v1
)
-
mat
(
a1
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v2
)
-
mat
(
a1
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v3
)
-
mat
(
a1
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v4
)
-
mat
(
a1
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v5
)
-
mat
(
a2
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v6
)
-
mat
(
a2
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v7
)
-
mat
(
a2
)))
==
0
);
DLIB_TEST
(
max
(
abs
(
mat
(
v8
)
-
mat
(
a2
)))
==
0
);
}
class
matrix_tester
:
public
tester
class
matrix_tester
:
public
tester
{
{
public:
public:
...
@@ -946,6 +1027,7 @@ namespace
...
@@ -946,6 +1027,7 @@ namespace
void
perform_test
(
void
perform_test
(
)
)
{
{
test_iterators
();
test_setsubs
();
test_setsubs
();
test_conv
<
0
,
0
,
0
,
0
>
();
test_conv
<
0
,
0
,
0
,
0
>
();
...
...
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