Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
8a1184a2
Unverified
Commit
8a1184a2
authored
Jun 07, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cif_id_for_number
parent
d2fbc547
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
16 deletions
+31
-16
src/text.cpp
+7
-16
test/unit-v2-test.cpp
+24
-0
No files found.
src/text.cpp
View file @
8a1184a2
...
@@ -236,28 +236,19 @@ std::string cif_id_for_number(int number)
...
@@ -236,28 +236,19 @@ std::string cif_id_for_number(int number)
{
{
std
::
string
result
;
std
::
string
result
;
if
(
number
>=
26
*
26
*
26
)
do
result
=
'L'
+
std
::
to_string
(
number
);
else
{
if
(
number
>=
26
*
26
)
{
{
int
v
=
number
/
(
26
*
26
);
int
r
=
number
%
26
;
result
+=
char
(
'A'
-
1
+
v
);
result
+=
'A'
+
r
;
number
%=
(
26
*
26
);
}
if
(
number
>=
26
)
number
=
(
number
-
r
)
/
26
-
1
;
{
int
v
=
number
/
26
;
result
+=
char
(
'A'
-
1
+
v
);
number
%=
26
;
}
}
while
(
number
>=
0
);
result
+=
char
(
'A'
+
number
);
std
::
reverse
(
result
.
begin
(),
result
.
end
());
}
assert
(
not
result
.
empty
());
assert
(
not
result
.
empty
());
return
result
;
return
result
;
}
}
...
...
test/unit-v2-test.cpp
View file @
8a1184a2
...
@@ -75,6 +75,30 @@ bool init_unit_test()
...
@@ -75,6 +75,30 @@ bool init_unit_test()
// --------------------------------------------------------------------
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
id_1
)
{
BOOST_TEST
(
cif
::
cif_id_for_number
(
0
)
==
"A"
);
BOOST_TEST
(
cif
::
cif_id_for_number
(
25
)
==
"Z"
);
BOOST_TEST
(
cif
::
cif_id_for_number
(
26
)
==
"AA"
);
BOOST_TEST
(
cif
::
cif_id_for_number
(
26
+
1
)
==
"AB"
);
BOOST_TEST
(
cif
::
cif_id_for_number
(
26
+
26
*
26
-
1
)
==
"ZZ"
);
BOOST_TEST
(
cif
::
cif_id_for_number
(
26
+
26
*
26
)
==
"AAA"
);
BOOST_TEST
(
cif
::
cif_id_for_number
(
26
+
26
*
26
+
1
)
==
"AAB"
);
std
::
set
<
std
::
string
>
testset
;
for
(
int
i
=
0
;
i
<
100000
;
++
i
)
{
std
::
string
id
=
cif
::
cif_id_for_number
(
i
);
BOOST_TEST
(
testset
.
count
(
id
)
==
0
);
testset
.
insert
(
id
);
}
BOOST_TEST
(
testset
.
size
()
==
100000
);
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
cc_1
)
BOOST_AUTO_TEST_CASE
(
cc_1
)
{
{
std
::
tuple
<
std
::
string_view
,
float
,
char
>
tests
[]
=
{
std
::
tuple
<
std
::
string_view
,
float
,
char
>
tests
[]
=
{
...
...
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