require "spec" require "../src/list.cr" describe "DoubleLinkedList" do it "add and remove values" do list = DoubleLinkedList(Int32).new list.push 1 list.to_s.should eq "[ 1 ]" list.push 2 list.to_s.should eq "[ 1, 2 ]" list << 3 << 4 list.to_s.should eq "[ 1, 2, 3, 4 ]" list.insert_at(8, 1) list.to_s.should eq "[ 1, 8, 2, 3, 4 ]" list.insert_at(0, 0) list.to_s.should eq "[ 0, 1, 8, 2, 3, 4 ]" list.insert_at(5, 6) list.to_s.should eq "[ 0, 1, 8, 2, 3, 4, 5 ]" v = list.pop v.value.should eq 5 list.to_s.should eq "[ 0, 1, 8, 2, 3, 4 ]" v = list.pop v.value.should eq 4 list.to_s.should eq "[ 0, 1, 8, 2, 3 ]" v = list.pop v.value.should eq 3 list.to_s.should eq "[ 0, 1, 8, 2 ]" v = list.pop v.value.should eq 2 list.to_s.should eq "[ 0, 1, 8 ]" v = list.pop v.value.should eq 8 list.to_s.should eq "[ 0, 1 ]" v = list.pop v.value.should eq 1 list.to_s.should eq "[ 0 ]" v = list.pop v.value.should eq 0 list.to_s.should eq "[ ]" expect_raises DoubleLinkedList::OutOfBounds do list.pop end list.size.should eq 0 end end