def test_load(self): """ should initalize the memory in the CPU with the contents from test.txt""" cpu = CPU() program_file = './tests/test.txt' cpu.load(program_file) self.assertEqual(cpu.RAM[0], '00000001') self.assertEqual(cpu.RAM[1], '00000010') self.assertEqual(cpu.RAM[2], '00000011') self.assertEqual(cpu.RAM[3], '00000100')
def test_advance_pc(self): """ should advance PC correctly""" cpu = CPU() self.assertEqual(cpu.PC, 0, f'Expected {cpu.PC} to eq 0') cpu.advance_pc('0000') self.assertEqual(cpu.PC, 1, f'Expected {cpu.PC} to eq 1') cpu.advance_pc('0100') self.assertEqual(cpu.PC, 3, f'Expected {cpu.PC} to eq 3') cpu.advance_pc('1000') self.assertEqual(cpu.PC, 6, f'Expected {cpu.PC} to eq 6')
def test_call(self): """should push next instruction onto stack and then set PC""" cpu = CPU() cpu.RAM[1] = '00000001' cpu.RAM[2] = '00001111' cpu.REG[1] = 4 cpu.call() self.assertEqual(cpu.SP, 243) self.assertEqual(cpu.PC, 4)
def test_mult(self): """should print the number 72 to the console""" cpu = CPU() program_file = './ls8/examples/mult.ls8' cpu.load(program_file) cpu.run() result = self.capturedOutput.getvalue().strip() self.assertEqual(result, '72', f'Expected 72 but got {result}')
def test_print8(self): """should print the number 8 to the console""" cpu = CPU() program_file = './ls8/examples/print8.ls8' cpu.load(program_file) cpu.run() result = self.capturedOutput.getvalue().strip() self.assertEqual(result, '8')
def test_ret(self): """should set PC and SP""" cpu = CPU() cpu.RAM[240] = 10 cpu.SP = 240 cpu.ret() self.assertEqual(cpu.PC, 10) self.assertEqual(cpu.SP, 241)
def test_subroutines(self): """should print the numbers 20,30,36,60 to the console""" cpu = CPU() program_file = './ls8/examples/call.ls8' cpu.load(program_file) cpu.run() expected = '20\n30\n36\n60' result = self.capturedOutput.getvalue().strip() self.assertEqual(result, expected, f'Expected {expected} but got {result}')
def test_stack(self): """should print the numbers 2,4,1 to the console""" cpu = CPU() program_file = './ls8/examples/stack.ls8' cpu.load(program_file) cpu.run() expected = '2\n4\n1' result = self.capturedOutput.getvalue().strip() self.assertEqual(result, expected, f'Expected {expected} but got {result}')
sys.path.append('../') import requests import time from dotenv import load_dotenv import os from requests.exceptions import HTTPError import json import hashlib import random from util import Stack, Queue from ls8.cpu import CPU load_dotenv() secret_key = os.getenv("KYLE_KEY") cpu = CPU() SET_HEADERS = {'Authorization': f'Token {secret_key}'} LAMBDA_SERVER = 'https://lambda-treasure-hunt.herokuapp.com/api/adv/' OS_SERVER = '' SERVER = LAMBDA_SERVER #Current map supplied by server player = {} world_map = {} important_places = {'store': 1, 'well': 55, 'fly': 22, 'dash': 461} # block for mining last_block = { "proof": 2005690142, "difficulty": 6,
print(f'HTTP error occurred: {http_err}') except Exception as err: print(f'Other error occurred: {err}') # if the req is good start a timer starttime = time.time() # make the data JSON r = response.json() # grab the wait time cooldown = r['cooldown'] print(r["messages"], '\n', r['errors']) # print(r['description']) # with open('well_message.txt', 'w') as f: # f.write(r["description"]) if current_data['name'] == "well": cpu = CPU() cpu.load(r["description"]) save = cpu.run() cpu = None # print("SAVE",save) if int(save) < 500: cmds.extend([f'f {save}', 'pr', 'm']) else: cmds.extend([f'f {save}', 'f 555', 'ex well']) else: print(r['description']) elif current_action == "get_proof/": # real_proof=0 # while True: time.sleep(cooldown - ((time.time() - starttime) % cooldown))