""" Tests for ResourceAllocator. """ import pytest from dcos.core.allocator import ResourceAllocator class TestResourceAllocator: def test_allocate(self): alloc = ResourceAllocator() assert alloc.allocate("agent_1", cpu=10.0, memory=256.0) is True def test_allocate_over_limit(self): alloc = ResourceAllocator() # Total is 100 CPU, 1024 memory assert alloc.allocate("agent_1", cpu=60.0, memory=512.0) is True assert alloc.allocate("agent_2", cpu=50.0, memory=512.0) is False # over CPU def test_release(self): alloc = ResourceAllocator() alloc.allocate("agent_1", cpu=10.0, memory=128.0) assert alloc.release("agent_1") is True assert alloc.release("nonexistent") is False def test_utilization(self): alloc = ResourceAllocator() alloc.allocate("agent_1", cpu=25.0, memory=256.0) util = alloc.utilization() assert util["cpu"] == 0.25 assert util["memory"] == 0.25 def test_get_allocation(self): alloc = ResourceAllocator() alloc.allocate("agent_1", cpu=10.0, memory=128.0) alloc_info = alloc.get_allocation("agent_1") assert alloc_info["cpu"] == 10.0