-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from girorme/feat/multi-ocurrences
chore: add multi ocurrences
- Loading branch information
Showing
5 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Binoculo.Refiner do | ||
def find_occurrences_in_responses(patterns, responses) when is_list(patterns) do | ||
Enum.filter(responses, fn %{response: response} -> | ||
Enum.all?(patterns, fn pattern -> String.contains?(response, pattern) end) | ||
end) | ||
end | ||
|
||
def find_occurrences_in_responses(pattern, responses) do | ||
Enum.filter(responses, fn %{response: response} -> | ||
String.contains?(response, pattern) | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule RefinerTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Binoculo.Refiner | ||
|
||
@responses [ | ||
%{response: "hello and world"}, | ||
%{response: "world"}, | ||
%{response: "test"}, | ||
%{response: "test xoo"} | ||
] | ||
|
||
describe "Refiner.find_occurrences_in_responses/2" do | ||
test "should find occurrences in responses with single pattern" do | ||
assert [%{response: "test"}, %{response: "test xoo"}] == | ||
Refiner.find_occurrences_in_responses("test", @responses) | ||
end | ||
|
||
test "should find occurrences in responses with multiple patterns (AND)" do | ||
assert [%{response: "hello and world"}] == | ||
Refiner.find_occurrences_in_responses(["hello", "world"], @responses) | ||
|
||
assert [%{response: "test xoo"}] == | ||
Refiner.find_occurrences_in_responses(["xoo"], @responses) | ||
end | ||
end | ||
end |