def filled_names(sample_names_list): """Return a Names class with three error codes and three names.""" new_names = Names() new_names.unique_error_codes(3) new_names.lookup(sample_names_list) return new_names
def new_names_with_items(): '''returns an instance of class Names with items ''' new_names_with_items = Names() new_names_with_items.lookup([ 'DEVICE', 'CONNECT', 'MONITOR', 'CLOCK', 'SWITCH', 'AND', 'NAND', 'G2' ]) return new_names_with_items
def test_lookup(): """Test the look_up method""" n = Names() assert n.lookup(["name1"]) == [0] assert n.lookup(["name2"]) == [1] assert n.lookup(["name2", "name3", "name1"]) == [1, 2, 0] assert n.query("name1") == 0 assert n.query(-1) is None
def test_2(): """Create network that matches test definition file 2""" names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) CK1, CK2, AND1, NAND1, OR1, NOR1 = names.lookup( ["CK1", "CK2", "AND1", "NAND1", "OR1", "NOR1"]) devices.make_device(CK1, devices.CLOCK, 2) devices.make_device(CK2, devices.CLOCK, 1) devices.make_device(AND1, devices.AND, 2) devices.make_device(NAND1, devices.NAND, 2) devices.make_device(OR1, devices.OR, 2) devices.make_device(NOR1, devices.NOR, 2) network.make_connection(CK1, None, AND1, names.query("I1")) network.make_connection(CK2, None, AND1, names.query("I2")) network.make_connection(CK2, None, NAND1, names.query("I2")) network.make_connection(CK2, None, OR1, names.query("I2")) network.make_connection(CK2, None, NOR1, names.query("I2")) network.make_connection(AND1, None, NAND1, names.query("I1")) network.make_connection(NAND1, None, OR1, names.query("I1")) network.make_connection(OR1, None, NOR1, names.query("I1")) monitors.make_monitor(NOR1, None) return names, devices, network, monitors
def test_1(): """Create network that matches test definition file 1""" names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) [SW1, SW2, SW3, SW4, D1, CK1, XOR1] = \ names.lookup(["SW1", "SW2", "SW3", "SW4", "D1", "CK1", "XOR1"]) print(names.query("SW1")) devices.make_device(SW1, devices.SWITCH, 1) devices.make_device(SW2, devices.SWITCH, 1) devices.make_device(SW3, devices.SWITCH, 1) devices.make_device(SW4, devices.SWITCH, 0) devices.make_device(D1, devices.D_TYPE) devices.make_device(CK1, devices.CLOCK, 2) devices.make_device(XOR1, devices.XOR) network.make_connection(SW1, None, XOR1, names.query("I1")) network.make_connection(SW2, None, XOR1, names.query("I2")) network.make_connection(XOR1, None, D1, names.query("DATA")) network.make_connection(CK1, None, D1, names.query("CLK")) network.make_connection(SW3, None, D1, names.query("SET")) network.make_connection(SW4, None, D1, names.query("CLEAR")) monitors.make_monitor(D1, names.query("Q")) monitors.make_monitor(D1, names.query("QBAR")) return names, devices, network, monitors
def test_get_name_string(): """Test the get_name_string method""" n = Names() _ = n.lookup(["name1", "name2", "name3"]) assert n.get_name_string(1) == "name2" assert n.get_name_string(5) is None with pytest.raises(TypeError): n.get_name_string('a')
def devices_with_items(): """Return a Devices class instance with three devices in the network.""" new_names = Names() new_devices = Devices(new_names) [AND1_ID, NOR1_ID, SW1_ID] = new_names.lookup(["And1", "Nor1", "Sw1"]) new_devices.make_device(AND1_ID, new_devices.AND, 2) new_devices.make_device(NOR1_ID, new_devices.NOR, 16) new_devices.make_device(SW1_ID, new_devices.SWITCH, 0) return new_devices
def network_with_devices(): """Return a Network class instance with three devices in the network.""" new_names = Names() new_devices = Devices(new_names) new_network = Network(new_names, new_devices) [SW1_ID, SW2_ID, OR1_ID] = new_names.lookup(["Sw1", "Sw2", "Or1"]) # Add devices new_devices.make_device(SW1_ID, new_devices.SWITCH, 0) new_devices.make_device(SW2_ID, new_devices.SWITCH, 0) new_devices.make_device(OR1_ID, new_devices.OR, 2) return new_network
def devices_with_items(): """Return a Devices class instance with four devices in the network.""" new_names = Names() new_devices = Devices(new_names) [AND1_ID, NOR1_ID, SW1_ID, SIGGEN_ID] = new_names.lookup(["And1", "Nor1", "Sw1", "Siggen1"]) new_devices.make_device(AND1_ID, new_devices.AND, [2]) new_devices.make_device(NOR1_ID, new_devices.NOR, [16]) new_devices.make_device(SW1_ID, new_devices.SWITCH, [0]) new_devices.make_device(SIGGEN_ID, new_devices.SIGGEN, [0, 1, 1, 1, 0]) print(new_devices.find_devices()) return new_devices
def test_4(): """Create network that matches test definition file 4, a ripple counter""" names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) SW, CK, D1, D2, D3, D4 = names.lookup(["SW", "CK", "D1", "D2", "D3", "D4"]) devices.make_device(SW, devices.SWITCH, 0) devices.make_device(CK, devices.CLOCK, 1) devices.make_device(D1, devices.D_TYPE) devices.make_device(D2, devices.D_TYPE) devices.make_device(D3, devices.D_TYPE) devices.make_device(D4, devices.D_TYPE) network.make_connection(SW, None, D1, names.query("SET")) network.make_connection(SW, None, D1, names.query("CLEAR")) network.make_connection(SW, None, D2, names.query("SET")) network.make_connection(SW, None, D2, names.query("CLEAR")) network.make_connection(SW, None, D3, names.query("SET")) network.make_connection(SW, None, D3, names.query("CLEAR")) network.make_connection(SW, None, D4, names.query("SET")) network.make_connection(SW, None, D4, names.query("CLEAR")) network.make_connection(CK, None, D1, names.query("CLK")) network.make_connection(D1, names.query("QBAR"), D2, names.query("CLK")) network.make_connection(D2, names.query("QBAR"), D3, names.query("CLK")) network.make_connection(D3, names.query("QBAR"), D4, names.query("CLK")) network.make_connection(D1, names.query("QBAR"), D1, names.query("DATA")) network.make_connection(D2, names.query("QBAR"), D2, names.query("DATA")) network.make_connection(D3, names.query("QBAR"), D3, names.query("DATA")) network.make_connection(D4, names.query("QBAR"), D4, names.query("DATA")) monitors.make_monitor(CK, None) monitors.make_monitor(D1, names.query("Q")) monitors.make_monitor(D2, names.query("Q")) monitors.make_monitor(D3, names.query("Q")) monitors.make_monitor(D4, names.query("Q")) return names, devices, network, monitors
def new_monitors(): """Return a Monitors class instance with monitors set on three outputs.""" new_names = Names() new_devices = Devices(new_names) new_network = Network(new_names, new_devices) new_monitors = Monitors(new_names, new_devices, new_network) [SW1_ID, SW2_ID, OR1_ID, I1, I2] = new_names.lookup(["Sw1", "Sw2", "Or1", "I1", "I2"]) # Add 2 switches and an OR gate new_devices.make_device(SW1_ID, new_devices.SWITCH, [0]) new_devices.make_device(SW2_ID, new_devices.SWITCH, [0]) new_devices.make_device(OR1_ID, new_devices.OR, [2]) # Make connections new_network.make_connection(SW1_ID, None, OR1_ID, I1) new_network.make_connection(SW2_ID, None, OR1_ID, I2) # Set monitors new_monitors.make_monitor(SW1_ID, None) new_monitors.make_monitor(SW2_ID, None) new_monitors.make_monitor(OR1_ID, None) return new_monitors
def test_3(): """Create network that matches test definition file 3""" names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) S, R, CK, D = names.lookup(["S", "R", "CK", "D"]) devices.make_device(S, devices.SWITCH, 0) devices.make_device(R, devices.SWITCH, 0) devices.make_device(CK, devices.CLOCK, 1) devices.make_device(D, devices.D_TYPE) network.make_connection(CK, None, D, names.query("CLK")) network.make_connection(S, None, D, names.query("SET")) network.make_connection(R, None, D, names.query("CLEAR")) network.make_connection(D, names.query("QBAR"), D, names.query("DATA")) monitors.make_monitor(CK, None) monitors.make_monitor(D, names.query("Q")) monitors.make_monitor(S, None) monitors.make_monitor(R, None) return names, devices, network, monitors
def used_names(name_string_list): """Return a names instance, after four names have been added.""" my_name = Names() my_name.lookup(name_string_list) return my_name
def used_names(name_string_list): """putting the list into class""" my_name = Names() my_name.lookup(name_string_list) return my_name
def used_names(name_string_list): """Return a names instance, after three names have been added.""" my_name = Names() for name in name_string_list: my_name.lookup([name]) return my_name