|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
import logging
|
|
|
|
|
from math import ceil
|
|
|
|
|
from random import randint
|
|
|
|
|
from unittest import TestCase
|
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
|
|
from modules import chankeep
|
|
|
|
|
from math import ceil
|
|
|
|
|
import heapq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestChanKeep(TestCase):
|
|
|
|
|
def setUp(self):
|
|
|
|
@ -48,7 +48,7 @@ class TestChanKeep(TestCase):
|
|
|
|
|
chanlimit = 5
|
|
|
|
|
max_chans = instances * chanlimit
|
|
|
|
|
listinfo = self.generate_listinfo(ranges=[[1000, 1, 2], [200, 400, 800], [10, 1000, 2000]])
|
|
|
|
|
listinfo_num = [x[1] for x in listinfo]
|
|
|
|
|
# listinfo_num = [x[1] for x in listinfo]
|
|
|
|
|
|
|
|
|
|
listlength = len(listinfo)
|
|
|
|
|
cumul = 0
|
|
|
|
@ -71,15 +71,22 @@ class TestChanKeep(TestCase):
|
|
|
|
|
|
|
|
|
|
sigrelay = ceil(siglength / chanlimit)
|
|
|
|
|
relay = ceil(listlength / chanlimit)
|
|
|
|
|
print(f"len:{listlength} cumul:{cumul} mean:{mean} siglength:{siglength} insiglength:{insiglength} sigrelay:{sigrelay} relay:{relay} sigcumul:{sigcumul} insigcumul:{insigcumul}")
|
|
|
|
|
print(
|
|
|
|
|
(
|
|
|
|
|
f"len:{listlength} cumul:{cumul} mean:{mean} "
|
|
|
|
|
f"siglength:{siglength} insiglength:{insiglength} "
|
|
|
|
|
f"sigrelay:{sigrelay} relay:{relay} sigcumul:{sigcumul} "
|
|
|
|
|
f"insigcumul:{insigcumul}"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
# We want a return between 1000 and 1100
|
|
|
|
|
|
|
|
|
|
list_insig = [x for x in listinfo_num if x < mean]
|
|
|
|
|
# list_insig = [x for x in listinfo_num if x < mean]
|
|
|
|
|
list_sig = [x for x in listinfo if x[1] > mean]
|
|
|
|
|
chosen = sorted(list_sig, reverse=True, key=lambda x: x[1])[:max_chans]
|
|
|
|
|
print("CHOSEN", chosen)
|
|
|
|
|
self.assertEqual(len(chosen), 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch("modules.chankeep.keepChannels")
|
|
|
|
|
def test__initialList(self, keepchannels):
|
|
|
|
|
chankeep._initialList(self.net, self.num, self.listinfo, self.chanlimit)
|
|
|
|
@ -91,7 +98,7 @@ class TestChanKeep(TestCase):
|
|
|
|
|
|
|
|
|
|
@patch("modules.chankeep.getChanFree")
|
|
|
|
|
def test_empty_chan_allocate(self, getchanfree):
|
|
|
|
|
getchanfree.return_value = ({1: 600}, 600) # pretend we have 600 channels free
|
|
|
|
|
getchanfree.return_value = ({1: 600}, 600) # pretend we have 600 channels free
|
|
|
|
|
eca = chankeep.emptyChanAllocate(self.net, self.chan_name_list, [])
|
|
|
|
|
self.assertEqual(len(eca), 1)
|
|
|
|
|
num = list(eca.keys())[0]
|
|
|
|
@ -106,4 +113,4 @@ class TestChanKeep(TestCase):
|
|
|
|
|
chans = eca[list(eca.keys())[0]]
|
|
|
|
|
self.assertEqual(num, self.num)
|
|
|
|
|
self.assertEqual(len(chans), 100)
|
|
|
|
|
#self.assertCountEqual(chans, self.chan_name_list)
|
|
|
|
|
# self.assertCountEqual(chans, self.chan_name_list)
|
|
|
|
|