Commit 72aa1518 authored by Eddie Schoute's avatar Eddie Schoute
Browse files

Organize routing tests. Add ATBS test

parent 8b70a0c8
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment