Best Python code snippet using fMBT_python
construction.py
Source:construction.py
1import copy2from component import *3import pygame4from personallib.camera import Camera5def component(base):6 return copy.deepcopy(base)7# Creating a NOT gate8map = {9 "inputs": [Input()],10 "components": [NAND()], # 'map' created including all inputs, components, and outputs which would be on the screen (each can be added by user)11 "outputs": [Output()]12}13map["inputs"][0].link(0, map["components"][0], 0)14map["inputs"][0].link(0, map["components"][0], 1) # Inputs, components, and outputs can be linked together (by user dragging a wire between them)15map["components"][0].link(0, map["outputs"][0], 0)16map["inputs"][0].value = (map["inputs"][0].value + 1) % 2 # Input values can be toggled (by user clicking on them)17output = map["outputs"][0].evaluate() # Output values can be evaluated given the current inputs 18print(map["inputs"][0].value, output) # (each time an input or component or link is changed, this is evaluated)19not_gate = Component("NOT", (0, 0, 0), 1, 1, map) # New component can be created from the current map (by user clicking to add the current map as a component)20# Creating an AND gate21map = {22 "inputs": [Input(), Input()],23 "components": [NAND(), component(not_gate)],24 "outputs": [Output()]25}26map["inputs"][0].link(0, map["components"][0], 0)27map["inputs"][1].link(0, map["components"][0], 1)28map["components"][0].link(0, map["components"][1], 0)29map["components"][1].link(0, map["outputs"][0], 0)30and_gate = Component("AND", (0, 0, 0), 2, 1, map)31# Creating an OR gate32map = {33 "inputs": [Input(), Input()],34 "components": [component(not_gate), component(not_gate), NAND()],35 "outputs": [Output()]36}37map["inputs"][0].link(0, map["components"][0], 0)38map["inputs"][1].link(0, map["components"][1], 0)39map["components"][0].link(0, map["components"][2], 0)40map["components"][1].link(0, map["components"][2], 1)41map["components"][2].link(0, map["outputs"][0], 0)42or_gate = Component("OR", (0, 0, 0), 2, 1, map)43# Creating an XOR gate44map = {45 "inputs": [Input(), Input()],46 "components": [component(or_gate), NAND(), component(and_gate)],47 "outputs": [Output()]48}49map["inputs"][0].link(0, map["components"][0], 0)50map["inputs"][1].link(0, map["components"][0], 1)51map["inputs"][0].link(0, map["components"][1], 0)52map["inputs"][1].link(0, map["components"][1], 1)53map["components"][0].link(0, map["components"][2], 0)54map["components"][1].link(0, map["components"][2], 1)55map["components"][2].link(0, map["outputs"][0], 0)56xor_gate = Component("XOR", (0, 0, 0), 2, 1, map)57# Creating a half adder58map = {59 "inputs": [Input(), Input()],60 "components": [component(and_gate), component(xor_gate)],61 "outputs": [Output(), Output()]62}63map["inputs"][0].link(0, map["components"][0], 0)64map["inputs"][1].link(0, map["components"][0], 1)65map["inputs"][0].link(0, map["components"][1], 0)66map["inputs"][1].link(0, map["components"][1], 1)67map["components"][0].link(0, map["outputs"][0], 0)68map["components"][1].link(0, map["outputs"][1], 0)69half_adder = Component("HALF ADDER", (0, 0, 0), 2, 2, map)70# Creating a full adder71map = {72 "inputs": [Input(), Input(), Input()],73 "components": [component(half_adder), component(half_adder), component(or_gate)],74 "outputs": [Output(), Output()]75}76map["inputs"][0].link(0, map["components"][0], 0)77map["inputs"][1].link(0, map["components"][0], 1)78map["inputs"][2].link(0, map["components"][1], 1)79map["components"][0].link(0, map["components"][2], 1)80map["components"][0].link(1, map["components"][1], 0)81map["components"][1].link(0, map["components"][2], 0)82map["components"][1].link(1, map["outputs"][1], 0)83map["components"][2].link(0, map["outputs"][0], 0)84full_adder = Component("FULL ADDER", (0, 0, 0), 3, 2, map)85# Creating a 4 bit adder86map = {87 "inputs": [Input(), Input(), Input(), Input(), Input(), Input(), Input(), Input(), Input()],88 "components": [component(full_adder), component(full_adder), component(full_adder), component(full_adder)],89 "outputs": [Output(), Output(), Output(), Output(), Output()]90}91map["inputs"][8].link(0, map["components"][3], 2)92map["inputs"][7].link(0, map["components"][3], 1)93map["inputs"][3].link(0, map["components"][3], 0)94map["inputs"][6].link(0, map["components"][2], 1)95map["inputs"][2].link(0, map["components"][2], 0)96map["inputs"][5].link(0, map["components"][1], 1)97map["inputs"][1].link(0, map["components"][1], 0)98map["inputs"][4].link(0, map["components"][0], 1)99map["inputs"][0].link(0, map["components"][0], 0)100map["components"][3].link(0, map["components"][2], 2)101map["components"][2].link(0, map["components"][1], 2)102map["components"][1].link(0, map["components"][0], 2)103map["components"][0].link(0, map["outputs"][0], 0)104map["components"][3].link(1, map["outputs"][4], 0)105map["components"][2].link(1, map["outputs"][3], 0)106map["components"][1].link(1, map["outputs"][2], 0)107map["components"][0].link(1, map["outputs"][1], 0)108four_bit_adder = Component("FOUR BIT ADDER", (0, 0, 0), 9, 5, map)109# Creating an adder & subtracter110map = {111 "inputs": [Input(), Input(), Input(), Input(), Input(), Input(), Input(), Input(), Input()],112 "components": [component(xor_gate), component(xor_gate), component(xor_gate), component(xor_gate), component(four_bit_adder)],113 "outputs": [Output(), Output(), Output(), Output()]114}115for i in range(4):116 map["inputs"][i].link(0, map["components"][4], i)117for i in range(4):118 map["inputs"][i + 4].link(0, map["components"][i], 0)119for i in range(4):120 map["inputs"][8].link(0, map["components"][i], 1)121map["inputs"][8].link(0, map["components"][4], 8)122for i in range(4):123 map["components"][i].link(0, map["components"][4], i + 4)124for i in range(4):125 map["components"][4].link(i + 1, map["outputs"][i], 0)126alu = Component("ALU", (0, 0, 0), 9, 4, map)127# 4 BIT ADDER DEMONSTRATION128map = {129 "inputs": [Input(), Input(), Input(), Input(), Input(), Input(), Input(), Input(), Input()],130 "components": [component(alu)],131 "outputs": [Output(), Output(), Output(), Output()]132}133for i in range(9):134 map["inputs"][i].link(0, map["components"][0], i)135for i in range(4):136 map["components"][0].link(i, map["outputs"][i], 0)137d_number1 = int(input("Enter first number: "))138d_number2 = int(input("Enter second number: "))139b_number1 = format(d_number1, '04b')140b_number2 = format(d_number2, '04b')141neg = {0: 0, 1: -8}142# NUMBER 1143map["inputs"][0].value = int(b_number1[-4])144map["inputs"][1].value = int(b_number1[-3])145map["inputs"][2].value = int(b_number1[-2])146map["inputs"][3].value = int(b_number1[-1])147# NUMBER 2148map["inputs"][4].value = int(b_number2[-4])149map["inputs"][5].value = int(b_number2[-3])150map["inputs"][6].value = int(b_number2[-2])151map["inputs"][7].value = int(b_number2[-1])152# ADDITION153map["inputs"][8].value = 0154out = ""155for output in map["outputs"]:156 out += f"{output.evaluate()}"157print(f"{d_number1} + {d_number2} = {neg[int(out[0])] + int(out[1:], 2)} ({out})")158# SUBTRACTION159map["inputs"][8].value = 1160out = ""161for output in map["outputs"]:162 out += f"{output.evaluate()}"...
test2.py
Source:test2.py
...20 return t[1]21def d_number1(t):22 '''number1 : number'''23 return t[0]24def d_number2(t):25 '''number2 : number'''26 return t[0]27def d_number(t):28 '''number : "[0-9]+"'''29 return t[0]30def ambiguity_func(v):31 return v[0]32def d_whitespace(t, spec):33 "whitespace : ' '*"34 35if Parser().parse('1 +2* (3+ 4+5)', ambiguity_fn = ambiguity_func, print_debug_info=0).getStructure() != 25:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!