Skip to content

Commit

Permalink
Use permutation rather than combination
Browse files Browse the repository at this point in the history
While it requires twice as many elements to check were not working with
that many and using permutation avoids needed to ensure the list is
sorted.
  • Loading branch information
rjlynch committed Dec 23, 2024
1 parent 278d3d7 commit 38b7ff1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/models/policies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def self.with_attribute(attr)
]

def self.prohibited_policy_combination?(policies)
policies.combination(2).any? do |policy1, policy2|
INVALID_POLICY_COMBINATIONS.include?([policy1, policy2].sort_by(&:to_s))
policies.permutation(2).any? do |policy1, policy2|
INVALID_POLICY_COMBINATIONS.include?([policy1, policy2])
end
end
end
8 changes: 0 additions & 8 deletions spec/models/policies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,4 @@
end
end
end

describe "::INVALID_POLICY_COMBINATIONS" do
it "contains subarrays that are sorted alphabetically" do
Policies::INVALID_POLICY_COMBINATIONS.each do |subarray|
expect(subarray).to eq(subarray.sort_by(&:to_s))
end
end
end
end

0 comments on commit 38b7ff1

Please sign in to comment.