def test_vol_nbin(nums): inputs = nums bin_cls = NumberBin a = Fit.fit(bin_cls, 9, inputs) expected = [bin_cls(9) for _ in range(5)] expected[0].append(inputs[0]) expected[1].append(inputs[1]) expected[1].append(inputs[5]) expected[1].append(inputs[6]) expected[2].append(inputs[2]) expected[3].append(inputs[3]) expected[4].append(inputs[4]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)))
def test_sort_sbin(chars, bin_size): inputs = chars bin_cls = SimpleBin a = Fit.fit(bin_cls, bin_size, inputs, sort=True, sort_reversed=False) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[6]) expected[0].append(inputs[5]) expected[0].append(inputs[1]) expected[1].append(inputs[2]) expected[2].append(inputs[4]) expected[3].append(inputs[3]) expected[4].append(inputs[0]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)))
def test_wfd_sbin(chars, bin_size): inputs = chars bin_cls = SimpleBin a = Fit.wfd(bin_cls, bin_size, inputs) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[0]) expected[1].append(inputs[3]) expected[2].append(inputs[4]) expected[3].append(inputs[2]) expected[3].append(inputs[6]) expected[4].append(inputs[1]) expected[4].append(inputs[5]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)))
def test_sort_rev_nbin(nums, bin_size): inputs = nums bin_cls = NumberBin a = Fit.fit(bin_cls, bin_size, inputs, sort=True) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[0]) expected[0].append(inputs[6]) expected[1].append(inputs[3]) expected[2].append(inputs[4]) expected[2].append(inputs[5]) expected[3].append(inputs[2]) expected[4].append(inputs[1]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)))
def test_bin_order_worst_nbin(nums, bin_size): inputs = nums bin_cls = NumberBin a = Fit.fit(bin_cls, bin_size, inputs, bin_sort=BinOrdering.worst_fit) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[0]) expected[1].append(inputs[1]) expected[1].append(inputs[5]) expected[2].append(inputs[2]) expected[2].append(inputs[6]) expected[3].append(inputs[3]) expected[4].append(inputs[4]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)))
def test_ffd_nbin(nums, bin_size): inputs = nums bin_cls = NumberBin a = Fit.ffd(bin_cls, bin_size, inputs) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[0]) expected[0].append(inputs[6]) expected[1].append(inputs[3]) expected[2].append(inputs[4]) expected[2].append(inputs[5]) expected[3].append(inputs[2]) expected[4].append(inputs[1]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)) and a.method == "First Fit Decreasing (FFD)")
def test_bin_order_best_sbin(chars, bin_size): inputs = chars bin_cls = SimpleBin a = Fit.fit(bin_cls, bin_size, inputs, bin_sort=BinOrdering.best_fit) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[0]) expected[0].append(inputs[6]) expected[1].append(inputs[1]) expected[2].append(inputs[2]) expected[3].append(inputs[3]) expected[4].append(inputs[4]) expected[4].append(inputs[5]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)))
def test_ff_sbin(chars, bin_size): inputs = chars bin_cls = SimpleBin a = Fit.ff(bin_cls, bin_size, inputs) expected = [bin_cls(bin_size) for _ in range(5)] expected[0].append(inputs[0]) expected[0].append(inputs[6]) expected[1].append(inputs[1]) expected[1].append(inputs[5]) expected[2].append(inputs[2]) expected[3].append(inputs[3]) expected[4].append(inputs[4]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)) and a.method == "First Fit (FF)")
def test_nf_nbin(nums, bin_size): inputs = nums bin_cls = NumberBin a = Fit.nf(bin_cls, bin_size, inputs) expected = [bin_cls(bin_size) for _ in range(6)] expected[0].append(inputs[0]) expected[1].append(inputs[1]) expected[2].append(inputs[2]) expected[3].append(inputs[3]) expected[4].append(inputs[4]) expected[4].append(inputs[5]) expected[5].append(inputs[6]) assert (bin_sorter(a.bins) == bin_sorter(tuple(expected)) and a.method == "Next Fit (NF)")
def test_meth_name(bin_size): bin_cls = SimpleBin a = Fit.fit(bin_cls, bin_size, [], method_name="TESTING") assert (a.method == "TESTING")
def test_start_bins_lt_one(bin_size): a = Fit.fit(SimpleBin, bin_size, [], starting_bins=-1) assert (a.bins == tuple([SimpleBin(bin_size)]))
def test_start(bin_size): a = Fit.fit(SimpleBin, bin_size, [], starting_bins=2) assert (a.bins == tuple([SimpleBin(bin_size), SimpleBin(bin_size)]))
def test_replace_blank(): assert (Fit._replace_method_code(None) == "Custom")
def test_starting_bins_gt_max_bins(bin_size): inputs = [] bin_cls = SimpleBin a = Fit.fit(bin_cls, bin_size, inputs, starting_bins=10, max_open_bins=3) assert (a.total_bins == 3)
def basic(request): return Fit.ffd(SimpleBin, 5, "a ab d c w xx z".split())
def test_detect_method_variant(): assert (Fit._detect_method(False, False, 1, BinOrdering.best_fit, None) == Fit._replace_method_code("bfv"))
def test_repr(): a = Fit.fit(SimpleBin,1,[]) assert(a.__repr__() == "<BPResult (Total Bins: 1, Total Volume: 1, Unused Volume: 1)>")
# bin_size = random.randint(10,100) # fit_these = [random.randint(1, bin_size) for _ in range(1000)] # print(fit_these) bin_size = 80 fit_these = [ 26, 57, 18, 8, 45, 16, 22, 29, 5, 11, 8, 27, 54, 13, 17, 21, 63, 14, 16, 45, 6, 32, 57, 24, 18, 27, 54, 35, 12, 43, 36, 72, 14, 28, 3, 11, 46, 27, 42, 59, 26, 41, 15, 41, 68 ] # print(fit_these) # generic_results = Fit.fit(NumberBin, bin_size, fit_these) next_fit_results = Fit.nf(NumberBin, bin_size, fit_these) first_fit_results = Fit.ff(NumberBin, bin_size, fit_these) worst_fit_result = Fit.wf(NumberBin, bin_size, fit_these) best_fit_result = Fit.bf(NumberBin, bin_size, fit_these) # sorted_next_fit_results = Fit.nfd(NumberBin, bin_size, fit_these) # not implemented sorted_first_fit_results = Fit.ffd(NumberBin, bin_size, fit_these) sorted_worst_fit_result = Fit.wfd(NumberBin, bin_size, fit_these) sorted_best_fit_result = Fit.bfd(NumberBin, bin_size, fit_these) print_result("Next Fit", next_fit_results) print_result("First Fit", first_fit_results) print_result("Worst Fit", worst_fit_result) print_result("Best Fit", best_fit_result) # print_result("Next Fit With Sort", next_fit_results) # not implemented
def test_repr(): a = Fit.fit(SimpleBin, 1, []) assert (a.__repr__() == "<BPResult (Total Bins: 1, Total Volume: 1, Unused Volume: 1)>")