Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
bef38649
Commit
bef38649
authored
5 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#29 Fikset skrivefeil lenght -> length
parent
9ce52a62
No related branches found
Branches containing commit
No related tags found
1 merge request
!15
Kodebok-koder
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
soitool/coder.py
+14
-14
14 additions, 14 deletions
soitool/coder.py
test/test_coder.py
+3
-3
3 additions, 3 deletions
test/test_coder.py
with
17 additions
and
17 deletions
soitool/coder.py
+
14
−
14
View file @
bef38649
...
...
@@ -4,14 +4,14 @@ import string
import
secrets
def
get_code
(
leng
h
t
):
def
get_code
(
lengt
h
):
"""
Generate a single alphabetic random code.
Parameters
----------
leng
h
t : int
The leng
h
t of the code
lengt
h
: int
The lengt
h
of the code
Return
------
...
...
@@ -21,14 +21,14 @@ def get_code(lenght):
code
=
""
i
=
0
while
i
<
leng
h
t
:
while
i
<
lengt
h
:
letter
=
secrets
.
choice
(
string
.
ascii_uppercase
)
code
=
code
+
letter
i
=
i
+
1
return
code
def
get_code_set
(
size
,
leng
h
t
):
def
get_code_set
(
size
,
lengt
h
):
"""
Generate a set of alphabetic codes.
...
...
@@ -37,8 +37,8 @@ def get_code_set(size, lenght):
size : int
Number of codes to be returned
leng
h
t : int
The leng
h
t of the code
lengt
h
: int
The lengt
h
of the code
Return
------
...
...
@@ -48,14 +48,14 @@ def get_code_set(size, lenght):
codes
=
set
()
while
len
(
codes
)
<
size
:
code
=
get_code
(
leng
h
t
)
code
=
get_code
(
lengt
h
)
if
code
not
in
codes
:
codes
.
add
(
code
)
return
codes
def
get_code_leng
h
t
(
quantity
):
def
get_code_lengt
h
(
quantity
):
"""
Get lentgth of code based on number of codewords.
...
...
@@ -66,12 +66,12 @@ def get_code_lenght(quantity):
Return
------
leng
h
t: int
lengt
h
: int
Lenght of code
"""
leng
h
t
=
0
while
len
(
string
.
ascii_uppercase
)
**
leng
h
t
<
quantity
:
leng
h
t
=
leng
h
t
+
1
lengt
h
=
0
while
len
(
string
.
ascii_uppercase
)
**
lengt
h
<
quantity
:
lengt
h
=
lengt
h
+
1
return
leng
h
t
return
lengt
h
This diff is collapsed.
Click to expand it.
test/test_coder.py
+
3
−
3
View file @
bef38649
...
...
@@ -12,7 +12,7 @@ class CoderTest(unittest.TestCase):
COMBINATIONS
=
len
(
ascii_uppercase
)
**
LEN
def
test_get_code
(
self
):
"""
Test code is uppercase alphabetic and correct leng
h
t.
"""
"""
Test code is uppercase alphabetic and correct lengt
h
.
"""
code
=
coder
.
get_code
(
3
)
self
.
assertRegex
(
code
,
'
[A-Z]{3}
'
)
...
...
@@ -34,8 +34,8 @@ class CoderTest(unittest.TestCase):
def
test_get_code_lenght
(
self
):
"
Test return correct codelenght.
"
self
.
assertEqual
(
self
.
LEN
,
coder
.
get_code_leng
h
t
(
self
.
COMBINATIONS
))
self
.
assertEqual
(
3
,
coder
.
get_code_leng
h
t
(
len
(
ascii_uppercase
)
**
3
))
self
.
assertEqual
(
self
.
LEN
,
coder
.
get_code_lengt
h
(
self
.
COMBINATIONS
))
self
.
assertEqual
(
3
,
coder
.
get_code_lengt
h
(
len
(
ascii_uppercase
)
**
3
))
if
__name__
==
'
__main__
'
:
...
...
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