Exemplo n.º 1
0
  SEQJ_tpCondRet SEQJ_DestroiSequencia ( SEQJ_tppSeqJ pSeqJ )
  {
    if(pSeqJ->pPilha != NULL)
    {
      PIL_DestruirPilha(pSeqJ->pPilha);
      
    }
    free(pSeqJ);

    return SEQJ_CondRetOK;
  }
Exemplo n.º 2
0
/***************************************************************************
*
*  Função: MON  &Destruir monte
*  ****/
   MON_tpCondRet MON_DestruirMonte ( MON_tppMonte pMonte )
   {

      if(pMonte->pPilha == NULL)
      {
        free(pMonte);
        return MON_CondRetOK;
      }

      PIL_DestruirPilha( pMonte->pPilha );
      free(pMonte);

      return MON_CondRetOK ; 
   }
Exemplo n.º 3
0
SEQFIM_tpCondRet SEQFIM_DestroiSeqFim ( SEQFIM_tppSeqFim pSeqFim )
{
	
	if( pSeqFim->pPilha != NULL )
	{
		PIL_DestruirPilha( pSeqFim->pPilha ) ;
	} /* if */
    
	if( pSeqFim != NULL )
	{
		free( pSeqFim ) ;
		pSeqFim = NULL ;
	} /* if */
    
    return SEQFIM_CondRetOK ;
    
}/* Fim função: SEQFIM Destruir Sequencia final */
Exemplo n.º 4
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxPilha  = -1 ,
		  inxDado	= -1,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      PIL_tpCondRet CondRet ;

      char   StringDado [ DIM_VALOR ] ;
	  char   vetDado[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'} ;
	  char   teste = '\0' ;

      int ValEsp = -1 ;

      int i ;

      int numElem = -1 ;

	  void *EndObtido = NULL;
	  void *EndEsperado = NULL;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de pilha */

         if ( strcmp( ComandoTeste , RESET_PILHA_CMD ) == 0 )
         {

            for( i = 0 ; i < DIM_VT_PILHA ; i++ )
            {
               vtPilhas[ i ] = NULL ;
            } /* for */

            return TST_CondRetOK ;

         } /* fim ativa: Efetuar reset de teste de pilha */

      /* Testar CriarPilha */

         else if ( strcmp( ComandoTeste , CRIAR_PILHA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
				&inxPilha, &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_CriarPilha( &vtPilhas[ inxPilha ] ) ;

            return TST_CompararInt( CondRetEsp , CondRet ,
               "Erro ao criar pilha."  ) ;

         } /* fim ativa: Testar CriarPilha */

      /* Testar Esvaziar pilha */

         else if ( strcmp( ComandoTeste , ESVAZIAR_PILHA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                               &inxPilha, &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp, PIL_EsvaziarPilha( vtPilhas[ inxPilha ] ),
					"Retorno inesperado." );

         } /* fim ativa: Testar Esvaziar pilha */

      /* Testar Destruir pilha */

         else if ( strcmp( ComandoTeste , DESTRUIR_PILHA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                               &inxPilha, &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_DestruirPilha( vtPilhas[ inxPilha ] ) ;
            vtPilhas[ inxPilha ] = NULL ;

            return TST_CompararInt( CondRetEsp , CondRet , "Retorno inesperado." ) ;

         } /* fim ativa: Testar Destruir pilha */

      /* Testar inserir elemento */

         else if ( strcmp( ComandoTeste , EMPILHAR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iii" ,
                       &inxPilha , &inxDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_Empilha( vtPilhas[ inxPilha ], &vetDado[inxDado]);

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir antes."                   ) ;

         } /* fim ativa: Testar inserir elemento */

      /* Testar excluir elemento */

         else if ( strcmp( ComandoTeste , DESEMPILHAR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                  &inxPilha , &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxPilha( inxPilha , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      PIL_Desempilha( vtPilhas[ inxPilha ] ) ,
                     "Condição de retorno errada ao excluir."   ) ;

         } /* fim ativa: Testar excluir elemento */

      /* Testar obter valor do elemento corrente */

         else if ( strcmp( ComandoTeste , OBTER_VALOR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iici" ,
                       &inxPilha , &inxDado , &teste , &ValEsp ) ;

            if ( numLidos != 4 )
            {
               return TST_CondRetParm ;
            } /* if */

			CondRet = PIL_ObterValor( vtPilhas[ inxPilha ], &EndObtido );
            
			if ( CondRet != PIL_CondRetOK )
            {
               return TST_CompararInt( ValEsp , CondRet ,
                         "Erro ao obter endereço do elemento." ) ;
            } /* if */

			EndEsperado = &vetDado[inxDado];

			if ( EndEsperado != EndObtido ) 
			{
				return TST_CompararPonteiro( EndEsperado, EndObtido, "Endereço obtido errado." );
			} /*if*/

            return TST_CompararChar( teste , *(char*)EndObtido ,
                         "Valor do elemento errado." ) ;

         } /* fim ativa: Testar obter valor do elemento corrente */

	  return TST_CondRetNaoConhec ;

   } /* Fim função: TPIL &Testar pilha */
Exemplo n.º 5
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      PIL_tpCondRet CondRetObtido   = PIL_CondRetOK ;
      PIL_tpCondRet CondRetEsperada = PIL_CondRetFaltouMemoria ;
                                      /* inicializa para qualquer coisa */

	 

      char NaipeEsperado = '?'  ;
      char NaipeObtido   = '!'  ;  
      char NaipeDado     = '\0' ;

      int ValorEsperado = -1  ;
      int ValorObtido   = -2  ;  
      int ValorDado     = 0 ;

      int PosicaoPilha = -1 ;
      int NumPilha = -1 ;
      int  NumLidos = -1 ;

      CAR_tppCarta CartaObtida ;
      CAR_tppCarta CartaDada ;

      TST_tpCondRet Ret ;

      /* Testar PIL Criar Pilha de Cartas */

         if ( strcmp( ComandoTeste , CRIAR_PIL_CMD ) == 0 )
         {

            NumLidos = LER_LerParametros( "ii" , &NumPilha ,
                               &CondRetEsperada ) ;
            if ( NumLidos != 2 || NumPilha >= MAX_PILS || NumPilha < 0 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = PIL_CriarPilhaVazia( &vPilhas[NumPilha] ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao criar pilha." );

         } /* fim ativa: Testar PIL Criar Pilha de cartas*/

      /* Testar PIL Push Carta na pilha */

         else if ( strcmp( ComandoTeste , PUSH_CMD ) == 0 )
         {
			
            NumLidos = LER_LerParametros( "icii" ,
                               &NumPilha, &NaipeDado , &ValorDado, &CondRetEsperada ) ;
            if ( NumLidos != 4 || NumPilha >= MAX_PILS || NumPilha < 0 )
            {
               return TST_CondRetParm ;
            } /* if */
			
			CAR_CriarCarta( &CartaDada ) ;
            CAR_PreencheCarta( CartaDada, NaipeDado , ValorDado );
			
            CondRetObtido = PIL_PushCarta( vPilhas[NumPilha] , CartaDada ) ;

            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                    "Retorno errado ao operar 'push' na pilha" );

         } /* fim ativa: Testar PIL Push Carta na pilha */

      /* Testar PIL Pop Carta da Pilha */

         else if ( strcmp( ComandoTeste , POP_CMD ) == 0 )
         {			
            NumLidos = LER_LerParametros( "ii" ,
                               &NumPilha , &CondRetEsperada ) ;
            if ( NumLidos != 2 || NumPilha >= MAX_PILS || NumPilha < 0 )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRetObtido = PIL_PopCarta( vPilhas[NumPilha] , &CartaObtida ) ;

			
            return TST_CompararInt( CondRetEsperada , CondRetObtido ,
                                   "Retorno errado ao operar 'pop' na pilha") ;


            } /* Testar PIL Ver Carta da Pilha */

		else if ( strcmp( ComandoTeste , VER_CMD ) == 0 )
         {
			
            NumLidos = LER_LerParametros( "iii" ,
                            &NumPilha , &PosicaoPilha , &CondRetEsperada ) ;
            if ( NumLidos != 3 || NumPilha >= MAX_PILS || NumPilha < 0 )
            {
                return TST_CondRetParm ;
            } /* if */

			 CondRetObtido = PIL_VerCarta( vPilhas[NumPilha] , &CartaObtida , PosicaoPilha ) ;
				
				
			 return TST_CompararInt( CondRetEsperada , CondRetObtido ,
						"Retorno errado ao ver carta da pilha") ;


            } /* Testar PIL Ver Carta da Pilha */

            /* Testar PIL Destruir pilha de cartas */
            else if ( strcmp( ComandoTeste , DESTROI_CMD ) == 0 )
            {

		    NumLidos = LER_LerParametros( "ii" , &NumPilha ,  
		                       &CondRetEsperada ) ;
		    if ( NumLidos != 2 || NumPilha >= MAX_PILS || NumPilha < 0 )
		    {
		       return TST_CondRetParm ;
		    } /* if */

		    CondRetObtido = PIL_DestruirPilha( vPilhas[NumPilha] ) ;

		    return TST_CompararInt( CondRetEsperada , CondRetObtido ,
		                            "Retorno errado destruir pilha." );

	    } /* fim ativa: Testar PIL Destruir Pilha de Cartas */

	    /* Testar PIL Destruir Pilha */

        return TST_CondRetNaoConhec ;

   } /* Fim função: TPIL Efetuar operações de teste específicas para pilha de cartas */