def test_push_decimal_2(self): source = s.push_decimal(-3.5) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), -3.5) self.assertEqual(sim.pointer, 4)
def test_if_one_then_2(self): source = c.if_one_then(1, c.inc_pos(3)) sim = BfSim(source) sim.memory[1] = 0 sim.run(10000) self.assertEqual(sim.memory[1], 0) self.assertEqual(sim.memory[3], 0)
def test_sub_byte_1(self): source = c.block_of(s.push_byte(3), s.push_byte(2), s.sub_byte()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getByte(sim, 0), 1) self.assertEqual(sim.pointer, 4)
def test_move_data_1(self): source = c.move_data(1, 2) sim = BfSim(source) sim.memory[1] = 3 sim.run(10000) self.assertEqual(sim.memory[1], 0) self.assertEqual(sim.memory[2], 3)
def test_push_byte_1(self): source = s.push_byte(3) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertEqual(self.getByte(sim, 0), 3) self.assertEqual(sim.pointer, 4)
def test_inc_data_tricky_4(self): source = c.inc_data_tricky(3, 2) sim = BfSim(source) sim.memory[3] = 255 sim.run(10000) self.assertEqual(sim.memory[1], 0) self.assertEqual(sim.memory[2], 1) self.assertEqual(sim.memory[3], 0)
def test_dec_data_tricky_2(self): source = c.dec_data_tricky(3, 1) sim = BfSim(source) sim.memory[3] = 10 sim.run(10000) self.assertEqual(sim.memory[1], 0) self.assertEqual(sim.memory[2], 0) self.assertEqual(sim.memory[3], 9)
def test_sub_decimal_2(self): source = c.block_of(s.push_decimal(3.5), s.push_decimal(-4.25), s.sub_decimal()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), 7.75) self.assertEqual(sim.pointer, 4)
def test_if_z_tricky_2(self): source = c.if_z_tricky(1, 1, 1, c.inc_pos(5), c.inc_pos(6)) sim = BfSim(source) sim.memory[1] = 0 sim.run(10000) self.assertEqual(sim.memory[1], 0) self.assertEqual(sim.memory[5], 1) self.assertEqual(sim.memory[6], 0)
def test_if_nz_int_swap_2(self): source = c.block_of(s.push_decimal(-0.5), s.push_decimal(2.25), s._if_nz_int_swap()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), -0.5) self.assertAlmostEqual(self.getFloat(sim, 4), 2.25) self.assertEqual(sim.pointer, 8)
def test_add_decimal_6(self): source = c.block_of(s.push_decimal(-4.5), s.push_decimal(4.5), s.add_decimal()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), 0.0) # TODO -0.0 self.assertAlmostEqual(self.getFloat(sim, 4), 0.0) self.assertEqual(sim.pointer, 4)
def test_top_minus_second_1(self): source = c.block_of(s.push_decimal(-0.5), s.push_decimal(2.25), s._top_minus_second()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), 1.75) self.assertAlmostEqual(self.getFloat(sim, 4), 0.0) self.assertEqual(sim.pointer, 8)
def test_dec_both_abs_decimal_3(self): source = c.block_of(s.push_decimal(0.5), s.push_decimal(0.5), s._dec_both_abs_decimal()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), 0.0) self.assertAlmostEqual(self.getFloat(sim, 4), 0.0) self.assertEqual(sim.pointer, 8)
def test_if_top_decimal_is_nz_then_override_2(self): source = c.block_of(s.push_decimal(0.5), s.push_decimal(0.0), s._if_top_decimal_is_nz_then_override()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), 0.5) self.assertAlmostEqual(self.getFloat(sim, 4), 0.0) self.assertEqual(sim.pointer, 8)
def test_multi_decimal_1(self): source = c.block_of(s.push_decimal(2.0), s.push_decimal(-4.25), s.multi_decimal()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertAlmostEqual(self.getFloat(sim, 0), -8.5) self.assertAlmostEqual(self.getFloat(sim, 4), 0.0) self.assertAlmostEqual(self.getFloat(sim, 8), 0.0) self.assertEqual(sim.pointer, 4)
def test_xor_sign_4(self): source = c.block_of(s.push_decimal(2.0), s.push_decimal(4.25), s._xor_sign()) sim = BfSim(source) while not sim.is_stopped(): sim.run(10000) self.assertEqual(sim.memory[8 + s.IDX_DMY], 0) self.assertEqual(sim.memory[8 + s.IDX_INT], 0) self.assertEqual(sim.memory[8 + s.IDX_DEC], 0) self.assertEqual(sim.memory[8 + s.IDX_SGN], 0) self.assertEqual(sim.memory[12], 0) self.assertEqual(sim.pointer, 8)
def test_if_nz_decimal_3(self): source = c.block_of( s.push_decimal(0.0), s.if_nz_decimal( then_statement=s.push_byte(ord('N')) + s.put_char(), else_statement=s.push_byte(ord('Z')) + s.put_char())) out = io.StringIO() sim = BfSim(source, stdout=out) while not sim.is_stopped(): sim.run(10000) self.assertEqual(out.getvalue(), "Z") self.assertAlmostEqual(self.getFloat(sim, 0), 0.0) self.assertAlmostEqual(self.getFloat(sim, 4), 0.0) self.assertEqual(sim.pointer, 0)
def test_multi_data_tricky_1(self): source = c.multi_data_tricky(source1=1, source2=3, pos=5, digit=2) sim = BfSim(source) sim.memory[1] = 100 sim.memory[3] = 100 sim.memory[4] = 0 sim.memory[5] = 0 while not sim.is_stopped(): sim.run(10000) self.assertEqual(sim.memory[4], 39) self.assertEqual(sim.memory[5], 16)
def test_add_data_tricky_1(self): source = c.add_data_tricky(source=2, pos=4, work=7, digit=2) sim = BfSim(source) sim.memory[2] = 129 sim.memory[3] = 5 sim.memory[4] = 129 sim.run(10000) self.assertEqual(sim.memory[2], 129) self.assertEqual(sim.memory[3], 6) self.assertEqual(sim.memory[4], 2)
def test_dec_data_tricky_5(self): source = c.dec_data_tricky(3, 3) sim = BfSim(source) sim.memory[1] = 1 sim.memory[2] = 0 sim.memory[3] = 0 sim.run(10000) self.assertEqual(sim.memory[1], 0) self.assertEqual(sim.memory[2], 255) self.assertEqual(sim.memory[3], 255)
def test_swap_data_1(self): source = c.swap_data(1, 2, 3) sim = BfSim(source) sim.memory[1] = 3 sim.memory[2] = 4 sim.run(10000) self.assertEqual(sim.memory[1], 4) self.assertEqual(sim.memory[2], 3)
def test_init_value_3(self): source = c.init_value(1, 255) sim = BfSim(source) sim.run(10000) self.assertEqual(sim.memory[1], 255)