Skip to content

Commit

Permalink
Remove duplicated sort related specs (#10208)
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored Feb 2, 2021
1 parent 63a3c51 commit e827b42
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 130 deletions.
94 changes: 0 additions & 94 deletions spec/std/array_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@ require "spec"

private alias RecursiveArray = Array(RecursiveArray)

private class BadSortingClass
include Comparable(self)

def <=>(other)
1
end
end

private class Spaceship
getter value : Float64

def initialize(@value : Float64, @return_nil = false)
end

def <=>(other : Spaceship)
return nil if @return_nil

value <=> other.value
end
end

describe "Array" do
describe "new" do
it "creates with default value" do
Expand Down Expand Up @@ -1270,42 +1249,6 @@ describe "Array" do
b.should eq(["a", "foo", "hello"])
a.should_not eq(b)
end

it "doesn't crash on special situations" do
[1, 2, 3].sort { 1 }
Array.new(10) { BadSortingClass.new }.sort
end

it "can sort just by using <=> (#6608)" do
spaceships = [
Spaceship.new(2),
Spaceship.new(0),
Spaceship.new(1),
Spaceship.new(3),
]

sorted = spaceships.sort
4.times do |i|
sorted[i].value.should eq(i)
end
end

it "raises if <=> returns nil" do
spaceships = [
Spaceship.new(2, return_nil: true),
Spaceship.new(0, return_nil: true),
]

expect_raises(ArgumentError) do
spaceships.sort
end
end

it "raises if sort block returns nil" do
expect_raises(ArgumentError) do
[1, 2].sort { nil }
end
end
end

describe "sort!" do
Expand All @@ -1320,43 +1263,6 @@ describe "Array" do
a.sort! { |x, y| x.size <=> y.size }
a.should eq(["a", "foo", "hello"])
end

it "sorts with invalid block (#4379)" do
a = [1] * 17
b = a.sort { -1 }
a.should eq(b)
end

it "can sort! just by using <=> (#6608)" do
spaceships = [
Spaceship.new(2),
Spaceship.new(0),
Spaceship.new(1),
Spaceship.new(3),
]

spaceships.sort!
4.times do |i|
spaceships[i].value.should eq(i)
end
end

it "raises if <=> returns nil" do
spaceships = [
Spaceship.new(2, return_nil: true),
Spaceship.new(0, return_nil: true),
]

expect_raises(ArgumentError) do
spaceships.sort!
end
end

it "raises if sort! block returns nil" do
expect_raises(ArgumentError) do
[1, 2].sort! { nil }
end
end
end

describe "sort_by" do
Expand Down
36 changes: 0 additions & 36 deletions spec/std/slice_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -542,42 +542,6 @@ describe "Slice" do
b.to_a.should eq(["a", "foo", "hello"])
a.should_not eq(b)
end

it "doesn't crash on special situations" do
Slice[1, 2, 3].sort { 1 }
Slice.[BadSortingClass.new].sort
end

it "can sort just by using <=> (#6608)" do
spaceships = [
Spaceship.new(2),
Spaceship.new(0),
Spaceship.new(1),
Spaceship.new(3),
]

sorted = spaceships.sort
4.times do |i|
sorted[i].value.should eq(i)
end
end

it "raises if <=> returns nil" do
spaceships = [
Spaceship.new(2, return_nil: true),
Spaceship.new(0, return_nil: true),
]

expect_raises(ArgumentError) do
spaceships.sort
end
end

it "raises if sort block returns nil" do
expect_raises(ArgumentError) do
[1, 2].sort { nil }
end
end
end

describe "sort!" do
Expand Down

0 comments on commit e827b42

Please sign in to comment.