-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestTape.py
More file actions
54 lines (46 loc) · 1.6 KB
/
Copy pathtestTape.py
File metadata and controls
54 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
import tape
class TestTape( unittest.TestCase ):
def setUp(self):
self.tape = tape.Tape()
def testInitialization(self):
"""
Test that the inital state of the tape is correct.
"""
self.assertEqual(self.tape.pointer, 0)
self.assertEqual(len(self.tape.tape), 30000)
self.assertEqual(self.tape.tape, [0 for x in range(0,30000,1)])
def testIncrement(self):
"""
Test that incrementing values works
"""
for i in range(10):
self.tape.increment()
self.assertEqual(self.tape.tape[0], 10)
def testDecrement(self):
"""
Test that decrementing values works.
"""
for i in range(10):
self.tape.increment()
self.tape.decrement()
self.assertEqual(self.tape.tape[0], 0)
def testMoving(self):
"""
Test that moving the tape forwards and backwards works as desired.
"""
for i in range(65536):
self.tape.move_forwards()
for i in range(65536):
self.tape.move_backwards()
# Could not get this next test working.
#self.assertRaises(self.tape.move_backwards(), tape.TapeError)
def testCellModification(self):
"""
Test that modifying cells works as stated.
"""
import random
for i in range(100):
randNum = random.randint(-65536,65536)
self.tape.replace(randNum)
self.assertEqual(randNum, self.tape.current_cell())