Ejemplo n.º 1
0
    def test_flatten(self):
        for project_name in ALL_FILES_DICT.keys():
            # get content
            nrp = NextReleaseProblem(project_name)
            cost, profit, dependencies, requests = deepcopy(nrp.content())
            # only test who has dependencies
            if not dependencies or len(dependencies) == 0:
                continue
            # flatten
            nrp.flatten()
            # get content again
            neo_cost, neo_profit, neo_dependencies, neo_requests = nrp.content(
            )
            # cost and profit should not be changed
            assert neo_cost == cost
            assert neo_profit == profit
            # dependencies should be empty
            assert not neo_dependencies or len(neo_dependencies) == 0
            # now check requests
            # depdencies, request => neo_requests
            for cus, req in requests:
                # this cus, req should in new requests
                assert (cus, req) in neo_requests
                # find all requirement that require this req
                requesters = self.requester(dependencies, req)
                # find all customers
                for requester in list(requesters):
                    assert (cus, requester) in neo_requests

            # neo_requests, dependencies => requests
            for cus, req in neo_requests:
                if (cus, req) in requests:
                    pass  # no problem
                else:
                    # find all requestees
                    requestees = self.requestee(dependencies, req)
                    # print(list(requestees))
                    flag = False
                    for requestee in list(requestees):
                        if (cus, requestee) in requests:
                            flag = True
                            break
                    assert flag
Ejemplo n.º 2
0
 def test_find_demands(self):
     for project_name in ALL_FILES_DICT.keys():
         if not project_name.startswith(
                 'classic') and not project_name.startswith('realistic'):
             continue
         # get content
         nrp = NextReleaseProblem(project_name)
         if project_name.startswith('classic'):
             nrp.flatten()
         # construct demands
         requests = nrp.content()[3]
         demands = NextReleaseProblem.find_demands(requests)
         # demands => requests
         for key, values in demands.items():
             for value in values:
                 assert (value, key) in requests
         # requests => demands
         for key, value in requests:
             assert value in demands
             assert key in demands[value]
Ejemplo n.º 3
0
 def test_xuan_encoding(self):
     for project_name in ALL_FILES_DICT.keys():
         if not project_name.startswith(
                 'classic') and not project_name.startswith('realistic'):
             continue
         # get content
         nrp = NextReleaseProblem(project_name)
         if project_name.startswith('classic'):
             nrp.flatten()
         cost, profit, dependencies, requests = deepcopy(nrp.content())
         # encoding
         req_encoder, cus_encoder = nrp.xuan_reencode()
         # get content again
         neo_cost, neo_profit, neo_dependencies, neo_requests = nrp.content(
         )
         # check if encoding is one-one mapping
         assert len(set(req_encoder.values())) == len(req_encoder)
         assert len(set(cus_encoder.values())) == len(cus_encoder)
         assert not dependencies and not neo_dependencies
         # construct decoder of encoder
         req_decoder = dict(
             zip(list(req_encoder.values()), list(req_encoder.keys())))
         cus_decoder = dict(
             zip(list(cus_encoder.values()), list(cus_encoder.keys())))
         # decode neo_cost
         de_cost = dict()
         for req, req_cost in neo_cost.items():
             de_cost[req_decoder[req]] = req_cost
         # decode neo_profit
         de_profit = dict()
         for cus, cus_profit in neo_profit.items():
             de_profit[cus_decoder[cus]] = cus_profit
         # decode requests
         de_requests = []
         for cus, req in neo_requests:
             de_requests.append((cus_decoder[cus], req_decoder[req]))
         # compare
         assert cost == de_cost
         assert profit == de_profit
         assert set(requests) == set(de_requests)