Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libsimple_support
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
We are moving to Forgejo!
You are on a read-only GitLab instance.
Show more breadcrumbs
namark
libsimple_support
Commits
1d063756
Commit
1d063756
authored
6 years ago
by
namark
Browse files
Options
Downloads
Patches
Plain Diff
Unit tests for to_<Number> function.
parent
6864048d
Branches
up_movement
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/simple/support/misc.hpp
+4
-4
4 additions, 4 deletions
source/simple/support/misc.hpp
unit_tests/misc.cpp
+19
-0
19 additions, 0 deletions
unit_tests/misc.cpp
with
23 additions
and
4 deletions
source/simple/support/misc.hpp
+
4
−
4
View file @
1d063756
...
@@ -77,14 +77,14 @@ namespace simple::support
...
@@ -77,14 +77,14 @@ namespace simple::support
return
ston
<
N
>
(
s
,
&
start_index
);
return
ston
<
N
>
(
s
,
&
start_index
);
}
}
template
<
typename
N
>
template
<
typename
N
umber
>
std
::
optional
<
N
>
to_
(
const
std
::
string
&
s
)
std
::
optional
<
N
umber
>
to_
(
const
std
::
string
&
s
)
{
{
static_assert
(
std
::
is_arithmetic_v
<
N
>
,
"simple::support::to_
n
umber expects an arithmetic type!"
);
static_assert
(
std
::
is_arithmetic_v
<
N
umber
>
,
"simple::support::to_
<N
umber
>
expects an arithmetic type!"
);
errno
=
0
;
errno
=
0
;
const
char
*
start
=
s
.
c_str
();
const
char
*
start
=
s
.
c_str
();
char
*
end
;
char
*
end
;
N
result
=
strton
<
N
>
(
start
,
&
end
);
N
umber
result
=
strton
<
N
umber
>
(
start
,
&
end
);
if
(
ERANGE
==
errno
)
if
(
ERANGE
==
errno
)
return
std
::
nullopt
;
return
std
::
nullopt
;
auto
diff
=
end
-
start
;
auto
diff
=
end
-
start
;
...
...
This diff is collapsed.
Click to expand it.
unit_tests/misc.cpp
+
19
−
0
View file @
1d063756
...
@@ -83,10 +83,29 @@ void NumericRangeToString()
...
@@ -83,10 +83,29 @@ void NumericRangeToString()
assert
(
tos
(
-
12.34
)
+
'-'
+
tos
(
12.34
)
==
tos
(
range
<
double
>
{
-
12.34
,
12.34
})
);
assert
(
tos
(
-
12.34
)
+
'-'
+
tos
(
12.34
)
==
tos
(
range
<
double
>
{
-
12.34
,
12.34
})
);
}
}
void
SimplifiedToNumber
()
{
assert
(
123
==
*
to_
<
int
>
(
"123"
)
);
assert
(
-
0xabc
==
*
to_
<
int
>
(
"-0xabc"
)
);
assert
(
-
0123
==
*
to_
<
int
>
(
"-0123"
)
);
assert
(
123.123
f
==
*
to_
<
float
>
(
tos
(
123.123
f
))
);
assert
(
-
123.123
==
*
to_
<
double
>
(
tos
(
-
123.123
))
);
assert
(
123.123
l
==
*
to_
<
long
double
>
(
tos
(
123.123
l
))
);
assert
(
123
==
*
to_
<
int
>
(
"123xyz"
)
);
assert
(
std
::
nullopt
==
to_
<
int
>
(
"abc123"
));
assert
(
std
::
nullopt
==
to_
<
signed
char
>
(
std
::
to_string
(
std
::
numeric_limits
<
signed
char
>::
max
())
+
'0'
));
assert
(
std
::
nullopt
==
to_
<
unsigned
char
>
(
std
::
to_string
(
std
::
numeric_limits
<
unsigned
char
>::
max
())
+
'0'
));
}
int
main
()
int
main
()
{
{
StringToNumber
();
StringToNumber
();
StringToNumericRange
();
StringToNumericRange
();
NumericRangeToString
();
NumericRangeToString
();
SimplifiedToNumber
();
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment