Skip to content
mager-bench1.3

GPT-5.6 Sol × elixir-test

9.3

ExUnit describe blocks + assert_raise + unicode handling

correctness 10.0quality 9.0documentation 9.012699ms
$ cat elixir-test.prompt — what the model was asked
Write an ExUnit test module for the following Elixir function:

```elixir
defmodule StringUtils do
  @doc """
  Truncates a string to at most `max_len` characters.
  If truncated, appends `suffix` (default: "...").
  Returns the original string if it is already within `max_len`.
  Raises ArgumentError if max_len is negative.
  """
  @spec truncate(String.t(), non_neg_integer(), String.t()) :: String.t()
  def truncate(str, max_len, suffix \\ "...")
end
```

Requirements:
- Module name: `StringUtilsTest`, `use ExUnit.Case`
- Use `describe` blocks to group related cases
- At least 2 `describe` blocks: one for happy path, one for edge/error cases
- At least 8 test cases total covering: string shorter than limit, exact length, longer string (suffix appended), empty string, custom suffix, max_len of 0, negative max_len (should raise), unicode string
- Use `assert`, `assert_raise`, and pattern matching appropriately
- Add at least one doctest-style `## Examples` in a module comment showing usage

run 1 of 1

9.3
correctness 10.0quality 9.0documentation 9.012699ms

# judge: The module comprehensively covers every required case with correct Unicode behavior, idiomatic assertions and grouping, though the describe labels say truncate/3 while most tests exercise the default-argument truncate/2 form.

$ cat codex-cli/gpt-5.6-sol.elixir-test.r1.response
defmodule StringUtilsTest do
  use ExUnit.Case

  @moduledoc """
  Tests for `StringUtils.truncate/3`.

  ## Examples

      iex> StringUtils.truncate("hello", 3)
      "hel..."
  """

  describe "truncate/3 happy path" do
    test "returns a string shorter than the limit unchanged" do
      assert StringUtils.truncate("hello", 10) == "hello"
    end

    test "returns a string at the exact limit unchanged" do
      assert StringUtils.truncate("hello", 5) == "hello"
    end

    test "appends the default suffix when truncating" do
      assert StringUtils.truncate("hello world", 5) == "hello..."
    end

    test "supports a custom suffix" do
      assert StringUtils.truncate("hello world", 5, "…") == "hello…"
    end

    test "counts Unicode characters rather than bytes" do
      result = StringUtils.truncate("héllo 🌍", 5)

      assert "héllo..." = result
    end
  end

  describe "truncate/3 edge and error cases" do
    test "returns an empty string unchanged" do
      assert StringUtils.truncate("", 5) == ""
    end

    test "truncates a non-empty string when max_len is zero" do
      assert StringUtils.truncate("hello", 0) == "..."
    end

    test "returns an empty string when max_len is zero" do
      assert StringUtils.truncate("", 0) == ""
    end

    test "raises ArgumentError for a negative max_len" do
      assert_raise ArgumentError, fn ->
        StringUtils.truncate("hello", -1)
      end
    end
  end
end