void RequestParser::Test() {
  assert(ExtractMethod("GET / HTTP1.1") == GET);
  assert(ExtractMethod("HEAD / HTTP1.1") == HEAD);
  assert(ExtractMethod("POST / HTTP1.1") == POST);
  assert(ExtractMethod("Error / HTTP1.1") == UNKNOWN);

  assert(ExtractTarget("GET / HTTP1.1") == "");
  assert(ExtractTarget("GET // HTTP1.1") == "");
  assert(ExtractTarget("GET /// HTTP1.1") == "");
  assert(ExtractTarget("GET /dir/file.txt HTTP1.1") == "dir/file.txt");
  assert(ExtractTarget("GET /dir/file.txt?params HTTP1.1") == "dir/file.txt");
  assert(ExtractTarget("GET /?params HTTP1.1") == "");
  assert(ExtractTarget("GET //?params HTTP1.1") == "");

  assert(Flatten(ExtractQueryParams("GET / HTTP1.1")) == "");

  assert(Flatten(ExtractQueryParams("GET // HTTP1.1")) == "");
  assert(Flatten(ExtractQueryParams("GET /// HTTP1.1")) == "");
  assert(Flatten(ExtractQueryParams("GET /dir/file.txt HTTP1.1")) == "");
  assert(Flatten(ExtractQueryParams("GET /dir/file.txt? HTTP1.1")) == "");
  assert(Flatten(ExtractQueryParams("GET /dir/file.txt?params HTTP1.1")) == "params=''");
  assert(Flatten(ExtractQueryParams("GET /dir/file.txt?param1&param2&param3 HTTP1.1")) == "param1='' param2='' param3=''");
  assert(Flatten(ExtractQueryParams("GET /dir/file.txt?param1=val1&param2=val2&param3=val3 HTTP1.1")) == "param1='val1' param2='val2' param3='val3'");
  assert(Flatten(ExtractQueryParams("GET /?params HTTP1.1")) == "params=''");
  assert(Flatten(ExtractQueryParams("GET /? HTTP1.1")) == "");
  assert(Flatten(ExtractQueryParams("GET //?params HTTP1.1")) == "params=''");

  assert(TestRange(true, "Range: bytes=0-1024", 0, 1024));
  assert(TestRange(false, "Range: time=0-1024", 0, 0));
  assert(TestRange(true, "Range: bytes=0-", 0, -1));
  assert(TestRange(true, "Range: bytes=1024-", 1024, -1));
  assert(TestRange(true, "Range: bytes=232128512-", 232128512, -1));
}
示例#2
0
文件: main.c 项目: QAndot/dyncall
int main(int argc, char* argv[] )
{
  int from = 1;
  int to = CONFIG_NSIGS;
  int ncases;

  int i;
  int pos;
  int number;
  int totalResult;

  dcTest_initPlatform();

  InitEnv();
  appname = argv[0];

  pos = 0;
  for(i = 1 ; i < argc ; ++i ) {

    if ( argv[i][0] == '-' ) {
      switch(argv[i][1]) {
        case 'v': OptionVerbose = 1; continue;
        case 'h': PrintUsage(appname); return 0;
        default: Error("invalid option: %s", argv[i]);
      }      
    }

    number = atoi(argv[i]);
    switch(pos) {
      case 0: to   = from = number; ++pos; break;
      case 1: to   = number; break;
      default: Error("too many arguments%s", "");
    }
  }

  assert(from > 0);
  assert(to   <= CONFIG_NSIGS);
  assert(from <= to);

  ncases = (to - from) + 1;

  PrintHeader();
  TestRange(from, to);
  totalResult = (totalErrorCodes[1] == ncases) ? 1 : 0; 
  PrintTotalResult(totalResult);

  dcTest_deInitPlatform();

  return 0;
}
示例#3
0
	static TestRange CreateDistribution(double value, double tolerance)
	{
		return TestRange(value-tolerance, value+tolerance);
	}
