//-*-c++-*-
#ifndef INCLUDED_TestBehavior_h_
#define INCLUDED_TestBehavior_h_

#include "Behaviors/Leapers.h"
#include "MorseConverter.h"

#include <string>
using namespace std;

unsigned int ind = 0;
MorseList lst = "";

#nodeclass TestBehavior: StateNode

	#shortnodeclass MorseTester : StateNode : DoStart
		string a = "a quick brown fox jumps over the lazy dog 0123456789";
		MorseList b = StringToList(a);
		string c = ListToString(b);
		cout<<"a = \""<<a<<"\""<<endl<<"b = \""<<b<<"\""<<endl<<"c = \""<<c<<"\""<<endl;
		if(a == c)
			cout<<"Conversion successful"<<endl;
		else
			cout<<"Conversion unsuccessful"<<endl;
		lst = b;
		postStateCompletion();
			
	#shortnodeclass HasMoreCharacters : StateNode : DoStart
		if(ind >= lst.size())
			postStateFailure();
		else
			postStateCompletion();
			
	#shortnodeclass GetNextCharInList : StateNode : DoStart
		char ch = lst[ind];
		ind++;
		if(ch == DOT)
			postStateCompletion();
		else if(ch == DASH)
			postStateFailure();
		//Timeout very shortly for STOP
			
	#shortnodeclass ClearList : StateNode : DoStart
		lst.clear();
		postStateCompletion();
			
	#shortnodeclass ReceiveDOT : StateNode : DoStart
		lst += DOT;
		postStateCompletion();
		
	#shortnodeclass ReceiveDASH : StateNode: DoStart
		lst += DASH;
		postStateCompletion();
		
	#shortnodeclass ReceiveSTOP : StateNode : DoStart
		lst += STOP;
		postStateCompletion();
		
	
	#shortnodemethod setup
		#statemachine
			startnode : MorseTester
			hasMore : HasMoreCharacters
			getCodeChar : GetNextCharInList
			
			startnode =C=> hasMore
			hasMore =C=> getCodeChar
			hasMore =F=> Speak($, "done")
			
			getCodeChar =C=> Speak($, "dot") =T(50)=> hasMore
			getCodeChar =F=> Speak($, "dash") =T(50)=> hasMore
			getCodeChar =T(50)=> Speak($, "stop") =T(50)=> hasMore
		#endstatemachine

#endnodeclass

#endif
