def test_xor_gate(self): input1 = Neuron(value=1, weight=1) #1 input2 = Neuron(value=1, weight=1) #1 input3 = Neuron(weight=1, threshold=0.5, neuron_input_list=[input1, input2]) input4 = Neuron(weight=-1, threshold=1.5, neuron_input_list=[input1, input2]) xor_gate = Neuron(threshold=0.5, neuron_input_list=[input3, input4]) self.assertEquals(xor_gate.fire(), 0) input1 = Neuron(value=1, weight=1) #1 input2 = Neuron(weight=1) #0 input3 = Neuron(weight=1, threshold=0.5, neuron_input_list=[input1, input2]) input4 = Neuron(weight=-1, threshold=1.5, neuron_input_list=[input1, input2]) xor_gate = Neuron(threshold=0.5, neuron_input_list=[input3, input4]) self.assertEquals(xor_gate.fire(), 1) input1 = Neuron(value=1, weight=1) #1 input2 = Neuron(weight=1) #0 input3 = Neuron(weight=1, threshold=0.5, neuron_input_list=[input2, input1]) input4 = Neuron(weight=-1, threshold=1.5, neuron_input_list=[input1, input2]) xor_gate = Neuron(threshold=0.5, neuron_input_list=[input4, input3]) self.assertEquals(xor_gate.fire(), 1) input1 = Neuron(weight=1) #0 input2 = Neuron(weight=1) #0 input3 = Neuron(weight=1, threshold=0.5, neuron_input_list=[input1, input2]) input4 = Neuron(weight=-1, threshold=1.5, neuron_input_list=[input1, input2]) xor_gate = Neuron(threshold=0.5, neuron_input_list=[input3, input4]) self.assertEquals(xor_gate.fire(), 0) #- XOR API -# in1 = Neuron(value=1, weight=1) #1 in2 = Neuron(value=1, weight=1) #1 xor_gate = Neuron.xor_gate() xor_gate.set_inputs([in1, in2]) self.assertEqual(xor_gate.fire(), 0) in1 = Neuron(value=1, weight=1) #1 in2 = Neuron(weight=1) #0 xor_gate = Neuron.xor_gate() xor_gate.set_inputs([in1, in2]) self.assertEqual(xor_gate.fire(), 1) xor_gate.set_inputs([in2, in1]) self.assertEqual(xor_gate.fire(), 1) xor_gate.set_inputs([in2, in2]) self.assertEqual(xor_gate.fire(), 0)