diff --git a/app/services/matchmaking/builds_participants.rb b/app/services/matchmaking/builds_participants.rb deleted file mode 100644 index d4c684e..0000000 --- a/app/services/matchmaking/builds_participants.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Matchmaking - class BuildsParticipants - def initialize - @scores_participant_candidates = ScoresParticipantCandidates.new - end - - def call(participant_ids) - participant_ids.map do |id| - match_candidates = build_match_candidates(participant_ids, id) - grouped_historical_matches = collect_historical_matches_by_grouping(id) - - @scores_participant_candidates.call( - participant: Participant.new( - id: id, - match_candidates: match_candidates, - grouped_historical_matches: grouped_historical_matches - ) - ) - end - end - - private - - def build_match_candidates(participant_ids, current_id) - participant_ids.difference([current_id]) - .map { |other_id| ScoredMatchCandidate.new(id: other_id) } - end - - def collect_historical_matches_by_grouping(participant_id) - HistoricalMatch.scoreable.where("'#{participant_id}' = any(members)").to_a - .group_by { |m| m.grouping } - end - end -end diff --git a/app/services/matchmaking/determines_matches.rb b/app/services/matchmaking/determines_matches.rb deleted file mode 100644 index 6854eb6..0000000 --- a/app/services/matchmaking/determines_matches.rb +++ /dev/null @@ -1,127 +0,0 @@ -module Matchmaking - class DeterminesMatches - def initialize(config: nil) - @config = config || Rails.application.config.x.matchmaking - @unmatched_participants = [] - @determined_matches = [] - end - - def call(grouping:, participants:) - reset!(grouping, participants) - - min_match_size = @config.send(grouping.intern).size - max_group_count = participants.size / min_match_size - iterations = min_match_size + (participants.size % min_match_size) - - while iterations > 0 - (0...max_group_count).each do |group_ix| - return @determined_matches if all_participants_are_matched? - - if match_missing?(group_ix) - # add the first member to the match when it hasn't been started - add_member_to_match(group_ix, choose_candidate(@unmatched_participants).id) - next - end - - # add remaining members to the match - add_member_to_match(group_ix, find_optimal_candidate_for_current_members(group_ix, participants)) - end - - iterations -= 1 - end - - @determined_matches - end - - private - - def reset!(grouping, participants) - @grouping = grouping - @unmatched_participants = participants - @determined_matches = [] - end - - def all_participants_are_matched? - @unmatched_participants.empty? - end - - def mark_participant_as_matched!(participant) - @unmatched_participants = @unmatched_participants.reject { |p| p.id == participant } - end - - def match_missing?(group_index) - @determined_matches[group_index].nil? - end - - def determine_match!(group_index, match) - @determined_matches[group_index] = match - end - - def current_match(group_index) - @determined_matches[group_index] - end - - def choose_candidate(eligible_candidates) - eligible_candidates.sample - end - - def add_member_to_match(group_index, chosen) - determine_match!(group_index, Match.new( - grouping: @grouping, - members: (current_match(group_index)&.members || []).union([chosen]).sort - )) - mark_participant_as_matched!(chosen) - end - - def find_optimal_candidate_for_current_members(group_index, participants) - all_previously_eligible_candidates = [] - chosen = nil - - all_candidates_by_score(participants, current_match(group_index)).each do |_, candidates_for_score| - next if candidates_for_score.empty? - - # candidate has to be unmatched AND be best option between current members - threshold_candidates = candidates_in_common(candidates_for_score, all_previously_eligible_candidates) - - if (selected = choose_candidate(threshold_candidates)) - chosen = selected - break - end - - all_previously_eligible_candidates += candidates_for_score.flatten.compact.intersection(@unmatched_participants.map(&:id)) - end - - if chosen.nil? && (chosen = choose_candidate(all_previously_eligible_candidates)).nil? - raise "something went terribly terribly wrong" - end - - chosen - end - - def all_candidates_by_score(participants, current_match) - # The goal of this method may not be as clear as to _why_ it needs to - # happen the way it is. Functionally, it builds up hash where the key - # is the score and the value is a multi-dimensional list of candidates. - current_match.members.map { |member| - participants.find { |p| p.id == member } - .match_candidates.group_by(&:score).sort_by { |k, v| k }.to_h - }.each_with_object({}) do |candidates_by_score, memo| - candidates_by_score.each do |score, candidates| - memo[score] = [] if memo[score].nil? - memo[score].push(candidates.map(&:id)) - end - - memo - end - end - - def candidates_in_common(candidates_per_participant, all_previously_eligible_candidates) - starting_candidates = candidates_per_participant.first - .union(all_previously_eligible_candidates).compact - - candidates_per_participant.drop(1) - .reduce(starting_candidates) { |memo, candidates| memo.intersection(candidates) } - .intersection(@unmatched_participants.map(&:id)) - end - end -end diff --git a/app/services/matchmaking/match.rb b/app/services/matchmaking/match.rb deleted file mode 100644 index 9c6b892..0000000 --- a/app/services/matchmaking/match.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Matchmaking - class Match < Struct.new(:grouping, :members, keyword_init: true) - end -end diff --git a/app/services/matchmaking/matches_participants.rb b/app/services/matchmaking/matches_participants.rb deleted file mode 100644 index ad31c88..0000000 --- a/app/services/matchmaking/matches_participants.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Matchmaking - class MatchesParticipants - def initialize(config: nil) - @builds_participants = BuildsParticipants.new - @determines_matches = DeterminesMatches.new(config: config) - end - - def call(grouping:, participant_ids:) - return [] if participant_ids.size < 2 - - @determines_matches.call( - grouping: grouping, - participants: @builds_participants.call(participant_ids) - ) - end - end -end diff --git a/app/services/matchmaking/participant.rb b/app/services/matchmaking/participant.rb deleted file mode 100644 index 752cbf2..0000000 --- a/app/services/matchmaking/participant.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Matchmaking - class Participant < Struct.new(:id, :match_candidates, :grouped_historical_matches, keyword_init: true) - end -end diff --git a/app/services/matchmaking/scored_match_candidate.rb b/app/services/matchmaking/scored_match_candidate.rb deleted file mode 100644 index 0bfd9bf..0000000 --- a/app/services/matchmaking/scored_match_candidate.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Matchmaking - class ScoredMatchCandidate < Struct.new(:id, :score, keyword_init: true) - def initialize(id:, score: 0) - super - end - end -end diff --git a/app/services/matchmaking/scores_participant_candidates.rb b/app/services/matchmaking/scores_participant_candidates.rb deleted file mode 100644 index e0ddd81..0000000 --- a/app/services/matchmaking/scores_participant_candidates.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Matchmaking - class ScoresParticipantCandidates - def call(participant:) - return participant if participant.grouped_historical_matches.empty? - - all_historical_matches = participant.grouped_historical_matches.values.flatten - - candidates_with_adjusted_scores = participant.match_candidates.map do |candidate| - candidate_matches = historical_candidate_matches(all_historical_matches, candidate) - - if (match_count = candidate_matches.count).positive? - ScoredMatchCandidate.new(id: candidate.id, score: candidate.score + match_count) - else - candidate - end - end - - Participant.new( - id: participant.id, - match_candidates: candidates_with_adjusted_scores, - grouped_historical_matches: participant.grouped_historical_matches - ) - end - - private - - def historical_candidate_matches(historical_matches, candidate) - historical_matches.select { |match| match.members.include?(candidate.id) } - end - end -end diff --git a/spec/lib/matchmaking/builds_participants_spec.rb b/spec/lib/matchmaking/builds_participants_spec.rb deleted file mode 100644 index e05344a..0000000 --- a/spec/lib/matchmaking/builds_participants_spec.rb +++ /dev/null @@ -1,72 +0,0 @@ -require "rails_helper" - -RSpec.describe Matchmaking::BuildsParticipants, type: :matchmaking do - subject { Matchmaking::BuildsParticipants.new } - - it "returns empty list for no participants" do - result = subject.call([]) - - expect(result).to eq([]) - end - - it "returns a list of participants with no historical matches when no historical matches are found" do - participant_ids = ["USER_ID_1", "USER_ID_2"] - - result = subject.call(participant_ids) - - expect(result).to eq([ - Matchmaking::Participant.new( - id: "USER_ID_1", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_2") - ], - grouped_historical_matches: {} - ), - Matchmaking::Participant.new( - id: "USER_ID_2", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_1") - ], - grouped_historical_matches: {} - ) - ]) - end - - it "returns a list of participants with historical matches when historical matches are found" do - one_and_three = create_historical_match(grouping: "test", members: ["USER_ID_1", "USER_ID_3"]) - participant_ids = ["USER_ID_1", "USER_ID_2", "USER_ID_3"] - - result = subject.call(participant_ids) - - expect(result).to eq([ - Matchmaking::Participant.new( - id: "USER_ID_1", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_2"), - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_3", score: 1) - ], - grouped_historical_matches: { - "test" => [one_and_three] - } - ), - Matchmaking::Participant.new( - id: "USER_ID_2", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_1"), - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_3") - ], - grouped_historical_matches: {} - ), - Matchmaking::Participant.new( - id: "USER_ID_3", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_1", score: 1), - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_2") - ], - grouped_historical_matches: { - "test" => [one_and_three] - } - ) - ]) - end -end diff --git a/spec/lib/matchmaking/determines_matches_spec.rb b/spec/lib/matchmaking/determines_matches_spec.rb deleted file mode 100644 index 900a79d..0000000 --- a/spec/lib/matchmaking/determines_matches_spec.rb +++ /dev/null @@ -1,265 +0,0 @@ -require "rails_helper" - -RSpec.describe Matchmaking::DeterminesMatches, type: :matchmaking do - let(:seed) { 98765 } - - before(:example) { srand(seed) } - - context "with a group size of 2" do - let(:config) { OpenStruct.new(test: OpenStruct.new(size: 2)) } - - subject { Matchmaking::DeterminesMatches.new(config: config) } - - it "returns empty list for no participants" do - matches = subject.call(grouping: "test", participants: []) - - expect(matches).to eq([]) - end - - it "returns empty list for a single participant" do - participants = new_participants(ids: ["USER_ID_1"]) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([]) - end - - it "returns a single match when only two participants are given" do - participants = new_participants(ids: ["USER_ID_1", "USER_ID_2"]) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_2"]) - ]) - end - - it "returns a larger match than desired when the number of participants does not divide cleanly" do - participants = new_participants(ids: ["USER_ID_1", "USER_ID_2", "USER_ID_3"]) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_2", "USER_ID_3"]) - ]) - end - - it "returns multiple groups for a number of participants greater than minimum group size" do - participants = new_participants(ids: ["USER_ID_1", "USER_ID_2", "USER_ID_3", "USER_ID_4"]) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_2", "USER_ID_4"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_3"]) - ]) - end - - it "matches lower scored candidates over higher scored candidates" do - one_and_two = create_historical_match(grouping: "test", members: ["USER_ID_1", "USER_ID_2"]) - one_and_three = create_historical_match(grouping: "test", members: ["USER_ID_1", "USER_ID_3"]) - two_and_four = create_historical_match(grouping: "test", members: ["USER_ID_2", "USER_ID_4"]) - - participants = [ - new_participant( - id: "USER_ID_1", - match_candidates: [ - new_match_candidate(id: "USER_ID_2", score: 1), - new_match_candidate(id: "USER_ID_3", score: 1), - new_match_candidate(id: "USER_ID_4") - ], - historical_matches: [one_and_two, one_and_three] - ), - new_participant( - id: "USER_ID_2", - match_candidates: [ - new_match_candidate(id: "USER_ID_1", score: 1), - new_match_candidate(id: "USER_ID_3"), - new_match_candidate(id: "USER_ID_4", score: 1) - ], - historical_matches: [one_and_two, two_and_four] - ), - new_participant( - id: "USER_ID_3", - match_candidates: [ - new_match_candidate(id: "USER_ID_1", score: 1), - new_match_candidate(id: "USER_ID_2"), - new_match_candidate(id: "USER_ID_4") - ], - historical_matches: [one_and_three] - ), - new_participant( - id: "USER_ID_4", - match_candidates: [ - new_match_candidate(id: "USER_ID_1"), - new_match_candidate(id: "USER_ID_2", score: 1), - new_match_candidate(id: "USER_ID_3") - ], - historical_matches: [two_and_four] - ) - ] - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_2", "USER_ID_3"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_4"]) - ]) - end - end - - context "with a group size of 3" do - let(:config) { OpenStruct.new(test: OpenStruct.new(size: 3)) } - - subject { Matchmaking::DeterminesMatches.new(config: config) } - - it "returns single larger group when multiple cannot satisfy minimum group size" do - participants = new_participants(ids: ["USER_ID_1", "USER_ID_2", "USER_ID_3", "USER_ID_4", "USER_ID_5"]) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_2", "USER_ID_3", "USER_ID_4", "USER_ID_5"]) - ]) - end - - it "returns multiple groups of the desired size when enough participants exist" do - participants = new_participants( - ids: ["USER_ID_1", "USER_ID_2", "USER_ID_3", "USER_ID_4", "USER_ID_5", "USER_ID_6"] - ) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_5", "USER_ID_6"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_2", "USER_ID_3", "USER_ID_4"]) - ]) - end - - it "returns multiple groups of difference sizes when enough participants exist" do - participants = new_participants( - ids: ["USER_ID_1", "USER_ID_2", "USER_ID_3", "USER_ID_4", "USER_ID_5", "USER_ID_6", "USER_ID_7"] - ) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_3", "USER_ID_5", "USER_ID_6", "USER_ID_7"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_2", "USER_ID_4"]) - ]) - end - - it "ensures all participants are matched exactly once on the first run" do - participants = new_participants( - ids: ["USER_ID_01", "USER_ID_02", "USER_ID_03", "USER_ID_04", "USER_ID_05", "USER_ID_06", "USER_ID_07", "USER_ID_08", "USER_ID_09", "USER_ID_10"] - ) - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches.map(&:members).flatten.uniq.size).to eq(10) - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_05", "USER_ID_06", "USER_ID_08", "USER_ID_09"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_03", "USER_ID_04", "USER_ID_10"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_01", "USER_ID_02", "USER_ID_07"]) - ]) - end - - it "ensures all participants are matched exactly once on a subsequent run when historical matches exist" do - five_six_eight_nine = create_historical_match(grouping: "test", members: ["USER_ID_05", "USER_ID_06", "USER_ID_08", "USER_ID_09"]) - three_four_ten = create_historical_match(grouping: "test", members: ["USER_ID_03", "USER_ID_04", "USER_ID_10"]) - one_two_seven = create_historical_match(grouping: "test", members: ["USER_ID_01", "USER_ID_02", "USER_ID_07"]) - - participants = [ - new_participant( - id: "USER_ID_01", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_03", "USER_ID_04", "USER_ID_05", "USER_ID_06", "USER_ID_08", "USER_ID_09", "USER_ID_10"], - 1 => ["USER_ID_02", "USER_ID_07"] - }), - historical_matches: [one_two_seven] - ), - new_participant( - id: "USER_ID_02", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_03", "USER_ID_04", "USER_ID_05", "USER_ID_06", "USER_ID_08", "USER_ID_09", "USER_ID_10"], - 1 => ["USER_ID_01", "USER_ID_07"] - }), - historical_matches: [one_two_seven] - ), - new_participant( - id: "USER_ID_03", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_05", "USER_ID_06", "USER_ID_07", "USER_ID_08", "USER_ID_09"], - 1 => ["USER_ID_04", "USER_ID_10"] - }), - historical_matches: [three_four_ten] - ), - new_participant( - id: "USER_ID_04", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_05", "USER_ID_06", "USER_ID_07", "USER_ID_08", "USER_ID_09"], - 1 => ["USER_ID_03", "USER_ID_10"] - }), - historical_matches: [three_four_ten] - ), - new_participant( - id: "USER_ID_05", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_03", "USER_ID_04", "USER_ID_07", "USER_ID_10"], - 1 => ["USER_ID_06", "USER_ID_08", "USER_ID_09"] - }), - historical_matches: [five_six_eight_nine] - ), - new_participant( - id: "USER_ID_06", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_03", "USER_ID_04", "USER_ID_07", "USER_ID_10"], - 1 => ["USER_ID_05", "USER_ID_08", "USER_ID_09"] - }), - historical_matches: [five_six_eight_nine] - ), - new_participant( - id: "USER_ID_07", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_03", "USER_ID_04", "USER_ID_05", "USER_ID_06", "USER_ID_08", "USER_ID_09", "USER_ID_10"], - 1 => ["USER_ID_01", "USER_ID_02"] - }), - historical_matches: [one_two_seven] - ), - new_participant( - id: "USER_ID_08", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_03", "USER_ID_04", "USER_ID_07", "USER_ID_10"], - 1 => ["USER_ID_05", "USER_ID_06", "USER_ID_09"] - }), - historical_matches: [five_six_eight_nine] - ), - new_participant( - id: "USER_ID_09", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_03", "USER_ID_04", "USER_ID_07", "USER_ID_10"], - 1 => ["USER_ID_05", "USER_ID_06", "USER_ID_08"] - }), - historical_matches: [five_six_eight_nine] - ), - new_participant( - id: "USER_ID_10", - match_candidates: new_candidates_by_score({ - 0 => ["USER_ID_01", "USER_ID_02", "USER_ID_05", "USER_ID_06", "USER_ID_07", "USER_ID_08", "USER_ID_09"], - 1 => ["USER_ID_03", "USER_ID_04"] - }), - historical_matches: [three_four_ten] - ) - ] - - matches = subject.call(grouping: "test", participants: participants) - - expect(matches.map(&:members).flatten.uniq.size).to eq(10) - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_02", "USER_ID_06", "USER_ID_09", "USER_ID_10"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_01", "USER_ID_04", "USER_ID_05"]), - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_03", "USER_ID_07", "USER_ID_08"]) - ]) - end - end -end diff --git a/spec/lib/matchmaking/matches_participants_spec.rb b/spec/lib/matchmaking/matches_participants_spec.rb deleted file mode 100644 index 33092a3..0000000 --- a/spec/lib/matchmaking/matches_participants_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require "rails_helper" - -RSpec.describe Matchmaking::MatchesParticipants do - let(:config) { OpenStruct.new(test: OpenStruct.new(size: 2)) } - let(:seed) { 98765 } - - subject { Matchmaking::MatchesParticipants.new(config: config) } - - before(:example) do - srand(seed) - end - - it "creates no matches for no participants" do - matches = subject.call(grouping: "test", participant_ids: []) - - expect(matches).to eq([]) - end - - it "creates no matches for a single participant" do - matches = subject.call(grouping: "test", participant_ids: ["USER_ID_1"]) - - expect(matches).to eq([]) - end - - it "creates one match with all participants for two participants" do - matches = subject.call(grouping: "test", participant_ids: ["USER_ID_1", "USER_ID_2"]) - - expect(matches).to eq([ - Matchmaking::Match.new(grouping: "test", members: ["USER_ID_1", "USER_ID_2"]) - ]) - end -end diff --git a/spec/lib/matchmaking/scores_participant_candidates_spec.rb b/spec/lib/matchmaking/scores_participant_candidates_spec.rb deleted file mode 100644 index 46d624f..0000000 --- a/spec/lib/matchmaking/scores_participant_candidates_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require "rails_helper" - -RSpec.describe Matchmaking::ScoresParticipantCandidates, type: :matchmaking do - subject { Matchmaking::ScoresParticipantCandidates.new } - - it "does not change score when no historical match exists" do - participant = new_participant( - id: "USER_ID_1", - match_candidates: [new_match_candidate(id: "USER_ID_2")], - historical_matches: [] - ) - - result = subject.call(participant: participant) - - expect(result).to eq( - Matchmaking::Participant.new( - id: "USER_ID_1", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_2") - ], - grouped_historical_matches: {} - ) - ) - end - - it "adjusts score for candidates found in previous matches" do - one_and_three_oldest = create_historical_match(grouping: "test", members: ["USER_ID_1", "USER_ID_3"]) - one_and_three_newest = create_historical_match(grouping: "test", members: ["USER_ID_1", "USER_ID_3"]) - one_and_four = create_historical_match(grouping: "test", members: ["USER_ID_1", "USER_ID_4"]) - - participant = new_participant( - id: "USER_ID_1", - match_candidates: [ - new_match_candidate(id: "USER_ID_2"), - new_match_candidate(id: "USER_ID_3"), - new_match_candidate(id: "USER_ID_4") - ], - historical_matches: [ - one_and_three_oldest, - one_and_three_newest, - one_and_four - ] - ) - - result = subject.call(participant: participant) - - expect(result).to eq( - Matchmaking::Participant.new( - id: "USER_ID_1", - match_candidates: [ - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_2"), - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_3", score: 2), - Matchmaking::ScoredMatchCandidate.new(id: "USER_ID_4", score: 1) - ], - grouped_historical_matches: { - "test" => [one_and_three_oldest, one_and_three_newest, one_and_four] - } - ) - ) - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c370516..5fe0a7d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -50,5 +50,4 @@ # config.filter_gems_from_backtrace("gem name") config.include DatabaseHelpers - config.include MatchmakingHelpers, type: :matchmaking end diff --git a/spec/support/matchmaking_helpers.rb b/spec/support/matchmaking_helpers.rb deleted file mode 100644 index 782f8ca..0000000 --- a/spec/support/matchmaking_helpers.rb +++ /dev/null @@ -1,35 +0,0 @@ -module MatchmakingHelpers - def new_participants(ids:, historical_matches: []) - all_match_candidates = ids.map { |id| new_match_candidate(id: id) } - - ids.map { |id| - new_participant( - id: id, - match_candidates: all_match_candidates.reject { |candidate| candidate.id == id }, - historical_matches: historical_matches.select { |match| match.members.include?(id) } - ) - } - end - - def new_participant(id:, match_candidates: [], historical_matches: []) - Matchmaking::Participant.new( - id: id, - match_candidates: match_candidates, - grouped_historical_matches: historical_matches.group_by(&:grouping) - ) - end - - def new_match_candidate(id:, score: 0) - Matchmaking::ScoredMatchCandidate.new(id: id, score: score) - end - - def new_match(grouping:, members:) - Matchmaking::Match.new(grouping: grouping, members: members) - end - - def new_candidates_by_score(scored_candidates) - scored_candidates.reduce([]) { |memo, (score, candidates)| - memo.concat(candidates.map { |id| new_match_candidate(id: id, score: score) }) - } - end -end