def verify_random_assignment(self, topo, cache_budget, cache_nodes): cacheplacement.random_cache_placement(topo, cache_budget, cache_nodes) actual_cache_budget = 0 actual_cache_nodes = 0 for v in topo.nodes(): if 'cache_size' in topo.node[v]['stack'][1]: self.assertEqual(int(cache_budget / cache_nodes), topo.node[v]['stack'][1]['cache_size']) actual_cache_budget += topo.node[v]['stack'][1]['cache_size'] actual_cache_nodes += 1 self.assertGreater(cache_budget + cache_nodes, actual_cache_budget) self.assertLess(cache_budget - cache_nodes, actual_cache_budget) self.assertEqual(cache_nodes, actual_cache_nodes)
def verify_random_assignment(self, topo, cache_budget, cache_nodes): cacheplacement.random_cache_placement(topo, cache_budget, cache_nodes) actual_cache_budget = 0 actual_cache_nodes = 0 for v in topo.nodes(): if 'cache_size' in topo.node[v]['stack'][1]: assert int( cache_budget / cache_nodes) == topo.node[v]['stack'][1]['cache_size'] actual_cache_budget += topo.node[v]['stack'][1]['cache_size'] actual_cache_nodes += 1 assert cache_budget + cache_nodes > actual_cache_budget assert cache_budget - cache_nodes < actual_cache_budget assert cache_nodes == actual_cache_nodes
def test_random_cache_placement_all_nodes(self): cacheplacement.random_cache_placement(self.topo, 100, 4) for i in range(1, 5): self.assertEqual(25, self.topo.node[i]['stack'][1]['cache_size'])
def test_random_cache_placement_all_nodes(self): cacheplacement.random_cache_placement(self.topo, 100, 4) for i in range(1, 5): assert 25 == self.topo.node[i]["stack"][1]["cache_size"]