def test_filter_and_empty(self): members = Members([Member('a'), Member('b')]) tree = members.combinations() filtered = EvaluationService( ).pair_must_have_only_either_member_of_last_pair( Pairs([Pair(Member('a'), Member('b'))]), tree) self.assertEqual(filtered, [])
def test_evaluate_three_times(self): history = [ Pairs([ Pair(Member('a'), Member('b')), Pair(Member('c'), Member('d')), Pair(Member('e'), None) ]), Pairs([ Pair(Member('a'), Member('c')), Pair(Member('d'), Member('e')), Pair(Member('b'), None) ]), Pairs([ Pair(Member('c'), Member('d')), Pair(Member('b'), Member('e')), Pair(Member('a'), None) ]) ] members = Members( [Member('a'), Member('b'), Member('c'), Member('d'), Member('e')]) pairs = EvaluationService().evaluate(history, members) self.assertEqual(pairs, [ Pairs([ Pair(Member('d'), Member('e')), Pair(Member('a'), Member('b')), Pair(Member('c'), None) ]) ])
def test_filter2(self): tree = self.members5.combinations() filtered_tree = EvaluationService( ).pair_must_have_only_either_member_of_last_pair( self.last_pairs5, tree) self.assertEqual(filtered_tree, [ PairTree(Pair(Member('a'), Member('c')), [ PairTree(Pair(Member('d'), Member('e')), [PairTree(Pair(Member('b'), None), [])]) ]), PairTree(Pair(Member('a'), Member('d')), [ PairTree(Pair(Member('c'), Member('e')), [PairTree(Pair(Member('b'), None), [])]) ]), PairTree(Pair(Member('a'), Member('e')), [ PairTree(Pair(Member('b'), Member('c')), [PairTree(Pair(Member('d'), None), [])]), PairTree(Pair(Member('b'), Member('d')), [PairTree(Pair(Member('c'), None), [])]) ]), PairTree(Pair(Member('b'), Member('c')), [ PairTree(Pair(Member('d'), Member('e')), [PairTree(Pair(Member('a'), None), [])]) ]), PairTree(Pair(Member('b'), Member('d')), [ PairTree(Pair(Member('c'), Member('e')), [PairTree(Pair(Member('a'), None), [])]) ]), PairTree(Pair(Member('b'), Member('e')), [ PairTree(Pair(Member('a'), Member('c')), [PairTree(Pair(Member('d'), None), [])]), PairTree(Pair(Member('a'), Member('d')), [PairTree(Pair(Member('c'), None), [])]) ]) ])
def test_filter_same_pair3(self): history = [ Pairs([ Pair(Member('a'), Member('c')), Pair(Member('d'), Member('e')), Pair(Member('b'), None) ]), Pairs([ Pair(Member('a'), Member('b')), Pair(Member('c'), Member('d')), Pair(Member('e'), None) ]) ] tree = self.members5.combinations() s = EvaluationService() filtered_pairs = s.pair_should_not_exist_same_pair_in_near_history( history, PairTree.possible_pairs( s.pair_must_have_only_either_member_of_last_pair( history[-1], tree))) self.assertEqual(filtered_pairs, [ Pairs([ Pair(Member('a'), Member('e')), Pair(Member('b'), Member('c')), Pair(Member('d'), None) ]), Pairs([ Pair(Member('a'), Member('e')), Pair(Member('b'), Member('d')), Pair(Member('c'), None) ]), Pairs([ Pair(Member('b'), Member('d')), Pair(Member('c'), Member('e')), Pair(Member('a'), None) ]), Pairs([ Pair(Member('b'), Member('e')), Pair(Member('a'), Member('c')), Pair(Member('d'), None) ]), Pairs([ Pair(Member('b'), Member('e')), Pair(Member('a'), Member('d')), Pair(Member('c'), None) ]) ])
def test_evaluate(self): last_pairs = Pairs([ Pair(Member('a'), Member('b')), Pair(Member('c'), Member('d')), Pair(Member('e'), None) ]) members = Members( [Member('a'), Member('b'), Member('c'), Member('d'), Member('e')]) pairs = EvaluationService().evaluate([last_pairs], members) self.assertEqual(pairs, [ Pairs([ Pair(Member('a'), Member('c')), Pair(Member('d'), Member('e')), Pair(Member('b'), None) ]), Pairs([ Pair(Member('a'), Member('d')), Pair(Member('c'), Member('e')), Pair(Member('b'), None) ]), Pairs([ Pair(Member('a'), Member('e')), Pair(Member('b'), Member('c')), Pair(Member('d'), None) ]), Pairs([ Pair(Member('a'), Member('e')), Pair(Member('b'), Member('d')), Pair(Member('c'), None) ]), Pairs([ Pair(Member('b'), Member('c')), Pair(Member('d'), Member('e')), Pair(Member('a'), None) ]), Pairs([ Pair(Member('b'), Member('d')), Pair(Member('c'), Member('e')), Pair(Member('a'), None) ]), Pairs([ Pair(Member('b'), Member('e')), Pair(Member('a'), Member('c')), Pair(Member('d'), None) ]), Pairs([ Pair(Member('b'), Member('e')), Pair(Member('a'), Member('d')), Pair(Member('c'), None) ]), ])
def test_filter_same_pair2(self): history = [ Pairs([Pair(Member('a'), Member('b')), Pair(Member('c'), None)]), Pairs([Pair(Member('a'), Member('c')), Pair(Member('b'), None)]) ] pairs = PairTree.possible_pairs(self.members3.combinations()) filtered_pairs = EvaluationService( ).pair_should_not_exist_same_pair_in_near_history(history, pairs) self.assertEqual( filtered_pairs, [Pairs([Pair(Member('b'), Member('c')), Pair(Member('a'), None)])])
def test_position_filter(self): history = [ Pairs([Pair(Member('a'), Member('b')), Pair(Member('c'), None)]), Pairs([Pair(Member('a'), Member('c')), Pair(Member('b'), None)]) ] tree = self.members3.combinations() possible_pairs = PairTree.possible_pairs(tree) filtered_tree = EvaluationService( ).member_is_must_not_in_same_position_at_three_times( history, possible_pairs) self.assertEqual( filtered_tree, [Pairs([Pair(Member('b'), Member('c')), Pair(Member('a'), None)])])
def setUp(self): self.repository = InMemoryPairsHistoryRepository() self.use_case = NextPairsByHistory(self.repository, EvaluationService())
def evaluation_service() -> EvaluationService: return EvaluationService()