def test_order(): r = registers.Registers() s = stack.Stack(r) s.push(1) s.push(2) s.push(3) assert s.pop() == 3 assert s.pop() == 2 assert s.pop() == 1
def init_kernel(stdin=None): r = ram.RAM(256) # Fill up RAM with 1's to be certain that 0 termination works r.load([1] * 256) s = stack.Stack(registers.Registers()) k = kernel.Kernel(r, s) if stdin: k.filenumber_mapping[0] = io.StringIO(stdin) return k
def test_changing_sp(): r = registers.Registers() s = stack.Stack(r) assert r.sp == 0 s.push(0) assert r.sp == 1 s.push(1) assert r.sp == 2 s.pop() assert r.sp == 1 s.pop() assert r.sp == 0
def test_init(): r = registers.Registers() for i in range(4): assert r.get(i) == 0
def test_persistence(): r = registers.Registers() r.set(0b00, 26) assert r.get(0b00) == 26
def test_str(): r = registers.Registers() for i in range(4): r.set(i, i) assert str(r) == "[0, 1, 2, 3] IP=0, SP=0"
def test_push_pop(): r = registers.Registers() s = stack.Stack(r) s.push(12) assert s.pop() == 12