|
| 1 | +import pytest |
| 2 | + |
| 3 | +from allocation.allocating import WeightedMap, Allocator |
| 4 | + |
| 5 | +def test_real_case_with_five_objects(): |
| 6 | + weights = WeightedMap([ |
| 7 | + {'from': '6', 'to': '5', 'weight': 2.0}, |
| 8 | + {'from': '6', 'to': '11', 'weight': 6.0}, |
| 9 | + {'from': '6', 'to': '25', 'weight': 0.0}, |
| 10 | + {'from': '6', 'to': '67', 'weight': 0.0}, |
| 11 | + {'from': '6', 'to': '97', 'weight': 4.0}, |
| 12 | + {'from': '1', 'to': '5', 'weight': 2.0}, |
| 13 | + {'from': '14', 'to': '5', 'weight': 1.0}, |
| 14 | + {'from': '20', 'to': '5', 'weight': 3.0}, |
| 15 | + {'from': '26', 'to': '5', 'weight': 4.0}, |
| 16 | + {'from': '1', 'to': '11', 'weight': 6.0}, |
| 17 | + {'from': '14', 'to': '11', 'weight': 3.0}, |
| 18 | + {'from': '20', 'to': '11', 'weight': 4.0}, |
| 19 | + {'from': '26', 'to': '11', 'weight': 5.0}, |
| 20 | + {'from': '1', 'to': '25', 'weight': 0.0}, |
| 21 | + {'from': '14', 'to': '25', 'weight': 1.0}, |
| 22 | + {'from': '20', 'to': '25', 'weight': 0.0}, |
| 23 | + {'from': '26', 'to': '25', 'weight': 1.0}, |
| 24 | + {'from': '1', 'to': '67', 'weight': 0.0}, |
| 25 | + {'from': '14', 'to': '67', 'weight': 1.0}, |
| 26 | + {'from': '20', 'to': '67', 'weight': 2.0}, |
| 27 | + {'from': '26', 'to': '67', 'weight': 3.0}, |
| 28 | + {'from': '1', 'to': '97', 'weight': 4.0}, |
| 29 | + {'from': '14', 'to': '97', 'weight': 5.0}, |
| 30 | + {'from': '20', 'to': '97', 'weight': 3.0}, |
| 31 | + {'from': '26', 'to': '97', 'weight': 2.0}]) |
| 32 | + |
| 33 | + sources = {w['from']: 1 for w in weights} |
| 34 | + targets = {w['to']: 1 for w in weights} |
| 35 | + |
| 36 | + allocator = Allocator(sources, weights, targets) |
| 37 | + allocation = allocator.get_best() |
| 38 | + assert len(allocation) == 5 |
| 39 | + |
| 40 | + # now "remove" one target |
| 41 | + targets['97'] = 0 |
| 42 | + allocator = Allocator(sources, weights, targets) |
| 43 | + allocation = allocator.get_best() |
| 44 | + assert len(allocation) == 4 |
0 commit comments