def test_network_contains_nodes(self): n1 = Node() self.assertTrue(n1.id in self.network) self.assertTrue(n1 in self.network.values()) n2 = Node() self.assertTrue(n1.id in self.network) self.assertTrue(n1 in self.network.values())
def test_get_node(self): n1 = Node() n2 = Node() gn1 = self.network.get(n1.id) self.assertEqual(gn1, n1) gn2 = self.network.get(n2.id) self.assertEqual(gn2, n2)
def test_list_proximate_node_locations(self): n1 = Node() pl = n1._proximate_locations(1) self.assertTrue((-1, 1, -1) in pl) self.assertTrue((-1, 1, 0) in pl) self.assertTrue((-1, 1, 1) in pl) self.assertTrue((0, 1, -1) in pl) self.assertTrue((0, 1, 0) in pl) self.assertTrue((0, 1, 1) in pl) self.assertTrue((1, 1, -1) in pl) self.assertTrue((1, 1, 0) in pl) self.assertTrue((1, 1, 1) in pl) self.assertTrue((-1, 0, -1) in pl) self.assertTrue((-1, 0, 0) in pl) self.assertTrue((-1, 0, 1) in pl) self.assertTrue((0, 0, -1) in pl) self.assertTrue((0, 0, 1) in pl) self.assertTrue((1, 0, -1) in pl) self.assertTrue((1, 0, 0) in pl) self.assertTrue((1, 0, 1) in pl) self.assertTrue((-1, -1, -1) in pl) self.assertTrue((-1, -1, 0) in pl) self.assertTrue((-1, -1, 1) in pl) self.assertTrue((0, -1, -1) in pl) self.assertTrue((0, -1, 0) in pl) self.assertTrue((0, -1, 1) in pl) self.assertTrue((1, -1, -1) in pl) self.assertTrue((1, -1, 0) in pl) self.assertTrue((1, -1, 1) in pl) self.assertTrue((0, 0, 0) not in pl)
def test_network_get(self): n1 = Node() n2 = Node() self.assertEqual(n1, self.network.get(n1.id, 'NOT_FOUND')) self.assertEqual(n2, self.network.get(n2.id, 'NOT_FOUND')) self.assertEqual('NOT_FOUND', self.network.get(uuid.uuid1(), 'NOT_FOUND'))
def test_len_network(self): self.assertEqual(len(self.network), 0) n1 = Node() self.assertEqual(len(self.network), 1) n2 = Node() self.assertEqual(len(self.network), 2) self.network.clear() self.assertEqual(len(self.network), 0)
def test_consume_from_synapse(self): s = Synapse(Node()) s.add_data({'S1': 10, 'S2': 20, 123: 20}) self.assertTrue(s.has_signal('S1')) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 1, 'S2': 1}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 1, 'S2': 1}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 1, 'S2': 2}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 1, 'S2': 2}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 1, 'S2': 3}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 1, 'S2': 4}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 2, 'S2': 4}) c = s.consume(str) _reward(10) self.assertEqual(c, {'S1': 2, 'S2': 3}) c = s.consume(str) _reward(10) self.assertEqual(c, None)
def test_add_to_synapse(self): s = Synapse(Node()) self.assertFalse(s.has_signal('S1')) self.assertEqual(0, s.intensity('S1')) s.add('S1', 10) self.assertTrue(s.has_signal('S1')) self.assertEqual(10, s.intensity('S1'))
def test_add_data_to_synapse(self): s = Synapse(Node()) self.assertFalse(s.has_signal('S1')) self.assertEqual(0, s.intensity('S1')) self.assertFalse(s.has_signal('S2')) self.assertEqual(0, s.intensity('S2')) s.add_data({'S1': 10, 'S2': 20}) self.assertTrue(s.has_signal('S1')) self.assertEqual(10, s.intensity('S1')) self.assertTrue(s.has_signal('S2')) self.assertEqual(20, s.intensity('S2'))
def test_age_synapse(self): s = Synapse(Node()) s.add_data({'S1': 10, 'S2': 20}) s.age() self.assertEqual({'S1': 5, 'S2': 10}, s.data) s.age() self.assertEqual({'S1': 2, 'S2': 5}, s.data) s.age() self.assertEqual({'S1': 1, 'S2': 2}, s.data) s.age() self.assertEqual({'S2': 1}, s.data) s.age() self.assertEqual({}, s.data)
def test_join(self): n1 = Node() n2 = Node() self.assertEqual(0, len(n1.outputs)) self.assertEqual(0, len(n2.inputs)) n1.join(n2) self.assertEqual(1, len(n1.outputs)) self.assertEqual(1, len(n2.inputs)) self.assertEqual(n1.outputs[0].node, n2) self.assertEqual(n1.outputs[0], n2.inputs[0]) n1.join(n2) self.assertEqual(1, len(n1.outputs)) self.assertEqual(1, len(n2.inputs)) self.assertEqual(n1.outputs[0].node, n2) self.assertEqual(n1.outputs[0], n2.inputs[0])
def test_network_is_iterable(self): n1 = Node() n2 = Node() for key in self.network: self.assertTrue(key in _nodes)
def test_clear_network(self): n1 = Node() n2 = Node() self.assertGreater(len(self.network), 0) self.network.clear() self.assertEqual(len(self.network), 0)
def test_synapse_node_has_synapse_input(self): n = Node() s = Synapse(n) self.assertTrue(s in n.inputs)
def test_network_values(self): n1 = Node() n2 = Node() self.assertTrue(n1 in self.network.values()) self.assertTrue(n2 in self.network.values())
def test_network_keys(self): n1 = Node() n2 = Node() self.assertTrue(n1.id in self.network.keys()) self.assertTrue(n2.id in self.network.keys())
def test_network_contains(self): n1 = Node() n2 = Node() self.assertTrue(n1.id in self.network) self.assertTrue(n2.id in self.network)
def test_new_node_has_location(self): n1 = Node() self.assertEqual(n1.loc, (0, 0, 0))
def test_network_is_subscriptable(self): n1 = Node() n2 = Node() self.assertEqual(n1, self.network[n1.id]) self.assertEqual(n2, self.network[n2.id])
def test_new_node_has_unique_id(self): n1 = Node() self.assertIsNotNone(n1.id) n2 = Node() self.assertIsNotNone(n2.id) self.assertNotEqual(n1.id, n2.id)