Пример #1
0
static char *formatDosToAmiga_ShouldMovePitcherActionGamesToSimulatedStarts_GivenAPlayersFile()
{
     fileplayer_s *players_file    = buildFilePlayers();
     int           expected_starts = 0;
     int           player_idx      = 0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos == fpos_Pitcher )
          {
               acc_pch_stats_s *sim = &(players_file[i].acc_stats.simulated.pitching);
               acc_bat_stats_s *act = &(players_file[i].acc_stats.action.batting);

               expected_starts = byte2int( sim->acc_starts );
               player_idx      = i;

               int2byte( sim->acc_starts, byte2int( act->acc_games ) );
               int2byte( act->acc_games,  expected_starts            );

               break;
          }
     }

     assertEquals( bl_True, formatDosToAmiga( players_file ) );

     acc_pch_stats_s *sim = &(players_file[player_idx].acc_stats.simulated.pitching);

     assertEquals( expected_starts, byte2int( sim->acc_starts ) );

     return NULL;
}
Пример #2
0
static char *formatDosToAmiga_ShouldCapStrikeOutsAndMoveExcessFromActionToSimulated_GivenAPlayersFile()
{
     fileplayer_s *players_file = buildFilePlayers();
     int           player_idx   = 0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               int2byte( players_file[i].acc_stats.action.batting.acc_so,    229 );
               int2byte( players_file[i].acc_stats.simulated.batting.acc_so,   0 );

               player_idx = i;

               break;
          }
     }

     formatDosToAmiga( players_file );

     assertEquals( 225, byte2int( players_file[player_idx].acc_stats.simulated.batting.acc_so ) );
     assertEquals(   4, byte2int( players_file[player_idx].acc_stats.action.batting.acc_so    ) );

     return NULL;
}
Пример #3
0
static char *formatDosToAmiga_ShouldSwapBatterSimulatedWithAction_GivenAPlayersFile()
{
     fileplayer_s    *players_file = buildFilePlayers();
     acc_bat_stats_s  expected_sim = { 0 };
     acc_bat_stats_s  expected_act = { 0 };
     int              player_idx   =   0;

     swapBatterStats( players_file );

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          int pos = nibble( players_file[i].position[0], n_High );

          if ( pos != fpos_Pitcher )
          {
               if ( byte2int( players_file[i].acc_stats.action.batting.acc_rbi ) < STAT_CAP_AMOUNT &&
                    byte2int( players_file[i].acc_stats.action.batting.acc_so  ) < STAT_CAP_AMOUNT    )
               {
                    expected_act = players_file[i].acc_stats.simulated.batting;
                    expected_sim = players_file[i].acc_stats.action.batting;
                    player_idx   = i;

                    break;
               }
          }
     }

     assertEquals( bl_True, formatDosToAmiga( players_file ) );

     compareBattingStats( &expected_act, &(players_file[player_idx].acc_stats.action.batting)    );
     compareBattingStats( &expected_sim, &(players_file[player_idx].acc_stats.simulated.batting) );

     return NULL;
}
Пример #4
0
string Sdr::loadDict() {
    if(this->isDictLoaded()){
        return "dict already loaded";
    }
    this->loadDictInfo();
	string epath = this->edxpath();
	string ipath = this->idxpath();
	string dpath = this->dictpath();

	this->edx_f = new fstream(epath.c_str(), ios::in);
	if (!this->edx_f->is_open()) {
		this->unloadDict();
		return "open .edx error:" + epath;
	}
	char cbuf[2048];
	if (this->medx) {
		this->edx_s = new stringstream();
		while (!this->edx_f->eof()) {
			this->edx_f->read(cbuf, 2048);
			size_t rsize = this->edx_f->gcount();
			this->edx_s->write(cbuf, rsize);
		}
		this->edx_f->close();
		delete this->edx_f;
		this->edx_s->seekg(0);
		this->edx_f = 0;
		this->edx = this->edx_s;
	} else {
		this->edx = this->edx_f;
	}
	this->edx->seekg(0);
	this->edx->read(cbuf, EDX_HSIZE);
	this->edxCharSize = byte2int(cbuf);
	this->edxOffsetSize = byte2int(cbuf + 4);
	this->edxEntryCount = byte2int(cbuf + 8);
	this->edxEntrySize = this->edxCharSize + this->edxOffsetSize;
	this->idx = new fstream(ipath.c_str(), ios::in);
	if (!this->idx->is_open()) {
		this->unloadDict();
		return "open .idx error:" + ipath;
	}
	this->dict = new fstream(dpath.c_str(), ios::in);
	if (!this->dict->is_open()) {
		this->unloadDict();
		return "open .dict error:" + dpath;
	}
	return "";
}
Пример #5
0
// return 0 if message type is not 1,2,3,4
int fetchReceivedMessage(struct MESSAGE* p, char* buf)
{
	p->msgType = (int)buf[0];
	int* path=NULL;
	int i;
	switch(p->msgType){
	case 1:
		p->dest = byte2int(&buf[1]);
    		strcpy(p->message, &buf[3]);
    		printf("%d fetchReceivedMessage: ",pGlobalTopo->myaddr);
    		printMESSAGE(buf);
    	return 1;
	case 2:
		path = (int*)(buf+1);
		p->hopNum = path[0];
		memcpy(p->path,&path[1],sizeof(int)*p->hopNum);
		strcpy(p->message,buf+1+sizeof(int)*(p->hopNum+1));
		p->src = p->path[0];
		p->dest = p->path[p->hopNum-1];
		printf("%d fetchReceivedMessage: ",pGlobalTopo->myaddr);
    		printMESSAGE(buf);
		return 2;
	case 3:
		memcpy(&p->linkinfo,&buf[1],sizeof(struct LINK));
		return 3;
	case 4:
		memcpy(&p->linkinfo,&buf[1],sizeof(struct LINK));
		return 4;
	default: 
		printf("Unknown UDP fetchReceivedMessage\n");
		return 0;
	}
}
Пример #6
0
boolean_e genPlayerIds( fileplayer_s *players_file )
{
     clearErrorMessage();

     for ( int player_id = 1, idx = 0; idx < TOTAL_PLAYERS; ++idx )
     {
          if ( EMPTY( players_file[idx].last_name ) ) continue;

          acc_player_id_s *id_info = &(players_file[idx].acc_stats.action.id_info);

          if ( word2int( id_info->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field already contains a number!" );

               return bl_False;
          }

          if ( byte2int( id_info->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field already contains a number!" );

               return bl_False;
          }

          int2word( id_info->player_id,               player_id   );
          int2byte( id_info->checksum,  calcChecksum( player_id ) );

          player_id++;
     }

     return bl_True;
}
Пример #7
0
boolean_e copyPlayerIds( fileplayer_s *players_file1, fileplayer_s *players_file2 )
{
     fileplayer_s   *matchingPlayer;


     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          if ( EMPTY( players_file1[i].last_name ) ) continue;

          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == NULL )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          acc_player_id_s *id_info1 = &(players_file1[i].acc_stats.action.id_info);
          acc_player_id_s *id_info2 = &(matchingPlayer->acc_stats.action.id_info);

          if ( word2int( id_info1->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          if ( byte2int( id_info1->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          int2word( id_info1->player_id, word2int( id_info2->player_id ) );
          int2byte( id_info1->checksum,  byte2int( id_info2->checksum  ) );
     }

     return bl_True;
}
Пример #8
0
static char *convertDivisions_ShouldReturnDivisionsWithTeams_GivenALeagueFileDataParksDataAndLeagueId()
{
     org_data_s org_data = { 0 };

     org_data.league_data  = buildFileLeagName();
     org_data.parks_data   = buildFileParks();
     org_data.players_data = buildFilePlayers();
     org_data.records      = buildRecords( org_data.league_data, 1, sp_Regular );

     fileleagname_s    *league_data      = org_data.league_data;
     fileparks_s       *parks_data       = org_data.parks_data;
     league_division_s *league_divisions = convertDivisions( &org_data, 1, 0 );

     for ( int i = 0; i < DIVISIONS_PER_LEAGUE; ++i )
     {
          assertNotNull( league_divisions[i].division );

          division_team_s *division_teams = league_divisions[i].division->teams;

          assertNotNull( division_teams );

          for ( int j = 0; j < TEAMS_PER_DIVISION; ++j )
          {
               int idx      = (i * TEAMS_PER_DIVISION) + j;
               int park_idx = byte2int( league_data->teams[idx].stadium );

               assertNotNull(                                                     division_teams[j].team                  );
               assertEqualsInt(           i + 1,                                  division_teams[j].division_id           );
               assertEqualsInt( byte2int( league_data->teams[idx].team_id ),      division_teams[j].team_id               );
               assertEqualsInt( byte2int( league_data->teams[idx].team_id ),      division_teams[j].team->team_id         );
               assertEqualsStr(           league_data->teams[idx].name,           division_teams[j].team->name            );
               assertEqualsStr(           parks_data->park_names[park_idx].text,  division_teams[j].team->location        );
               assertEqualsInt( byte2int( league_data->teams[idx].color ),        division_teams[j].team->primary_color   );
               assertEqualsInt( byte2int( league_data->teams[idx].color ),        division_teams[j].team->secondary_color );
          }
     }

     free_league_divisions( league_divisions );

     return NULL;
}
Пример #9
0
SdrRes Sdr::find(long beg_idx, long end_idx, string word) {
    if(!this->isDictLoaded()){
        this->loadDict();
    }
	SdrRes nfound = { 0, 0, 0, 0, "", word, "", "not found" };
	long idxsize = this->idxfilesize();
	if (end_idx < 0) {
		end_idx = idxsize;
	}
	if (beg_idx >= end_idx || end_idx >= idxsize) {
		return nfound;
	}
	this->idx->seekg(beg_idx);
	string sbuf;
	char cbuf[1024];
	const char* tword = word.c_str();
	int wsize = word.length();
	int idx_size = this->lessVersion("3.0.0") ? 4 : 8;
	while (this->idx->tellg() < end_idx) {
		sbuf.clear();
		getline(*this->idx, sbuf, '\0');
		this->idx->read(cbuf, idx_size + 4);
		if (ccmp_c(sbuf.c_str(), tword, wsize) == 0) {
			string mtype = this->sametypesequence();
			if (mtype == "m") {
				long dofft = byte2long(cbuf, idx_size);
				int dsize = byte2int(cbuf + idx_size);
				string dstr = this->dictm(dofft, dsize);
				SdrRes res = { 0, 0, beg_idx, end_idx, sbuf, word, dstr, "" };
				return res;
			} else {
				cout << "not implement:" << mtype << endl;
			}
			break;
		}
	}
	return nfound;
}
Пример #10
0
void printMESSAGE(char* message)
{
	int msgType;
	msgType = (int)message[0];
	int dest;
	int* paths;
	int hopNum;
	int i;
	int* nodes;
	float* cost;
	switch(msgType){
	case 1:
		printf("printMESSAGE messagetype: %d ", msgType);
		dest = byte2int(&message[1]);
    		printf("dest: %d message: %s\n",dest,&message[3]);
		return;
	case 2:
		printf("printMESSAGE messagetype: %d ", msgType);
		memcpy(&hopNum,&message[1],sizeof(int));
		printf("hopNum: %d ",hopNum);
		paths = (int*)&message[1+sizeof(int)];
		printf("Paths: ");
		for(i=0;i<hopNum;i++){
			printf("%d ",paths[i]);
		}
		printf("message: %s\n",&message[1+sizeof(int)+sizeof(int)*hopNum]);
		return;
	case 3:
	case 4:
		printf("printMESSAGE messagetype: %d ", msgType);
		printf("node1: %d node2: %d cost: %.0f \n", *(int*)(message+1), *(int*)(message+1+sizeof(int)), *(float*)(message+1+sizeof(int)*2));
		return;
	default: 
		printf("printMESSAGE: Unknown MESSAGE\n");
		return;
	}
}
int  ParserP2P::getBHAckIdentifier	() {return byte2int(m_bh_ackIdentifier	);}
int  ParserP2P::getBHAckUniqueID 	() {return byte2int(m_bh_ackUniqueID 	);}
int  ParserP2P::getBHMessageLength	() {return byte2int(m_bh_messageLength	);}
int  ParserP2P::getBHFlag 		() {return byte2int(m_bh_flag 	 	);}
int  ParserP2P::getBHTotalDataSize	() {return byte2int(m_bh_totalDataSize	);}
int  ParserP2P::getBHDataOffset 	() {return byte2int(m_bh_dataOffset 	);}
int  ParserP2P::getBHid			() {return byte2int(m_bh_identifier	);}
int  ParserP2P::getBHSessionID 	 	() {return byte2int(m_bh_sessionID	);}
Пример #19
0
boolean_e formatDosToAmiga( fileplayer_s *players_file )
{
     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
	  if ( EMPTY( players_file[i].last_name ) ) continue;

          unsigned int pos = nibble( players_file[i].position[0], n_High );

          if   ( pos != fpos_Pitcher )
          {
               acc_bat_stats_s *action = &(players_file[i].acc_stats.action.batting);

               if ( byte2int( action->acc_rbi ) >= STAT_CAP_AMOUNT ||
                    byte2int( action->acc_so  ) >= STAT_CAP_AMOUNT    )
               {
                    acc_pch_stats_s *pch = &(players_file[i].acc_stats.simulated.pitching);

                    unsigned int act_inn  = word2int( pch->acc_innings );
                    unsigned int act_hits = word2int( pch->acc_hits    );

                    if ( act_inn > 0  ||  act_hits > 0 )
                    {
                         sprintf( error_message, "ERROR: Player %.*s, %.*s requires overflow and has pitching stats.",
                                  sizeof(players_file[i].last_name),  players_file[i].last_name,
                                  sizeof(players_file[i].first_name), players_file[i].first_name );

                         return bl_False;
                    }
               }

               acc_stats_s *acc_stats = &(players_file[i].acc_stats);

               acc_stats_u sim = acc_stats->simulated;

               acc_stats->simulated = acc_stats->action;
               acc_stats->action    = sim;

               capStat( acc_stats->simulated.batting.acc_rbi, acc_stats->action.batting.acc_rbi );
               capStat( acc_stats->simulated.batting.acc_so,  acc_stats->action.batting.acc_so  );
          }
          else
          {
               acc_bat_stats_s *act = &(players_file[i].acc_stats.action.batting);
               acc_pch_stats_s *sim = &(players_file[i].acc_stats.simulated.pitching);

               unsigned char games = act->acc_games[0];

               act->acc_games[0] = 0;

               sim->acc_starts[0] = games;
          }

          acc_player_id_s *id_info = &(players_file[i].acc_stats.action.id_info);

          int player_id = word2int( id_info->player_id );

          if ( player_id == 0  ||  calcChecksum( player_id ) != byte2int( id_info->checksum ) )
          {
               sprintf( error_message, "ERROR: Player %.*s, %.*s has a player id checksum mismatch.",
                        sizeof(players_file[i].last_name),  players_file[i].last_name,
                        sizeof(players_file[i].first_name), players_file[i].first_name );

               return bl_False;
          }
     }

     return bl_True;
}
int  ParserP2P::getBHAckDataSize 	() {return byte2int(m_bh_ackDataSize 	);}
bool ParserP2P::isFinished() {
	bool st = (byte2int(m_bh_dataOffset) + byte2int(m_bh_messageLength)) == byte2int(m_bh_totalDataSize);
	return st;
}
Пример #22
0
char *_compareBattingStats( acc_bat_stats_s *expected, acc_bat_stats_s *actual )
{
     assertEquals( word2int( expected->acc_ab    ), word2int( actual->acc_ab    ) );
     assertEquals( word2int( expected->acc_hits  ), word2int( actual->acc_hits  ) );
     assertEquals( byte2int( expected->acc_2b    ), byte2int( actual->acc_2b    ) );
     assertEquals( byte2int( expected->acc_3b    ), byte2int( actual->acc_3b    ) );
     assertEquals( byte2int( expected->acc_hr    ), byte2int( actual->acc_hr    ) );
     assertEquals( byte2int( expected->acc_bb    ), byte2int( actual->acc_bb    ) );
     assertEquals( byte2int( expected->acc_so    ), byte2int( actual->acc_so    ) );
     assertEquals( byte2int( expected->acc_games ), byte2int( actual->acc_games ) );
     assertEquals( byte2int( expected->acc_runs  ), byte2int( actual->acc_runs  ) );
     assertEquals( byte2int( expected->acc_rbi   ), byte2int( actual->acc_rbi   ) );
     assertEquals( byte2int( expected->acc_sb    ), byte2int( actual->acc_sb    ) );
     assertEquals( byte2int( expected->acc_err   ), byte2int( actual->acc_err   ) );

     return NULL;
}