Skip to content

Commit

Permalink
Split up Tape and HeadTape tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Feb 3, 2024
1 parent b81b6b7 commit f51c443
Showing 1 changed file with 51 additions and 50 deletions.
101 changes: 51 additions & 50 deletions test/test_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,29 @@ def stringify_sig(sig: Signature) -> str:
return f'{l_sig}[{scan}]{r_sig}'


class TestTape(TestCase):
tape: Tape | HeadTape
class TestHeadTape(TestCase):
tape: HeadTape

def set_tape(
self,
lspan: list[tuple[int, int]],
scan: Color,
rspan: list[tuple[int, int]],
head: int | None = None,
head: int,
) -> None:
self.tape = (
Tape(lspan, scan, rspan)
if head is None else
HeadTape(lspan, scan, rspan, head)
)
self.tape = HeadTape(lspan, scan, rspan, head)

def assert_tape(self, tape_str: str):
self.assertEqual(tape_str, str(self.tape))

def assert_signature(
self,
expected: str,
tape: Tape | HeadTape | None = None,
tape: HeadTape | None = None,
) -> None:
if tape is None:
tape = self.tape

assert isinstance(tape, HeadTape)

self.assertEqual(
expected,
stringify_sig(Tape(
Expand All @@ -68,10 +62,6 @@ def assert_signature(
[(block.color, block.count) for block in tape.rspan],
).signature))

def test_marks(self):
self.assertFalse(
Tape().marks)

def test_copy(self):
self.set_tape(
[(1, 1), (0, 1), (1, 1)],
Expand All @@ -88,8 +78,6 @@ def test_copy(self):
self.assert_signature(
'1|0|1[2]2|1')

assert isinstance(self.tape, HeadTape)

copy_1 = self.tape.copy()
copy_2 = self.tape.copy()

Expand All @@ -107,6 +95,52 @@ def test_copy(self):
'1|0|1[2]1',
tape = copy_2)

def test_hash(self):
blocks = set()

block1 = HeadBlock(1, 1)

blocks.add(block1)

block2 = HeadBlock(1, 1)

self.assertEqual(hash(block1), hash(block2))

self.assertIn(block2, blocks)

tapes = set()

tape1 = HeadTape([(1, 1)], 1, [(1, 4)], -4)

tapes.add(tape1)

self.assertIn(tape1, tapes)

tape2 = HeadTape([(1, 1)], 1, [(1, 4)], -4)

self.assertEqual(hash(tape1), hash(tape2))

self.assertIn(tape2, tapes)


class TestTape(TestCase):
tape: Tape

def set_tape(
self,
lspan: list[tuple[int, int]],
scan: Color,
rspan: list[tuple[int, int]],
) -> None:
self.tape = Tape(lspan, scan, rspan)

def assert_tape(self, tape_str: str):
self.assertEqual(tape_str, str(self.tape))

def test_marks(self):
self.assertFalse(
Tape().marks)

def test_rule_1(self):
self.set_tape(
[(1, 12), (2, 3)],
Expand All @@ -116,8 +150,6 @@ def test_rule_1(self):
self.assert_tape(
"2^3 1^12 [3] 4^15 5^2 6^2")

assert isinstance(self.tape, Tape)

self.tape.apply_rule({
(0, 1): 3,
(1, 0): -2,
Expand All @@ -140,8 +172,6 @@ def test_rule_2(self):
4,
[(5, 60), (2, 1), (4, 1), (5, 7), (1, 1)])

assert isinstance(self.tape, Tape)

self.assert_tape(
"4^2 [4] 5^60 2^1 4^1 5^7 1^1")

Expand All @@ -156,8 +186,6 @@ def test_rule_2(self):
def test_rule_3(self):
self.set_tape([(1, 152), (2, 655345), (3, 1)], 0, [])

assert isinstance(self.tape, Tape)

self.assert_tape(
"3^1 2^655345 1^152 [0]")

Expand All @@ -171,33 +199,6 @@ def test_rule_3(self):
self.assert_tape(
f"3^1 2^1 1^{exp} [0]")

def test_hash(self):
blocks = set()

block1 = HeadBlock(1, 1)

blocks.add(block1)

block2 = HeadBlock(1, 1)

self.assertEqual(hash(block1), hash(block2))

self.assertIn(block2, blocks)

tapes = set()

tape1 = HeadTape([(1, 1)], 1, [(1, 4)], -4)

tapes.add(tape1)

self.assertIn(tape1, tapes)

tape2 = HeadTape([(1, 1)], 1, [(1, 4)], -4)

self.assertEqual(hash(tape1), hash(tape2))

self.assertIn(tape2, tapes)


class TestTags(TestCase):
tape: TagTape
Expand Down

0 comments on commit f51c443

Please sign in to comment.