Context
From PR #175 review: The implementation correctly added MapSet-specific clauses for remove/2, mapv/2, empty?/1, and count/1 in lib/ptc_runner/lisp/runtime.ex, but these operations lack dedicated tests.
Current State
Implementation (all correct):
remove/2 at runtime.ex:33 - def remove(pred, %MapSet{} = set), do: Enum.reject(set, pred)
mapv/2 at runtime.ex:48 - def mapv(f, %MapSet{} = set), do: Enum.map(set, f)
count/1 at runtime.ex:83 - def count(%MapSet{} = set), do: MapSet.size(set)
empty?/1 at runtime.ex:89 - def empty?(%MapSet{} = set), do: MapSet.size(set) == 0
Existing test coverage: The "collection operations on sets" describe block at test/ptc_runner/lisp/eval_test.exs:1023 tests map, filter, and contains? on sets. The four operations listed above have no dedicated tests.
Implementation
Add tests to test/ptc_runner/lisp/eval_test.exs in the existing "collection operations on sets" describe block (around line 1023):
test "remove on set returns vector" do
{:ok, result, _} = run(~S"(remove odd? #{1 2 3 4})")
assert is_list(result)
assert Enum.sort(result) == [2, 4]
end
test "mapv on set returns vector" do
{:ok, result, _} = run(~S"(mapv inc #{1 2 3})")
assert is_list(result)
assert Enum.sort(result) == [2, 3, 4]
end
test "count returns set size" do
{:ok, result, _} = run(~S"(count #{})")
assert result == 0
{:ok, result, _} = run(~S"(count #{1 2 3})")
assert result == 3
end
test "empty? on sets" do
{:ok, result, _} = run(~S"(empty? #{})")
assert result == true
{:ok, result, _} = run(~S"(empty? #{1})")
assert result == false
end
Note: Use ~S sigil for set literal syntax to avoid escaping issues.
Acceptance Criteria
Benefits
Notes
- This is a nice-to-have improvement, not a blocking issue
- The implementation code is correct and follows obvious patterns
- The MapSet-specific clauses provide better efficiency than falling through to the generic Enum-based implementations
Context
From PR #175 review: The implementation correctly added MapSet-specific clauses for
remove/2,mapv/2,empty?/1, andcount/1inlib/ptc_runner/lisp/runtime.ex, but these operations lack dedicated tests.Current State
Implementation (all correct):
remove/2at runtime.ex:33 -def remove(pred, %MapSet{} = set), do: Enum.reject(set, pred)mapv/2at runtime.ex:48 -def mapv(f, %MapSet{} = set), do: Enum.map(set, f)count/1at runtime.ex:83 -def count(%MapSet{} = set), do: MapSet.size(set)empty?/1at runtime.ex:89 -def empty?(%MapSet{} = set), do: MapSet.size(set) == 0Existing test coverage: The "collection operations on sets" describe block at
test/ptc_runner/lisp/eval_test.exs:1023testsmap,filter, andcontains?on sets. The four operations listed above have no dedicated tests.Implementation
Add tests to
test/ptc_runner/lisp/eval_test.exsin the existing "collection operations on sets" describe block (around line 1023):Note: Use
~Ssigil for set literal syntax to avoid escaping issues.Acceptance Criteria
mix test test/ptc_runner/lisp/eval_test.exsmix formatBenefits
Notes