Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Andrew Childs
reversal-sort
Commits
72aa1518
Commit
72aa1518
authored
Feb 25, 2021
by
Eddie Schoute
Browse files
Organize routing tests. Add ATBS test
parent
8b70a0c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/test_routing.py
View file @
72aa1518
...
...
@@ -3,29 +3,27 @@ from unittest import TestCase
from
reversal_sort.routing
import
DCRoute
from
reversal_sort.tripartite_binary_sort
import
tripartite_binary_sort
from
reversal_sort.adaptive_tbs
import
adaptive_tb_sort
class
TestRouting
(
TestCase
):
def
test_route_tbs_simple
(
self
):
L
=
[
0
,
1
,
3
,
2
]
def
check_route_correctly
(
self
,
router
,
L
):
L_orig
=
L
.
copy
()
router
=
DCRoute
(
tripartite_binary_sort
)
reversals
=
router
.
route
(
L
.
copy
())
for
rev
in
reversals
:
rev
.
apply
(
L
)
self
.
assertEqual
(
sorted
(
L_orig
),
L
)
self
.
assertEqual
(
sorted
(
L_orig
),
L
,
msg
=
f
"Did not route
{
L_orig
}
"
)
def
test_route_tbs_simple
(
self
):
L
=
[
0
,
1
,
3
,
2
]
router
=
DCRoute
(
tripartite_binary_sort
)
self
.
check_route_correctly
(
router
,
L
)
def
test_route_tbs_simple2
(
self
):
L
=
[
1
,
3
,
0
,
4
,
2
]
L_orig
=
L
.
copy
()
router
=
DCRoute
(
tripartite_binary_sort
)
reversals
=
router
.
route
(
L
.
copy
())
for
rev
in
reversals
:
rev
.
apply
(
L
)
self
.
assertEqual
(
sorted
(
L_orig
),
L
)
self
.
check_route_correctly
(
router
,
L
)
def
test_route_tbs
(
self
):
"""
...
...
@@ -38,9 +36,17 @@ class TestRouting(TestCase):
for
ct
in
range
(
n
):
L
=
list
(
range
(
0
,
random
.
randint
(
5
,
200
)))
random
.
shuffle
(
L
)
reversals
=
router
.
route
(
L
.
copy
()
)
self
.
check_route_correctly
(
router
,
L
)
L_orig
=
L
.
copy
()
for
rev
in
reversals
:
rev
.
apply
(
L
)
self
.
assertEqual
(
sorted
(
L_orig
),
L
,
msg
=
f
"Did not route
{
L_orig
}
"
)
def
test_route_atbs
(
self
):
"""
Testing correctness of sorting permutations with TBS as
bitstring sorting subroutine.
Returns number
"""
n
=
1000
router
=
DCRoute
(
adaptive_tb_sort
)
for
ct
in
range
(
n
):
L
=
list
(
range
(
0
,
random
.
randint
(
5
,
50
)))
random
.
shuffle
(
L
)
self
.
check_route_correctly
(
router
,
L
)
\ No newline at end of file
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