def test_Transmitter(): transmitter = Transmitter(root) transmitter.default_input.force(1) work(transmitter) assert value(transmitter) == 1 transmitter.default_input.force(0) work(transmitter) assert value(transmitter) == 0
def test_SwitchOR(): and_ = power | power work(and_) assert value(and_) == 1 and_1 = power | not_ work(and_1) assert value(and_1) == 1 and_2 = not_ | not_ work(and_2) assert value(and_2) == 0
def test_SwitchXOR(): and_ = power ^ power work(and_) assert value(and_) == 0 and_1 = power ^ not_ work(and_1) assert value(and_1) == 1 and_2 = not_ ^ not_ work(and_2) assert value(and_2) == 0
def test_SwitchAND(): and_ = power & power work(and_) assert value(and_) == 1 and_1 = power & not_ work(and_1) assert value(and_1) == 0 and_2 = not_ & not_ work(and_2) assert value(and_2) == 0
def switch(self, state, machine): prev = state.previous_states current_state = value(self.on) | value(self.off) << 1 if current_state in (3, 2) and prev in (0, 1): current_state = 2 elif current_state in (3, 1) and prev in (0, 2): current_state = 1 else: current_state = state.default_output state.previous_states = value(self.on) | value(self.off) << 1 state.default_output = current_state & 1
def test_AND(): and_ = AND(root) and_.first.force(1) and_.second.force(1) work(and_) assert value(and_) == 1 and_.second.force(0) work(and_) assert value(and_) == 0 and_.first.force(0) work(and_) assert value(and_) == 0
def test_PersistentSwitch(): switch = PersistentSwitch(root) switch.prepare() work(switch) assert value(switch) == 0 power >> switch.on work(switch) assert value(switch) == 1 work(switch) assert value(switch) == 1 power >> switch.off work(switch) assert value(switch) == 0
def test_Switch(): machine.tick = 2 switch = Switch(root) switch.prepare() switch.default_input.force(0) work(switch) assert value(switch) == 0 switch.default_input.force(1) work(switch) assert value(switch) == 1 work(switch) assert value(switch) == 1 switch.default_input.force(0) work(switch) assert value(switch) == 1 switch.default_input.force(1) work(switch) assert value(switch) == 0
def visit_Node(self, node, graph): style = self.pick_style(node).copy() style['color'] = 'green' if value(node) else style.get('color') graph.node(node.uuid, label=node.name, style='filled', **style) for input in node.inputs: for signal in input.inputs: label = input._name if label == 'input': label = None seed(hash(label)) self.root_graph.edge(signal.node.uuid, node.uuid, label=label, color=choice(self.arrow_colors))
def visit_Compound(self, node, graph=None): parent = graph graph = gv.Digraph(name='cluster_%i' % self.cluster_count, format='png') if not parent: self.root_graph = graph self.cluster_count += 1 graph.graph_attr.update(self.pick_style(node)) graph.graph_attr.update({'label': node.name}) if value(node): graph.graph_attr.update({'style': 'filled', 'color': 'darkgreen'}) #graph.graph_attr.update({'bgcolor': '#%i33333' % random.randint(0, 99)}) for child in node.children.values(): self.visit(child, graph) if parent: parent.subgraph(graph) return graph
def visit_Compound(self, node, graph=None): parent = graph graph = gv.Digraph(name='cluster_%i' % self.cluster_count,format='png') if not parent: self.root_graph = graph self.cluster_count += 1 graph.graph_attr.update(self.pick_style(node)) graph.graph_attr.update({'label': node.name}) if value(node): graph.graph_attr.update({ 'style': 'filled', 'color': 'darkgreen' }) #graph.graph_attr.update({'bgcolor': '#%i33333' % random.randint(0, 99)}) for child in node.children.values(): self.visit(child, graph) if parent: parent.subgraph(graph) return graph
def switch(self, state, machine): state.default_output = value(self.first) ^ value(self.second)
def switch(self, state, machine): if value(self.enable): state.default_output = self.data
def switch(self, state, machine): state.default_output = not value(self.default_input)
def switch(self, state, machine): nomatch = state.previous_input == 0 and value(self.default_input) == 1 is_first_tick = machine.tick == 1 if nomatch and not is_first_tick: self.activate(state) state.previous_input = value(self.default_input)
def test_SwitchNOT(): assert value(power) == 1 assert value(not_) == 0