def test_rotate_clockwise(self): block = Block([ [1, 0], [1, 0], [1, 1] ]) block.rotate() assert block.data == [ [1, 1, 1], [1, 0, 0] ] block.rotate() assert block.data == [ [1, 1], [0, 1], [0, 1] ] block.rotate() assert block.data == [ [0, 0, 1], [1, 1, 1] ] block.rotate() assert block.data == [ [1, 0], [1, 0], [1, 1] ]
def test_simple(self): zero = Block(0, 0, False, True) first = Block(1, 1, False, True) second = Block(2, 2, False, False) third = Block(3, 3, False, False) zero_chain = Chain([zero, first, second]) first_chain = Chain([zero, third]) res = merge([zero_chain, first_chain]) self.assertEqual(res["deterministic_ordering"][0], 0) self.assertEqual(res["deterministic_ordering"][1], 1) self.assertEqual(len(res["merged_chain"]), 4) self.assertEqual(res["merged_chain"][0], zero) self.assertEqual(res["merged_chain"][1], first) self.assertEqual(res["merged_chain"][2], second) self.assertEqual(res["merged_chain"][3], third)
def test_can_not_move_outside_of_board(self): block = BlockBoard(width=5, height=5) block.cell_position = 1 block.row_position = 4 block.block = Block([ [1, 1], [1, 1], ]) with self.assertRaises(ValueError): block.move_block('a')
def main(): global no_of_tabs, block_buffer, condition_stack with open(sample) as file: lines = file.readlines() for eachline in lines: eachline = eachline.strip() matched = re.match(identation_expression, eachline).groups() if matched[0] is not None: tabs = len(matched[0]) else: tabs = 0 if tabs > no_of_tabs: block_buffer = [eachline] elif tabs < no_of_tabs: conditional_block = ConditionalBlock(condition_stack, Block(block_buffer)) graph.connect(conditional_block) condition_stack.pop() # if(isOnElse): # condition_stack.pop() else: block_buffer.append(eachline) no_of_tabs = tabs print("", " ".join( map( lambda x: "'{0}'".format(x), condition_stack if len(condition_stack) > 0 else ["outofblock"])), end=" ") print(" ", eachline.strip()) is_conditional_statement = re.match(conditional_expression, eachline.strip()) is_else_conditional_statement = re.match(else_expression, eachline.strip()) if is_conditional_statement is not None: if eachline.startswith('elif'): condition_stack.pop() condition_stack.append( Condition(is_conditional_statement.groups()[0], is_conditional_statement.groups()[1])) for_else.append( Condition(is_conditional_statement.groups()[0], is_conditional_statement.groups()[1])) no_of_tabs -= 1 isOnElse = False elif is_else_conditional_statement is not None: condition_stack.append(condition_stack.pop().negate()) no_of_tabs -= 1 isOnElse = True condition_stack.pop() else: isOnElse = False
def test_can_not_rotate(self): block = BlockBoard(width=5, height=5) block.cell_position = 3 block.row_position = 0 block.block = Block([ [0, 1], [0, 1], [1, 1] ]) with self.assertRaises(ValueError): block.move_block('s')
def test_valid_block_move(self): moves = ['a', 'd', 'w', 's'] for move in moves: with self.subTest(f'Move: {move}'): block = BlockBoard(width=5, height=5) block.cell_position = 1 block.row_position = 0 block.block = Block([ [1, 0], [1, 0], [1, 1] ]) self.assertIsNone(block.move_block(move))
def hj(s, ProcessName): # ProcessName = "Chrome" , say label = tk.Label(s, text=ProcessName, font=SMALL_FONT) label.pack(pady=10, padx=10) # # list.add(label) # Process Path # label2 = tk.Label(s, text=getProcessPathByName(ProcessName), font=SMALL_FONT) # label2.pack(pady=10,padx=10) # self.buttonframe = Frame(self.root) # self.buttonframe.grid(row=2, column=0, columnspan=2) # Button(self.buttonframe, text = "Brighten").grid(row=0, column=0) # Button(self.buttonframe, text = "Darken").grid(row=0, column=1) buttonB = ttk.Button(s, text="Block", command=lambda: Block(ProcessName)) buttonB.pack() buttonU = ttk.Button(s, text="Unblock", command=lambda: Unblock(ProcessName)) buttonU.pack()
for result in query: result.delete() # Sets up the new block: newBlock = NewBlock(parent=construction) newBlock.data_version = '0' newBlock.init_pos_b = [0, 0, 3] newBlock.init_a = 0 newBlock.move_space_1_b = [-1, -1, 0] newBlock.move_space_2_b = [3, 3, 3] newBlock.build_space_1_b = [0, 0, 0] newBlock.build_space_2_b = [2, 2, 3] newBlock.put() # Deletes all block entries: queries = [Block.all()] for query in queries: for result in query: result.delete() # Creates block entries: cs = simplejson.loads(prerenderMode.block_configurations[0]) for c in cs: x_b = c[0] y_b = c[1] z_b = c[2] a = c[3] block = Block.insert_at(construction, [x_b, y_b, z_b], a) block.state = 2 block.put()
# Deletes all new block entries: queries = [NewBlock.all()] for query in queries: for result in query: result.delete() # Sets up the new block: newBlock = NewBlock(parent=construction) newBlock.data_version = '0' newBlock.init_pos_b = [4, 0, 4] newBlock.init_a = 0 newBlock.put() # Deletes all block entries: queries = [Block.all()] for query in queries: for result in query: result.delete() # Creates block entries: cs = [[1, 4, 3, 1], [1, 4, 2, 0], [1, 4, 1, 3], [1, 4, 0, 2], [5, 5, 1, 2], [5, 5, 0, 2], [0, 1, 0, 3], [3, 0, 0, 2], [4, 0, 0, 0], [1, 0, 0, 0], [4, 4, 0, 0]] for c in cs: x_b = c[0] y_b = c[1] z_b = c[2] a = c[3] block = Block.insert_at(construction, [x_b, y_b, z_b], a) block.state = 2
def test_3_with_im(self): zero = Block(0, 0, False, True) first = Block(1, 1, False, False) second = Block(2, 2, False, False) zero_chain = Chain([ zero, first, Block(2, 3, True, False), Block(3, 4, False, False), Block(4, 5, False, False), Block(5, 6, True, False), Block(6, 7, False, False), Block(7, 8, True, False), Block(8, 9, True, False), Block(9, 10, False, False), ]) first_chain = Chain([ zero, first, second, Block(3, 11, True, False), Block(4, 12, True, False), Block(5, 13, False, False), Block(6, 14, True, False), Block(7, 15, True, False), Block(8, 16, True, False), Block(9, 17, True, False), ]) first_im = Block(first.timeslot, first.identifier, first.is_empty, True) second_im = Block(second.timeslot, second.identifier, second.is_empty, True) second_chain = Chain([ zero, first_im, second_im, Block(3, 18, True, True), Block(4, 19, True, True), Block(5, 20, True, True), Block(6, 21, True, True), Block(7, 22, False, False), Block(8, 23, False, False), Block(9, 24, True, False), ]) res = merge([zero_chain, first_chain, second_chain]) self.assertEqual(res["merged_chain"][0].timeslot, 0) self.assertEqual(res["merged_chain"][1].timeslot, 1) self.assertEqual(res["merged_chain"][2].timeslot, 2) self.assertEqual(res["merged_chain"][3].timeslot, 3) self.assertEqual(res["merged_chain"][4].timeslot, 4) self.assertEqual(res["merged_chain"][5].timeslot, 6) self.assertEqual(res["merged_chain"][6].timeslot, 9) self.assertEqual(res["merged_chain"][7].timeslot, 7) self.assertEqual(res["merged_chain"][8].timeslot, 8) self.assertEqual(res["merged_chain"][9].timeslot, 5)
def test_block_size_1(self): block1 = Block([2, 2, 2]) self.assertEqual(block1.get_width(), 2)
def test_block_size_1(self): block1 = Block([2, 2, 2]) self.assertEqual(block1.get_surface_area(), 24)
def test_block_size_1(self): block1 = Block([2, 2, 2]) self.assertEqual(block1.get_volume(), 8)
def test_block_size_3(self): block1 = Block([2, 2, 2]) self.assertEqual(block1.get_height(), 2)
def test_block_size_2(self): block1 = Block([2, 2, 2]) self.assertEqual(block1.get_length(), 2)
from main import Block import datetime import time num_blocks_to_add = 10 block_chain = [Block.create_genesis()] print( "------------------------------------------------------------------------\n" ) print("The genesis block has been created.") print(block_chain[0]) time.sleep(2) for i in range(1, num_blocks_to_add + 1): block_chain.append( Block(block_chain[i - 1].hash, "Block number %d" % i, datetime.datetime.now())) print( "\n---------------------------------------------------------------------------------\n" ) print("Block #%d created.\n" % i) print(block_chain[i]) time.sleep(2)
def Blocker(s, pName): Block(pName) s.config(background="#b22222")
from main import Block blockchain = [] genesis_block = Block("This is Ashish...", [ "raj sent 3 BTC to Sham", "king sent 2 BTC to Slave ", "Sam sent 5 BTC to Olive" ]) second_block = Block(genesis_block.block_hash, ["X 5 BTC to Z", "A 4 BTC to B"]) third_block = Block(second_block.block_hash, ["X 5 BTC to Z", "A 5 BTC to B"]) #print(genesis_block.block_hash) print(second_block.block_hash) #print(third_block.block_hash)