Skip to content

Commit

Permalink
Sync strain (exercism#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Apr 3, 2023
1 parent a2b8544 commit 6c056f9
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 74 deletions.
52 changes: 52 additions & 0 deletions exercises/practice/strain/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[26af8c32-ba6a-4eb3-aa0a-ebd8f136e003]
description = "keep on empty list returns empty list"

[f535cb4d-e99b-472a-bd52-9fa0ffccf454]
description = "keeps everything"

[950b8e8e-f628-42a8-85e2-9b30f09cde38]
description = "keeps nothing"

[92694259-6e76-470c-af87-156bdf75018a]
description = "keeps first and last"

[938f7867-bfc7-449e-a21b-7b00cbb56994]
description = "keeps neither first nor last"

[8908e351-4437-4d2b-a0f7-770811e48816]
description = "keeps strings"

[2728036b-102a-4f1e-a3ef-eac6160d876a]
description = "keeps lists"

[ef16beb9-8d84-451a-996a-14e80607fce6]
description = "discard on empty list returns empty list"

[2f42f9bc-8e06-4afe-a222-051b5d8cd12a]
description = "discards everything"

[ca990fdd-08c2-4f95-aa50-e0f5e1d6802b]
description = "discards nothing"

[71595dae-d283-48ca-a52b-45fa96819d2f]
description = "discards first and last"

[ae141f79-f86d-4567-b407-919eaca0f3dd]
description = "discards neither first nor last"

[daf25b36-a59f-4f29-bcfe-302eb4e43609]
description = "discards strings"

[a38d03f9-95ad-4459-80d1-48e937e4acaf]
description = "discards lists"
161 changes: 87 additions & 74 deletions exercises/practice/strain/test/strain_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,105 @@ defmodule StrainTest do

defp is_odd?(n), do: rem(n, 2) == 1
defp is_even?(n), do: rem(n, 2) == 0
defp noop(_), do: true

# @tag :pending
test "empty keep" do
assert Strain.keep([], &noop/1) == []
end
describe "keep" do
# @tag :pending
test "on empty list returns empty list" do
assert Strain.keep([], fn _ -> true end) == []
end

@tag :pending
test "keep everything" do
assert Strain.keep([1, 2, 3], fn e -> e < 10 end) == [1, 2, 3]
end
@tag :pending
test "keep everything" do
assert Strain.keep([1, 3, 5], fn _ -> true end) == [1, 3, 5]
end

@tag :pending
test "keep first and last" do
assert Strain.keep([1, 2, 3], &is_odd?/1) == [1, 3]
end
@tag :pending
test "keep nothing" do
assert Strain.keep([1, 3, 5], fn _ -> false end) == []
end

@tag :pending
test "keep neither first nor last" do
assert Strain.keep([1, 2, 3, 4, 5], &is_even?/1) == [2, 4]
end
@tag :pending
test "keep first and last" do
assert Strain.keep([1, 2, 3], &is_odd?/1) == [1, 3]
end

@tag :pending
test "keep strings" do
words = ~w(apple zebra banana zombies cherimoya zelot)
assert Strain.keep(words, &String.starts_with?(&1, "z")) == ~w(zebra zombies zelot)
end
@tag :pending
test "keep neither first nor last" do
assert Strain.keep([1, 2, 3], &is_even?/1) == [2]
end

@tag :pending
test "keep arrays" do
rows = [
[1, 2, 3],
[5, 5, 5],
[5, 1, 2],
[2, 1, 2],
[1, 5, 2],
[2, 2, 1],
[1, 2, 5]
]

assert Strain.keep(rows, fn row -> 5 in row end) == [
[5, 5, 5],
[5, 1, 2],
[1, 5, 2],
[1, 2, 5]
]
end
@tag :pending
test "keep strings" do
words = ~w(apple zebra banana zombies cherimoya zelot)
assert Strain.keep(words, &String.starts_with?(&1, "z")) == ~w(zebra zombies zelot)
end

@tag :pending
test "empty discard" do
assert Strain.discard([], &noop/1) == []
end
@tag :pending
test "keep lists" do
rows = [
[1, 2, 3],
[5, 5, 5],
[5, 1, 2],
[2, 1, 2],
[1, 5, 2],
[2, 2, 1],
[1, 2, 5]
]

@tag :pending
test "discard nothing" do
assert Strain.discard([1, 2, 3], fn e -> e > 10 end) == [1, 2, 3]
assert Strain.keep(rows, fn row -> 5 in row end) == [
[5, 5, 5],
[5, 1, 2],
[1, 5, 2],
[1, 2, 5]
]
end
end

@tag :pending
test "discard first and last" do
assert Strain.discard([1, 2, 3], &is_odd?/1) == [2]
end
describe "discard" do
@tag :pending
test "on empty list returns empty list" do
assert Strain.discard([], fn _ -> true end) == []
end

@tag :pending
test "discard neither first nor last" do
assert Strain.discard([1, 2, 3, 4, 5], &is_even?/1) == [1, 3, 5]
end
@tag :pending
test "discard everything" do
assert Strain.discard([1, 3, 5], fn _ -> true end) == []
end

@tag :pending
test "discard strings" do
words = ~w(apple zebra banana zombies cherimoya zelot)
assert Strain.discard(words, &String.starts_with?(&1, "z")) == ~w(apple banana cherimoya)
end
@tag :pending
test "discard nothing" do
assert Strain.discard([1, 3, 5], fn _ -> false end) == [1, 3, 5]
end

@tag :pending
test "discard first and last" do
assert Strain.discard([1, 2, 3], &is_odd?/1) == [2]
end

@tag :pending
test "discard neither first nor last" do
assert Strain.discard([1, 2, 3], &is_even?/1) == [1, 3]
end

@tag :pending
test "discard strings" do
words = ~w(apple zebra banana zombies cherimoya zelot)
assert Strain.discard(words, &String.starts_with?(&1, "z")) == ~w(apple banana cherimoya)
end

@tag :pending
test "discard arrays" do
rows = [
[1, 2, 3],
[5, 5, 5],
[5, 1, 2],
[2, 1, 2],
[1, 5, 2],
[2, 2, 1],
[1, 2, 5]
]

@tag :pending
test "discard arrays" do
rows = [
[1, 2, 3],
[5, 5, 5],
[5, 1, 2],
[2, 1, 2],
[1, 5, 2],
[2, 2, 1],
[1, 2, 5]
]

assert Strain.discard(rows, fn row -> 5 in row end) == [[1, 2, 3], [2, 1, 2], [2, 2, 1]]
assert Strain.discard(rows, fn row -> 5 in row end) == [[1, 2, 3], [2, 1, 2], [2, 2, 1]]
end
end
end

0 comments on commit 6c056f9

Please sign in to comment.