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
d2cfcb7b
Commit
d2cfcb7b
authored
Feb 10, 2013
by
Davis King
Browse files
Added unit tests for new matrix operator>> and fixed a bug in it.
parent
3f2a0c2b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
4 deletions
+58
-4
dlib/matrix/matrix_read_from_istream.h
dlib/matrix/matrix_read_from_istream.h
+2
-4
dlib/test/matrix3.cpp
dlib/test/matrix3.cpp
+56
-0
No files found.
dlib/matrix/matrix_read_from_istream.h
View file @
d2cfcb7b
...
@@ -59,17 +59,15 @@ namespace dlib
...
@@ -59,17 +59,15 @@ namespace dlib
// Eat next block of whitespace but also note if we hit the start of the next
// Eat next block of whitespace but also note if we hit the start of the next
// line.
// line.
int
last_ch
=
'a'
;
// set last_ch to anything other than '\n'
while
(
next_is_whitespace
(
in
))
while
(
next_is_whitespace
(
in
))
{
{
if
(
last_ch
==
'\n'
&&
in
.
peek
()
==
'\n'
)
if
(
at_start_of_line
&&
in
.
peek
()
==
'\n'
)
{
{
stop
=
true
;
stop
=
true
;
break
;
break
;
}
}
last_ch
=
in
.
get
();
if
(
in
.
get
()
==
'\n'
)
if
(
last_ch
==
'\n'
)
at_start_of_line
=
true
;
at_start_of_line
=
true
;
}
}
}
}
...
...
dlib/test/matrix3.cpp
View file @
d2cfcb7b
...
@@ -1001,6 +1001,61 @@ namespace
...
@@ -1001,6 +1001,61 @@ namespace
}
}
void
test_matrix_IO
()
{
dlib
::
rand
rnd
;
print_spinner
();
for
(
int
i
=
0
;
i
<
400
;
++
i
)
{
ostringstream
sout
;
sout
.
precision
(
20
);
matrix
<
double
>
m1
,
m2
,
m3
;
const
long
r
=
rnd
.
get_random_32bit_number
()
%
7
+
1
;
const
long
c
=
rnd
.
get_random_32bit_number
()
%
7
+
1
;
const
long
num
=
rnd
.
get_random_32bit_number
()
%
2
+
1
;
m1
=
randm
(
r
,
c
,
rnd
);
sout
<<
m1
;
if
(
num
!=
1
)
sout
<<
"
\n
"
<<
m1
;
if
(
rnd
.
get_random_double
()
<
0.3
)
sout
<<
"
\n
"
;
else
if
(
rnd
.
get_random_double
()
<
0.3
)
sout
<<
"
\n\n
3 3 3 3"
;
else
if
(
rnd
.
get_random_double
()
<
0.3
)
sout
<<
"
\n
\n
v 3 3 3 3 3"
;
istringstream
sin
(
sout
.
str
());
sin
>>
m2
;
DLIB_TEST_MSG
(
equal
(
m1
,
m2
),
m1
<<
"
\n
***********
\n
"
<<
m2
);
if
(
num
!=
1
)
{
sin
>>
m3
;
DLIB_TEST_MSG
(
equal
(
m1
,
m3
),
m1
<<
"
\n
***********
\n
"
<<
m3
);
}
}
{
istringstream
sin
(
" 1 2
\n
3"
);
matrix
<
double
>
m
;
DLIB_TEST
(
sin
);
sin
>>
m
;
DLIB_TEST
(
!
sin
);
}
{
istringstream
sin
(
""
);
matrix
<
double
>
m
;
DLIB_TEST
(
sin
);
sin
>>
m
;
DLIB_TEST
(
!
sin
);
}
}
...
@@ -1017,6 +1072,7 @@ namespace
...
@@ -1017,6 +1072,7 @@ namespace
void
perform_test
(
void
perform_test
(
)
)
{
{
test_matrix_IO
();
matrix_test
();
matrix_test
();
}
}
}
a
;
}
a
;
...
...
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