Add plan builder and tests

This commit is contained in:
Andrew Miner
2015-09-19 09:31:14 -07:00
parent f6b71c9464
commit 6ea97ac3aa
9 changed files with 198 additions and 10 deletions
+21
View File
@@ -31,6 +31,27 @@ MOD_VERSION_FILE =
item: Cobblestone
item: Copper Block
recipe:
input: Copper Ingot
pattern: 000 000 000
tools: Crafting Table
item: Copper Ingot
recipe:
input: Copper Ore, Coal
pattern: .0. ... .1.
tools: Furnace
recipe:
input: Copper Ore, Charcoal
pattern: .0. ... .1.
tools: Furnace
recipe:
input: Copper Block
pattern: ... .0. ...
item: Copper Ore
item: Furnace
recipe:
input: Cobblestone
+7 -5
View File
@@ -5,8 +5,8 @@ Copyright (c) 2015 by Redwood Labs
All rights reserved.
###
fixtures = require './fixtures'
ItemSlug = require '../../src/coffee/models/item_slug'
fixtures = require './fixtures'
ItemSlug = require '../../src/coffee/models/item_slug'
########################################################################################################################
@@ -61,9 +61,11 @@ describe 'GraphBuilder.coffee', ->
it 'an item with multiple inputs', ->
runSingleItemTreeBuildingTest 'test__lever', 8, 9
it 'can make a tree for an item with multiple recipes', ->
it 'an item with multiple recipes', ->
runSingleItemTreeBuildingTest 'test__iron_ingot', 6, 11
it 'can make a tree for an item with multiple inputs and multiple recipes', ->
it 'an item with multiple inputs and multiple recipes', ->
runSingleItemTreeBuildingTest 'test__iron_sword', 8, 18
logger.debug builder.toString()
it 'an item with one recursive recipe', ->
runSingleItemTreeBuildingTest 'test__copper_ingot', 10, 24
+38
View File
@@ -0,0 +1,38 @@
###
Crafting Guide - plan_builder.test.coffee
Copyright (c) 2015 by Redwood Labs
All rights reserved.
###
fixtures = require './fixtures'
PlanBuilder = require '../../src/coffee/models/crafting/plan_builder'
########################################################################################################################
describe 'plan_builder.coffee', ->
printPlan = (plan)->
return ((s.slug.replace(/^.*>.*>/, '') for s in plan)).join ' > '
it 'generates no plans for a gatherable item', ->
builder = new PlanBuilder fixtures.makeTree 'test__oak_wood'
plans = builder.producePlans 100
plans.length.should.equal 0
builder.complete.should.be.true
it 'can find a multi-step plan', ->
builder = new PlanBuilder fixtures.makeTree 'test__lever'
plans = builder.producePlans 100
printPlan(plans[0]).should.equal '4 test__oak_planks > 4 test__stick > test__lever'
plans.length.should.equal 1
builder.complete.should.be.true
it 'can find multiple plans', ->
builder = new PlanBuilder fixtures.makeTree 'test__iron_ingot'
plans = builder.producePlans 100
printPlan(plans[0]).should.equal 'test__charcoal > test__iron_ingot'
printPlan(plans[1]).should.equal 'test__iron_ingot'