Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed property.coffee and passed state_machine tests
- Loading branch information
Showing
3 changed files
with
40 additions
and
42 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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 | ||
|
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 |
---|---|---|
@@ -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() | ||
|