Skip to content

Commit

Permalink
Clean up slice tests, now that workflows work correctly again
Browse files Browse the repository at this point in the history
  • Loading branch information
Qqwy committed Sep 6, 2021
1 parent dec2184 commit 4082d12
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/arrays.ex
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ contents = quote [location: :keep] do
##{@current_default_array}<["this", "will"]>
"""
# TODO
@spec new(Enum.t(), keyword) :: array()
def new(enumerable, options) do
size = Keyword.get(options, :size, nil)
Expand Down
20 changes: 0 additions & 20 deletions test/arrays_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,4 @@ defmodule ArraysTest do

doctest Arrays

describe "Arrays.slice" do

test "raises ArgumentError on range with non-1 step" do
arr = Arrays.new([1, 2,3])
if :erlang.system_info(:otp_release) == '24' do
assert_raise(ArgumentError, fn ->
Arrays.slice(arr, %{__struct__: Range, first: 1, last: 10, step: 2})
end)

assert_raise(ArgumentError, fn ->
Arrays.slice(arr, %{__struct__: Range, first: 10, last: 1, step: -3})
end)
end
end

test "Works correctly on (old) ranges without a step " do
arr = Arrays.new([1, 2,3])
assert Arrays.new([1, 2, 3]) == Arrays.slice(arr, %{__struct__: Range, first: 0, last: 2})
end
end
end
19 changes: 19 additions & 0 deletions test/implementations/erlang_array_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,23 @@ defmodule Arrays.Implementations.ErlangArrayTest do

alias Arrays.Implementations.ErlangArray
doctest Arrays.Implementations.ErlangArray

describe "Arrays.slice" do

test "raises ArgumentError on range with non-1 step" do
arr = Arrays.new([1, 2,3], implementation: ErlangArray)
assert_raise(ArgumentError, fn ->
Arrays.slice(arr, %{__struct__: Range, first: 1, last: 10, step: 2})
end)

assert_raise(ArgumentError, fn ->
Arrays.slice(arr, %{__struct__: Range, first: 10, last: 1, step: -3})
end)
end
end

test "Works correctly on (old) ranges without a step " do
arr = Arrays.new([1, 2,3], implementation: ErlangArray)
assert Arrays.new([1, 2, 3], implementation: ErlangArray) == Arrays.slice(arr, %{__struct__: Range, first: 0, last: 2})
end
end
22 changes: 21 additions & 1 deletion test/implementations/map_array_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
defmodule Arrays.Implementations.MapArrayTest do
use ExUnit.Case, async: true

# alias Arrays.Implementations.MapArray
alias Arrays.Implementations.MapArray
doctest Arrays.Implementations.MapArray


describe "Arrays.slice" do

test "raises ArgumentError on range with non-1 step" do
arr = Arrays.new([1, 2,3], implementation: MapArray)
assert_raise(ArgumentError, fn ->
Arrays.slice(arr, %{__struct__: Range, first: 1, last: 10, step: 2})
end)

assert_raise(ArgumentError, fn ->
Arrays.slice(arr, %{__struct__: Range, first: 10, last: 1, step: -3})
end)
end
end

test "Works correctly on (old) ranges without a step " do
arr = Arrays.new([1, 2,3], implementation: MapArray)
assert Arrays.new([1, 2, 3]) == Arrays.slice(arr, %{__struct__: Range, first: 0, last: 2})
end
end

0 comments on commit 4082d12

Please sign in to comment.