Skip to content
Snippets Groups Projects
Commit e10fed81 authored by Travis Savo's avatar Travis Savo
Browse files

Adding more bodypart tests

parent e4bb6f4f
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
Loading
@@ -20,30 +20,32 @@ part.init = (@name, @bones, @coverable, @removable, @critical, @parts = {})->
 
part.findPart = (name)->
return this if name is @name or @name.indexOf(name) is 0 or name.test?(@name)
_ = require("./node_modules/underscore")
_ = require("underscore")
_(@parts).find (part)->
part.findPart(name)
 
part.coverageMap = (map = {})->
return map if not @coverable
_ = require("underscore")
map[@name] = this
@parts.forEach (part)->
_(@parts).map (part)->
part.coverageMap map
map
 
part.contentsMap = (map = {})->
if(this.contents?.length)
map[this] = this.contents
@parts.forEach (part)->
_ = require("underscore")
_(@parts).map (part)->
part.contentsMap(map)
map
 
part.resolveAllContents = ->
_ = require("./node_modules/underscore")
_ = require("underscore")
_(this.contentsMap()).chain().pluck().flatten().value()
 
part.randomPart = ->
return this if not @parts.length
return this if not Object.keys(@parts).length
keys = Object.keys(@parts)
@parts[keys[keys.length * Math.random() << 0]]
 
Loading
Loading
Loading
Loading
@@ -5,7 +5,54 @@ require("../src/bodyPart")
 
describe "BodyPart", ->
it "should be constructable", ->
bodyPart = new global.$game.classes.BodyPart("Test body part")
bodyPart = new global.$game.classes.BodyPart("Test body part", [], true, true, true)
bodyPart.condition.should.be.empty
bodyPart.contents.should.be.empty
 
it "should compute it's own coverage map", ->
bodyPart = new global.$game.classes.BodyPart "Test body part", [], true, true, true,
testPart1: testPart1 = new global.$game.classes.BodyPart "Test body part 1", [], true, true, true
testPart2: testPart2 = new global.$game.classes.BodyPart "Test body part 2", [], true, true, true
bodyPart.coverageMap()
it "should be able to find a part", ->
testPart1 = testPart2 = undefined
bodyPart = new global.$game.classes.BodyPart "Test body part", [], true, true, true,
testPart1: testPart1 = new global.$game.classes.BodyPart "Test body part 1", [], true, true, true
testPart2: testPart2 = new global.$game.classes.BodyPart "Test body part 2", [], true, true, true
bodyPart.findPart("Test body part 1").should.equal testPart1
bodyPart.findPart("Test body part 2").should.equal testPart2
it "should return a map of it's contents", ->
testPart1 = testPart2 = undefined
bodyPart = new global.$game.classes.BodyPart "Test body part", [], true, true, true,
testPart1: testPart1 = new global.$game.classes.BodyPart "Test body part 1", [], true, true, true
testPart2: testPart2 = new global.$game.classes.BodyPart "Test body part 2", [], true, true, true
inventory1 = {}
inventory2 = {}
testPart1.contents.push inventory1
testPart2.contents.push inventory2
bodyPart.contentsMap().should.not.be.undefined
it "should resolve all it's contents", ->
testPart1 = testPart2 = undefined
bodyPart = new global.$game.classes.BodyPart "Test body part", [], true, true, true,
testPart1: testPart1 = new global.$game.classes.BodyPart "Test body part 1", [], true, true, true
testPart2: testPart2 = new global.$game.classes.BodyPart "Test body part 2", [], true, true, true
inventory1 = {}
inventory2 = {}
testPart1.contents.push inventory1
testPart2.contents.push inventory2
bodyPart.resolveAllContents().should.not.be.undefined
it "should resolve all it's contents", ->
testPart1 = testPart2 = undefined
bodyPart = new global.$game.classes.BodyPart "Test body part", [], true, true, true,
testPart1: testPart1 = new global.$game.classes.BodyPart "Test body part 1", [], true, true, true
testPart2: testPart2 = new global.$game.classes.BodyPart "Test body part 2", [], true, true, true
bodyPart.randomPart().should.not.be.undefined
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment