Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Added a few test cases. One of them fails, it looks like a bug in fla…
Browse files Browse the repository at this point in the history
…tten.
  • Loading branch information
DrDub committed Dec 5, 2012
1 parent 237d8e1 commit 605cf92
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions spec/arrays_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local _ = require("lib/underscore")
local _ = require("underscore")

describe("#first", function()
local numbers = {1,2,3}
Expand Down Expand Up @@ -73,6 +73,11 @@ describe("#flatten", function()
it("flatten shallowly", function()
assert.same(_.flatten(list, true), {1,2,3,{{4}}})
end)

it("flatten empty", function()
list[2] = {}
assert.same(_.flatten(list), {1,3,4})
end)
end)

describe("#without", function()
Expand All @@ -94,6 +99,10 @@ describe("#uniq", function()
assert.same(_.uniq(list), {1,2,3,4})
end)

it("can find the uniq values of an empty array", function()
assert.same(_.uniq({}), {})
end)

it("can find the uniq values of a sorted array", function()
local list = {1, 1, 1, 2, 2, 3, 4}
assert.same(_.uniq(list, true), {1,2,3,4})
Expand All @@ -118,6 +127,17 @@ describe("#intersection", function()
local b = {"moe","groucho"}
assert.same(_.intersection(a,b), {"moe"})
end)
it("intersection with empty is empty", function()
local a = {"moe","curly","larry"}
local b = {"moe","groucho"}
assert.same(_.intersection(a,{}), {})
assert.same(_.intersection(b,{}), {})
end)
it("intersection with inclusion is smaller array", function()
local a = {"moe","curly","larry"}
local b = {"moe","curly"}
assert.same(_.intersection(a,b), b)
end)
end)

describe("#union", function()
Expand Down Expand Up @@ -296,7 +316,18 @@ describe("#sort", function()
end)

describe("#splice", function()

it("can remove on element", function()
local list = {1,2,3,4}
local removed = _.splice(list,2,1)
assert.same(list, {1,3,4})
assert.same(removed, {2})
end)
it("can replace sub array", function()
local list = {1,2,3,4}
local removed = _.splice(list,2,1,8,9)
assert.same(list, {1,8,9,3,4})
assert.same(removed, {2})
end)
end)

describe("#unshift", function()
Expand Down Expand Up @@ -347,6 +378,10 @@ describe("#join", function()
assert.same(_.join({"moe", 30, "curly", 20}, "\t"), "moe\t30\tcurly\t20")
assert.same(_.join({"a", "b", "c"}, "..."), "a...b...c")
end)

it("joining single element shouldn't change", function()
assert.same(_.join({"moe"}, "dontprintit"), "moe")
end)
end)

describe("#slice", function()
Expand Down

0 comments on commit 605cf92

Please sign in to comment.