Skip to content

Commit

Permalink
removed property.coffee and passed state_machine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Mar 18, 2012
1 parent 556c96b commit 4091546
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
1 change: 0 additions & 1 deletion lib/alpha_simprini/core/property.coffee

This file was deleted.

35 changes: 17 additions & 18 deletions lib/alpha_simprini/core/state_machine.coffee
@@ -1,21 +1,20 @@
# AS = require("alpha_simprini")
# _ = require "underscore"
AS = require("alpha_simprini")
_ = require "underscore"

# # Example:
# #
# # class StopLight
# # AS.StateMachine.extends(this)
# # @event "stop_soon"
# # @event "stop_now"
# # @event ""
# AS.StateMachine = new AS.Mixin
# instanceMethods:
# transition_state: (options) ->
# if @state is options.from
# @["exit_#{@state}"]?(options) if @state # default state comes from nowhere
# @state = options.to
# @["enter_#{options.to}"]?(options)
# Example:
#
# class StopLight
# AS.StateMachine.extends(this)
# @event "stop_soon"
# @event "stop_now"
# @event ""
AS.StateMachine = AS.Module.extend ({def}) ->
def transition_state: (options) ->
if @state is options.from
@["exit_#{@state}"]?(options) if @state # default state comes from nowhere
@state = options.to
@["enter_#{options.to}"]?(options)

# default_state: (state) ->
# @transition_state from:undefined, to:state
def default_state: (state) ->
@transition_state from:undefined, to:state

46 changes: 23 additions & 23 deletions test/core/state_machine.coffee
@@ -1,33 +1,33 @@
# {AS, _, sinon, coreSetUp} = require require("path").resolve("./test/helper")
# exports.setUp = coreSetUp
{AS, NS, _, sinon, coreSetUp} = require require("path").resolve("./test/helper")
exports.setUp = coreSetUp


# class Car
# AS.StateMachine.extends(this)
Car = NS.Car = AS.Object.extend ({include, def}) ->
include AS.StateMachine

# constructor: -> @default_state "off"
def initialize: -> @default_state "off"

# exports.StateMachine =
# hasDefaultState: (test) ->
# test.equal (new Car).state, "off"
# test.done()
exports.StateMachine =
hasDefaultState: (test) ->
test.equal Car.new().state, "off"
test.done()

# "will not transition from the wrong state": (test) ->
# car = new Car
# car.transition_state from: "wrongstate", to: "on"
# test.equal car.state, "off"
# test.done()
"will not transition from the wrong state": (test) ->
car = Car.new()
car.transition_state from: "wrongstate", to: "on"
test.equal car.state, "off"
test.done()

# "calls transition method with options for a valid transition": (test) ->
# test.expect 2
# car = new Car
# car.exit_off = (options) ->
# test.deepEqual from: "off", to: "on", options
"calls transition method with options for a valid transition": (test) ->
test.expect 2
car = Car.new()
car.exit_off = (options) ->
test.deepEqual from: "off", to: "on", options

# car.enter_on = (options) ->
# test.deepEqual from: "off", to: "on", options
car.enter_on = (options) ->
test.deepEqual from: "off", to: "on", options

# car.transition_state from: "off", to: "on"
car.transition_state from: "off", to: "on"

# test.done()
test.done()

0 comments on commit 4091546

Please sign in to comment.