#include "testbt.hpp"

//#############################################################################
// Test Class -- Emitter
//

Logical
	Emitter::TestClass(Mech &mech)
{
	Emitter			*emitter;
	PowerBar			*power_Bar;
	Condenser		*condenser;
	Generator		*generator;
	const Scalar	time_Slice = 0.05f;

#if 0
	Tell("Testing Emitter .................\n");
	emitter 		= (Emitter*) mech.GetSubsystem(LaserSubsystemID);
	power_Bar 	= (PowerBar*) mech.GetSubsystem(PowerBarSubsystemID);
	condenser 	= (Condenser*) mech.GetSubsystem(CondenserSubsystemID);
	generator = (Generator*) mech.GetSubsystem(GeneratorSubsystemID);

	// Test Initial Values as given in the resource file
	Test(Close_Enough(emitter->dischargeVoltage, 3.8f));
	Test(Close_Enough(emitter->outputVoltage, 0.0f));
	Test(Close_Enough(emitter->currentTemperature, 300.0f));

	// Run the simulation a few times
	#if defined (TEST_DEBUG)
		Dump(emitter->currentLevel);
		Dump(emitter->outputVoltage);
		Dump(emitter->currentTemperature);
	#endif
	Test(Close_Enough(emitter->currentLevel,0.0f));
	Test(Close_Enough(emitter->outputVoltage,0.0f));

	// Run the Simulation Loops
	MemoryStream stream(NULL, 0);
	condenser->HeatSimulation(time_Slice, stream);
	power_Bar->PoweredSimulation(time_Slice, stream);
	emitter->EmitterSimulation(time_Slice, stream);
	generator->GeneratorSimulation(time_Slice, stream);

	#if defined (TEST_DEBUG)
		Dump(emitter->currentLevel);
		Dump(emitter->outputVoltage);
		Dump(emitter->currentTemperature);
	#endif

	Test(Close_Enough(emitter->outputVoltage,0.00f,0.001f));
	Test(Close_Enough(emitter->currentTemperature, 300.00f,0.001f));


	emitter->outputVoltage = 5.0f;		//Give it enough to fire!
	#if defined (TEST_DEBUG)
	  Dump(emitter->outputVoltage);
	#endif

	emitter->AcceptHeat(35.0f);
	// Run the Simulation Loops
	condenser->HeatSimulation(time_Slice, stream);
	power_Bar->PoweredSimulation(time_Slice, stream);
	emitter->EmitterSimulation(time_Slice, stream);

	#if defined (TEST_DEBUG)
		Dump(emitter->currentLevel);
		Dump(emitter->outputVoltage);
		Dump(emitter->currentTemperature);
	#endif
	Test(Close_Enough(emitter->currentTemperature, 301.75f, 0.001f));

	// Run the Simulation Loops
	condenser->HeatSimulation(time_Slice, stream);
	power_Bar->PoweredSimulation(time_Slice, stream);
	emitter->EmitterSimulation(time_Slice, stream);

	#if defined( TEST_DEBUG)
		Dump(emitter->currentLevel);
		Dump(emitter->outputVoltage);
		Dump(emitter->currentTemperature);
	#endif
	Test(Close_Enough(emitter->currentTemperature, 301.597f, 0.001f));

	// Return Power Bar and Laser to Initial States!
	condenser->ResetToInitialState();
	power_Bar->ResetToInitialState();
	emitter->ResetToInitialState();
	generator->ResetToInitialState();
#endif
	return True;
}
//########################################################################
// resetToInitialState Emitter
//
void Emitter::ResetToInitialState()
{
	SetSimulationState(Loaded);
	PoweredSubsystem::ResetToInitialState();

}

