-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a94929
commit 05e968d
Showing
6 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
return { | ||
groupName = "Stack:Pop", | ||
|
||
cases = { | ||
{ | ||
name = "Pops the value off the stack properly", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 2 | ||
stack[1] = "Hello" | ||
stack[2] = "World" | ||
|
||
stack:Pop( 1 ) | ||
|
||
expect( stack[0] ).to.equal( 1 ) | ||
expect( stack[1] ).to.equal( "Hello" ) | ||
expect( stack[2] ).to.equal( nil ) | ||
|
||
stack:Pop( 1 ) | ||
|
||
expect( stack[0] ).to.equal( 0 ) | ||
expect( stack[1] ).to.equal( nil ) | ||
end | ||
}, | ||
|
||
{ | ||
name = "Errors if we pop too much off the stack", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 0 | ||
|
||
local test = function() | ||
stack:Pop( 1 ) | ||
end | ||
|
||
expect( test ).to.errWith( [[attempted to pop 1 element in stack of length 0]] ) | ||
end | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
return { | ||
groupName = "Stack:PopMulti", | ||
|
||
cases = { | ||
{ | ||
name = "Pops the values off the stack properly", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 2 | ||
stack[1] = "Hello" | ||
stack[2] = "World" | ||
|
||
stack:PopMulti( 2 ) | ||
|
||
expect( stack[0] ).to.equal( 0 ) | ||
expect( stack[1] ).to.equal( nil ) | ||
expect( stack[2] ).to.equal( nil ) | ||
end | ||
}, | ||
|
||
{ | ||
name = "Errors if we pop too much off the stack", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 0 | ||
|
||
local test = function() | ||
stack:PopMulti( 2 ) | ||
end | ||
|
||
expect( test ).to.errWith( [[attempted to pop 2 elements in stack of length 0]] ) | ||
end | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
return { | ||
groupName = "Stack:Push", | ||
|
||
cases = { | ||
{ | ||
name = "Pushes the value onto the stack properly", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 0 | ||
|
||
stack:Push("Hello") | ||
|
||
expect( stack[0] ).to.equal( 1 ) | ||
expect( stack[1] ).to.equal( "Hello" ) | ||
expect( stack[2] ).to.equal( nil ) | ||
|
||
stack:Push("World") | ||
|
||
expect( stack[0] ).to.equal( 2 ) | ||
expect( stack[1] ).to.equal( "Hello" ) | ||
expect( stack[2] ).to.equal( "World" ) | ||
end | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
return { | ||
groupName = "Stack:Size", | ||
|
||
cases = { | ||
{ | ||
name = "Returns the stack size properly", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 10 | ||
|
||
local size = stack:Size() | ||
|
||
expect( size ).to.equal( 10 ) | ||
|
||
stack[0] = -10 | ||
local size = stack:Size() | ||
|
||
expect( size ).to.equal( -10 ) | ||
end | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
return { | ||
groupName = "Stack:Top", | ||
|
||
cases = { | ||
{ | ||
name = "returns the top of the stack properly", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[0] = 2 | ||
stack[1] = "Hello" | ||
stack[2] = "World" | ||
|
||
local top = stack:Top() | ||
|
||
expect( top ).to.equal( "World" ) -- top == stack[ stack[0] ] | ||
|
||
stack[0] = 1 | ||
local top = stack:Top() | ||
|
||
expect( top ).to.equal( "Hello" ) | ||
end | ||
}, | ||
|
||
{ | ||
name = "Return nil if stack length is zero", | ||
func = function() | ||
local stack = util.Stack() | ||
stack[-1] = "Hello" | ||
stack[0] = 0 | ||
stack[1] = "World" | ||
|
||
local top = stack:Top() | ||
|
||
expect( top ).to.equal( nil ) | ||
|
||
stack[0] = -1 -- It checks it with len == 0 and which should allow this | ||
local top = stack:Top() | ||
|
||
expect( top ).to.equal( "Hello" ) | ||
end | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
return { | ||
groupName = "gmod.GetGamemode", | ||
|
||
cases = { | ||
{ | ||
name = "Exists on the gmod table", | ||
func = function() | ||
expect( gmod.GetGamemode ).to.beA( "function" ) | ||
end | ||
}, | ||
|
||
{ | ||
name = "Always returns the valid GAMEMODE table", | ||
func = function() | ||
local gm = gmod.GetGamemode() | ||
|
||
expect( gm ).to.equal( GAMEMODE or GM ) | ||
end | ||
}, | ||
|
||
{ | ||
name = "Always returns the valid GAMEMODE table", | ||
func = function() | ||
GAMEMODE = nil | ||
|
||
local gm = gmod.GetGamemode() | ||
|
||
expect( gm ).to.beA( "table" ) | ||
|
||
GAMEMODE = gm | ||
end | ||
}, | ||
} | ||
} |