1
\$\begingroup\$

I've implemented the following prop. test:

  use ExUnit.Case, async: true
  use Quixir

      ptest [half_width: positive_int(), median: int(min: ^half_width)], trace: true, repeat_for: 500 do
        ptest half_width: positive_int(), median: int(min: ^half_width) do
          result = Pullapi.Numbers.median_range(median, half_width)
          f..l = result

          assert l - f == 2 * half_width
        end
      end

with the function:

  @doc """                                                                                                             
  Returns a range specified by a median and half-width.                                                                

  ## Examples                                                                                                          
      iex> Pullapi.Numbers.median_range(10, 4)                                                                         
      6..14                                                                                                            
  """
  @spec median_range(integer, integer) :: Range.t()
  def median_range(median, half_width) when half_width > 0 and median >= half_width do
    min = median - half_width
    max = median + half_width
    min..max
  end

Have I identified the key invariant and properties that should be tested here? I believe I've implicitly tested that the enumerable is an ordered range by pattern matching the returned data structure.

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.