static void OnOK(HWND hDlg)
{
	BOOL ret = FALSE;
	TCHAR buf[23];
	int temp=m_newCheat->size;
	S9xCheatDataSize tmp = S9X_8_BITS;
	ZeroMemory(m_newCheat, sizeof(struct SCheat));
	m_newCheat->size=temp;
	GetDlgItemText(hDlg, IDC_NC_ADDRESS, buf, 7);
	ScanAddress(buf, m_newCheat->address);

	if(temp==1)
		tmp=S9X_8_BITS;
	if(temp==2)
		tmp=S9X_16_BITS;
	if(temp==3)
		tmp=S9X_24_BITS;
	if(temp==4)
		tmp=S9X_32_BITS;

	if(0!=GetDlgItemText(hDlg, IDC_NC_NEWVAL, buf, 12))
	{
		if(m_newCheat->format==2)
			ret = (sscanf(buf, "%d", &m_newCheat->new_val) == 1);
		else if(m_newCheat->format==1)
			ret = (sscanf(buf, "%u", &m_newCheat->new_val) == 1);
		else if(m_newCheat->format==3)
			ret = (sscanf(buf, "%x", &m_newCheat->new_val) == 1);

		if(!ret || !TestRange(m_newCheat->format, tmp, m_newCheat->new_val))
		{
			MessageBox(hDlg, SEARCH_ERR_INVALIDNEWVALUE, SEARCH_TITLE_RANGEERROR, MB_OK);
			return;
		}

		if(0==GetDlgItemText(hDlg, IDC_NC_CURRVAL, buf, 12))
			m_newCheat->saved=FALSE;
		else
		{
			int i;
			if(m_newCheat->format==2)
				ret = (sscanf(buf, "%d", &i) == 1);
			else if(m_newCheat->format==1)
				ret = (sscanf(buf, "%u", &i) == 1);
			else if(m_newCheat->format==3)
				ret = (sscanf(buf, "%x", &i) == 1);

			if(!ret || !TestRange(m_newCheat->format, tmp, i))
			{
				MessageBox(hDlg, SEARCH_ERR_INVALIDCURVALUE, SEARCH_TITLE_RANGEERROR, MB_OK);
				return;
			}

			m_newCheat->saved_val=i;
			m_newCheat->saved=TRUE;
		}
		GetDlgItemText(hDlg, IDC_NC_DESC, m_newCheat->name, 23);

		m_newCheat->enabled=TRUE;

		// don't add new cheat here, parent should do.
		//S9xAddCheat(m_newCheat->enabled,m_newCheat->saved_val,m_newCheat->address,m_newCheat->new_val);
		//strcpy(Cheat.c[Cheat.num_cheats-1].name,m_newCheat->name);

		ret = TRUE;
	}
	EndDialog(hDlg, ret);
}
示例#5
0
//-------------------------------Update()--------------------------------
//
//	First we take sensor readings and feed these into the sweepers brain.
//
//	The inputs are:
//	
//  The readings from the minesweepers sensors
//
//	We receive two outputs from the brain.. lTrack & rTrack.
//	So given a force for each track we calculate the resultant rotation 
//	and acceleration and apply to current velocity vector.
//
//-----------------------------------------------------------------------
bool CMinesweeper::Update(vector<SPoint> &objects)
{
	
	//this will store all the inputs for the NN
	vector<double> inputs;	

  //grab sensor readings
  TestSensors(objects);


  //input sensors into net
  for (int sr=0; sr<m_vecdSensors.size(); ++sr)
  {
    inputs.push_back(m_vecdSensors[sr]);

    inputs.push_back(m_vecFeelers[sr]);
  }
	
  inputs.push_back(m_bCollided);
  
	//update the brain and get feedback
	vector<double> output = m_pItsBrain->Update(inputs, CNeuralNet::active);

	//make sure there were no errors in calculating the 
	//output
	if (output.size() < CParams::iNumOutputs) 
  {
    return false;
  }
  
	//assign the outputs to the sweepers left & right tracks
	m_lTrack = output[0];
	m_rTrack = output[1];

	//calculate steering forces
	double RotForce = m_lTrack - m_rTrack;

  //clamp rotation
	Clamp(RotForce, -CParams::dMaxTurnRate, CParams::dMaxTurnRate);
	
	m_dRotation += RotForce;

	//update Look At 
	m_vLookAt.x = -sin(m_dRotation);
	m_vLookAt.y = cos(m_dRotation);

  //if the sweepers haven't collided with an obstacle
  //update their position
  if (!m_bCollided)
  {
    m_dSpeed = m_lTrack + m_rTrack;

   //update position
   m_vPosition += (m_vLookAt * m_dSpeed);

   //test range of x,y values - because of 'cheap' collision detection
   //this can go into error when using < 4 sensors
   TestRange();
  }

  //update the memory map
  m_MemoryMap.Update(m_vPosition.x, m_vPosition.y);
  
	return true;
}
示例#6
0
//-------------------------------Update()--------------------------------
//
//	First we take sensor readings and feed these into the sweepers brain.
//
//	The inputs are:
//	
//  The readings from the minesweepers sensors
//
//	We receive two outputs from the brain.. lTrack & rTrack.
//	So given a force for each track we calculate the resultant rotation 
//	and acceleration and apply to current velocity vector.
//
//-----------------------------------------------------------------------
bool CMinesweeper::Update(vector<SPoint> &objects)
{
	if (m_bActive) {	
		//this will store all the inputs for the NN
		vector<double> inputs;	

		//grab sensor readings
		TestSensors(objects);


		//input sensors into net
		for (int sr=0; sr<m_vecdSensors.size(); ++sr)
		{
			inputs.push_back(m_vecdSensors[sr]);

		//	inputs.push_back(m_vecFeelers[sr]); // No need for feelers
		}

	//	inputs.push_back(m_bCollided);

		double reward = m_MemoryMap.CheckReward(m_vPosition.x, m_vPosition.y, m_bReverse);

		if (reward > 0.9) {
			reward = 0.1;
		}
		else if (reward > 0) {
			reward = 1;
		}

		inputs.push_back(reward);

		double turningPoint = m_MemoryMap.CheckTurningPoint(m_vPosition.x, m_vPosition.y);

		inputs.push_back(turningPoint);
		vector<double> output;
		if (reward < 0.01) {
		//update the brain and get feedback
			output = m_pItsBrain->Update(inputs, CNeuralNet::active);
		} else {
			output = m_pItsBrain->Update(inputs, CNeuralNet::snapshot);
		}

		//make sure there were no errors in calculating the 
		//output
		if (output.size() < CParams::iNumOutputs) 
		{
			return false;
		}

		//assign the outputs to the sweepers left & right tracks
	//	m_lTrack = output[0] * 2 - 1;
		//m_rTrack = output[1];
		m_lTrack = output[0] * 2 - 1;
		//calculate steering forces
		//double RotForce = m_lTrack - m_rTrack;


		//clamp rotation
		//Clamp(RotForce, -CParams::dMaxTurnRate, CParams::dMaxTurnRate);

		//if(m_lTrack < -0.3) m_dRotation = 0;//3.14159265358979;//3.14159265358979f * (3.0 / 2.0);
		//else if(m_lTrack > 0.3) m_dRotation = 3.1415926358979f * 0.5;
		//else m_dRotation = 3.1415926358979f * 1.5;

		m_dRotation += m_lTrack;

		//update Look At 
		m_vLookAt.x = -sin(m_dRotation);
		m_vLookAt.y = cos(m_dRotation);
		

		//if the sweepers haven't collided with an obstacle
		//update their position
		if (!m_bCollided)
		{
			m_dSpeed = 3;// + m_rTrack;

			//m_dSpeed *= 2;

			//update position
			m_vPosition += (m_vLookAt * m_dSpeed);

			//test range of x,y values - because of 'cheap' collision detection
			//this can go into error when using < 4 sensors
			TestRange();
		}

		//update the memory map
		m_MemoryMap.Update(m_vPosition.x, m_vPosition.y);

		m_bActive = reward < 0.05;

		return true;
	}
	return true;
}
示例#7
0
void runTExMap()
{
   cout << endl << "TExMap Basic Tests Start" << endl << endl;

   TExMap *m = 0;

   cout << "TExMap()" << endl << endl;

   m = new TExMap;
   m->Print();
   cout << "Capacity(): " << m->Capacity() << endl;
   cout << "GetSize(): " << m->GetSize() << endl;
   delete m;

   cout << endl << "TExMap(1000)" << endl << endl;

   m = new TExMap(1000);
   m->Print();
   cout << "Capacity(): " << m->Capacity() << endl;
   cout << "GetSize(): " << m->GetSize() << endl;
   delete m;

   cout << endl << "TExMap(0)" << endl << endl;

   m = new TExMap(0);
   m->Print();
   cout << "Capacity(): " << m->Capacity() << endl;
   cout << "GetSize(): " << m->GetSize() << endl;
   delete m;

   cout << endl << "TExMap(-1)" << endl << endl;

   m = new TExMap(-1);
   m->Print();
   cout << "Capacity(): " << m->Capacity() << endl;
   cout << "GetSize(): " << m->GetSize() << endl;
   delete m;

   for( int i=0; i < kNUlv; i++) {
      for( int j=0; j < kNLv; j++) {
         for( int k=0; k < kNLv; k++) {
            if ( !TestOne(ulv[i], lv[j], lv[k]) ) return;
         }
      }
   }

   cout << endl << "TestRange(hash_identity)" << endl << endl;
   if ( !TestRange(hash_identity) ) return;

   cout << endl << "TestRange(hash_min)" << endl << endl;
   if ( !TestRange(hash_min) ) return;

   cout << endl << "TestRange(hash_max)" << endl << endl;
   if ( !TestRange(hash_max) ) return;

   cout << endl << "TestRange(hash_div4)" << endl << endl;
   if ( !TestRange(hash_div4) ) return;


   int i;
   for(i=0; i < kNLv; i++) {

      cout << endl << "TestDoubleAdd(hash_identity, " << lv[i]<< ")" << endl << endl;
      if ( !TestDoubleAdd(hash_identity, lv[i]) ) return;

      cout << endl << "TestDoubleAdd(hash_min, " << lv[i]<< ")" << endl << endl;
      if ( !TestDoubleAdd(hash_min, lv[i]) ) return;

      cout << endl << "TestDoubleAdd(hash_max, " << lv[i]<< ")" << endl << endl;
      if ( !TestDoubleAdd(hash_max, lv[i]) ) return;

      cout << endl << "TestDoubleAdd(hash_div4, " << lv[i]<< ")" << endl << endl;
      if ( !TestDoubleAdd(hash_div4, lv[i]) ) return;
   }

   cout << endl << "TExMap Basic Tests End" << endl << endl;
}