Skip to content

[From PR #175] Add test coverage for remove, mapv, empty?, and count on sets #176

@andreasronge

Description

@andreasronge

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

  • All 4 tests added to "collection operations on sets" describe block
  • Tests use strong assertions (specific values, not just shape matching)
  • Tests pass: mix test test/ptc_runner/lisp/eval_test.exs
  • Code formatted: mix format

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    claude-approvedMaintainer-approved for Claude automationfrom-pr-reviewIssue created from PR review feedbackready-for-implementationIssue is approved and ready to implementtech-debtTechnical debt or refactoring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions