Permalink
Browse files

made fsm.addTransition and fsm.addEpsilonTransition throw if the toSt…

…ates argument is not an array
  • Loading branch information...
1 parent 8cf94f9 commit 4b50386868aa1a56515a86340d82829acca92b32 @ibudiselic ibudiselic committed May 25, 2012
Showing with 13 additions and 0 deletions.
  1. +3 −0 noam.js
  2. +10 −0 test/test-fsm.spec.js
View
@@ -232,6 +232,9 @@ noam.fsm.setInitialState = function(fsm, stateObj) {
// Common implementation for addTransition and addEpsilonTransition.
noam.fsm._addTransition = function(fsm, fromState, toStates, transitionSymbol) {
+ if (!Array.isArray(toStates)) {
+ throw new Error("The toStates argument must be an array");
+ }
if (!noam.util.contains(fsm.states, fromState) ||
!noam.util.containsAll(fsm.states, toStates)) {
throw new Error("One of the specified objects is not a state of the FSM");
View
@@ -191,6 +191,11 @@ describe("FSM", function() {
expect(function() { noamFsm.addTransition(automaton, state1, [state2], noamFsm.epsilonSymbol); }).
toThrow(new Error("The specified object is not an alphabet symbol of the FSM"));
});
+
+ it("throws an Error if the toStates argument is not an array", function() {
+ expect(function() { noamFsm.addTransition(automaton, state1, state2, symbolObj); }).
+ toThrow(new Error("The toStates argument must be an array"));
+ });
});
describe("addEpsilonTransition", function() {
@@ -233,6 +238,11 @@ describe("FSM", function() {
expect(function() { noamFsm.addEpsilonTransition(automaton, state1, [state2, "zaz"]); }).
toThrow(new Error("One of the specified objects is not a state of the FSM"));
});
+
+ it("throws an Error if the toStates argument is not an array", function() {
+ expect(function() { noamFsm.addEpsilonTransition(automaton, state1, state2); }).
+ toThrow(new Error("The toStates argument must be an array"));
+ });
});
});

0 comments on commit 4b50386

Please sign in to comment.