From ca568a8e51756b5bad94cfec859005b3aa0ba19a Mon Sep 17 00:00:00 2001 From: Tassio Date: Fri, 23 Oct 2015 17:09:13 -0200 Subject: [PATCH 1/2] ModuloBar OK e TestLis atualizado --- BAR.c | 27 ++- BAR.h | 17 ++ TESTBAR.c | 219 +++++++++++++++++++++++ TESTLIS.C | 449 +++++++++++++++++++++++++++++++++++++++++++++++ Teste.script | 36 ++++ testlista.script | 137 +++++++++++++++ 6 files changed, 878 insertions(+), 7 deletions(-) create mode 100644 TESTBAR.c create mode 100644 TESTLIS.C create mode 100644 Teste.script create mode 100644 testlista.script diff --git a/BAR.c b/BAR.c index 64b80c3..74550fa 100644 --- a/BAR.c +++ b/BAR.c @@ -21,13 +21,14 @@ #include #include #include -#include "LISTA.h" -#include "PECA.h" + + #define BAR_OWN #include "BAR.h" +#include "LISTA.H" +#include "PECA.h" #undef BAR_OWN - /*********************************************************************** * * $TC Tipo de dados: BAR Descritor da BAR @@ -101,12 +102,12 @@ BAR_tpCondRet BAR_AdicionarPeca(BAR_tppCapturadas pBAR) BAR_tpCondRet BAR_RemoverPeca(BAR_tppCapturadas pBAR) { + pBAR->tamanho--; if(LIS_ExcluirElemento(pBAR->ListaCapturadas) != LIS_CondRetOK) { printf("Erro ao excluir peca da lsita (BAR) \n"); return BAR_CondRetErro; } - return BAR_CondRetOK; } @@ -122,8 +123,8 @@ BAR_tpCondRet BAR_ObterTamanhoBar(BAR_tppCapturadas pBAR, int *tam) *tam = pBAR->tamanho; - if(*tam == 0) - return BAR_CondRetVazia; + //if(*tam == 0) + //return BAR_CondRetVazia; return BAR_CondRetOK; } @@ -153,5 +154,17 @@ BAR_tpCondRet BAR_ObterCorBar(BAR_tppCapturadas pBAR, char *cor) } return BAR_CondRetOK; }*/ -/******** Fim do Módulo de Implementação: BAR Lista de Peças Capturadas *************/ +/*************************************************************************** +* +* Função: TAB &Destruir BAR +* ****/ + +BAR_tpCondRet Bar_DestruirBar(BAR_tppCapturadas pBAR) +{ + LIS_DestruirLista(pBAR->ListaCapturadas); + free(pBAR); + return BAR_CondRetOK; +} + +/******** Fim do Módulo de Implementação: BAR Lista de Peças Capturadas *************/ \ No newline at end of file diff --git a/BAR.h b/BAR.h index 4e14c73..b24f7ff 100644 --- a/BAR.h +++ b/BAR.h @@ -161,6 +161,23 @@ typedef struct BAR_tagCapturadas * BAR_tppCapturadas ; BAR_tpCondRet BAR_ObterCorBar(BAR_tppCapturadas pBAR, char *cor) ; +/*************************************************************************** +* +* Função: TAB &Destruir BAR +* +* $ED Descrição da função +* Destroi a lista BAR. +* +* $EP Parâmetros +* PBar - A BAR que se destruir +* +* $FV Valor retornado +* BAR_CondRetOk +* BAR_CondRetErro +* ****/ + + BAR_tpCondRet Bar_DestruirBar(BAR_tppCapturadas pBAR); + /********************************************************************/ #undef BAR_EXT diff --git a/TESTBAR.c b/TESTBAR.c new file mode 100644 index 0000000..dbc2d47 --- /dev/null +++ b/TESTBAR.c @@ -0,0 +1,219 @@ +/*************************************************************************** +* $MCI Módulo de implementação: Módulo de teste específico + +* Módulo criado para operar com listas +* +* Arquivo gerado: TESTBAR.C +* Letras identificadoras: TBar +* +* Nome da base de software: Exemplo de teste automatizado +* +* Projeto: Disciplinas INF 1628 / 1301 +* Gestor: DI/PUC-Rio +* Autores: fvc - Felipe Vieira Cortes +* tbm - Tássio Borges de Miranda +* db - Daniela Brazão +* +* $HA Histórico de evolução: +* Versão Autor Data Observações +* 4.00 tbm 23/10/2015 Módulo criado para operar com listas +* +* $ED Descrição do módulo +* Este módulo contém as funções específicas para o teste do +* módulo Bar. +* +* $EIU Interface com o usuário pessoa +* Comandos de teste específicos para testar o módulo BAR: + +* =criarbar - Chama a função BAR_tpCondRet BAR_CriarBAR() +* =obtercorbar - Chama a função BAR_tpCondRet BAR_AdicionarPeca(BAR_tppCapturadas pBAR) +* =obtertamanhobar - Chama a função BAR_tpCondRet BAR_RemoverPeca(BAR_tppCapturadas pBAR) +* =removerbar - Chama a função BAR_tpCondRet BAR_ObterTamanhoBar(BAR_tppCapturadas pBAR, int *tam) +* =addbar - Chama a função BAR_tpCondRet BAR_ObterCorBar(BAR_tppCapturadas pBAR, char *cor) +* =destruirbar - Chama a função BAR_tpCondRet Bar_DestruirBar(BAR_tppCapturadas pBAR) +* +***************************************************************************/ + +#include +#include +#include + +#include "BAR.h" +#include "LISTA.H" +#include "GENERICO.H" +#include "LERPARM.H" +#include "PECA.h" +#include "TST_ESPC.H" + + +/* Tabela dos nomes dos comandos de teste específicos */ +#define MAX 5 +#define DIM_VET_BAR 2 +#define CRIAR_BAR_CMD "=criarbar" +#define REMOVER_BAR_CMD "=removerbar" +#define OBTER_COR_BAR_CMD "=obtercorbar" +#define ADD_BAR_CMD "=addbar" +#define OBTER_TAM_BAR_CMD "=obtertamanhobar" +#define DESTRUIR_BAR_CMD "=destruirbar" + +BAR_tppCapturadas BarCap [DIM_VET_BAR]; + +/***** Protótipos das funções encapuladas no módulo *****/ + + static void DestruirValor( void * pValor ) ; + +/***** Código das funções exportadas pelo módulo *****/ + + +/*********************************************************************** +* +* $FC Função: TPec Efetuar operações de teste específicas para o Modulo Peca +* +* $ED Descrição da função +* Efetua os diversos comandos de teste específicos para o módulo +* Peca sendo testado. +* +* $EP Parâmetros +* $P ComandoTeste - String contendo o comando +* +* $FV Valor retornado +* Ver TST_tpCondRet definido em TST_ESPC.H +* +***********************************************************************/ + + TST_tpCondRet TST_EfetuarComando( char * ComandoTeste ) + { + + int CondRetObtido = BAR_CondRetOK ; + int CondRetEsperada = BAR_CondRetFaltouMemoria ; + /* inicializa para qualquer coisa */ + + char ValorEsperado = '?' ; + char ValorObtido = '!' ; + char ValorDado = '\0' ; + char corEsperada = 'x'; + char corRecebida; + int NumLidos = -1 ; + int i = 0; + int inxpec, tamanhobar,tamanhobaresp; + + TST_tpCondRet Ret; + TST_tpCondRet CondRet; + + /* Testar Bar Criar Bar */ + if ( strcmp( ComandoTeste , CRIAR_BAR_CMD ) == 0 ) + { + + NumLidos = LER_LerParametros( "ici" , + &inxpec, &corRecebida, &CondRetEsperada ) ; + if ( NumLidos != 3 ) + { + return TST_CondRetParm ; + } /* if */ + + if(inxpec > 5 || inxpec < 0) return TST_CondRetErro; + + CondRetObtido = BAR_CriarBAR(&BarCap[inxpec],corRecebida,DestruirValor); + + return TST_CompararInt( CondRetEsperada , CondRetObtido , + "Retorno errado ao criar BAR." ); + + } /* fim ativa: Testar BAR Criar BAr */ + + /* Testar Bar Remover Bar */ + else if ( strcmp( ComandoTeste , REMOVER_BAR_CMD ) == 0 ) + { + + NumLidos = LER_LerParametros( "ii" , &inxpec, &CondRetEsperada ) ; + if ( NumLidos != 2 ) + { + return TST_CondRetParm ; + } /* if */ + + CondRetObtido = BAR_RemoverPeca(BarCap[inxpec]) ; + + return TST_CompararInt( CondRetEsperada , CondRetObtido , + "Retorno errado ao Removar Bar." ); + + } /* fim ativa: Testar Bar Remover Bar */ + + /* Testar Bar Obter cor da Bar */ + else if ( strcmp( ComandoTeste , OBTER_COR_BAR_CMD ) == 0 ) + { + + NumLidos = LER_LerParametros( "ici",&inxpec,&corEsperada, &CondRetEsperada ) ; + if ( NumLidos != 3 ) + { + return TST_CondRetParm ; + } /* if */ + CondRetObtido = BAR_ObterCorBar(BarCap[inxpec],&corRecebida) ; + + Ret = TST_CompararChar( corRecebida , corEsperada , + "Valor do elemento errado, diferente do esperado" ) ; + + if ( Ret != TST_CondRetOK ) + { + return Ret ; + } /* if */ + + return TST_CompararChar(CondRetObtido, CondRetEsperada, "Retorno errado ao obter o cor do BAR."); + + } /* fim ativa: Testar Bar Obter cor da Bar */ + + /* Testar Bar AddBar */ + else if ( strcmp( ComandoTeste , ADD_BAR_CMD ) == 0 ) + { + + NumLidos = LER_LerParametros( "ii" , &inxpec, &CondRetEsperada ) ; + if ( NumLidos != 2 ) + { + return TST_CondRetParm ; + } /* if */ + + CondRetObtido = BAR_AdicionarPeca(BarCap[inxpec]) ; + + return TST_CompararInt( CondRetEsperada , CondRetObtido , + "Retorno errado ao obter cor da BAR." ); + + } + /*Fim da ativa: Testar Bar addbar*/ + + /* Testar obter tamanho BAR*/ + else if( strcmp ( ComandoTeste , OBTER_TAM_BAR_CMD) == 0) + { + NumLidos = LER_LerParametros( "iii" , &inxpec,&tamanhobaresp, &CondRetEsperada); + if ( NumLidos != 3 ) + return TST_CondRetParm; + + CondRetObtido = BAR_ObterTamanhoBar(BarCap[inxpec],&tamanhobar); + + CondRet = TST_CompararInt(tamanhobaresp,tamanhobar,"Tamanho do elemento errado, diferente do esperado"); + + if ( CondRet != TST_CondRetOK ) + return CondRet; + + return TST_CompararInt( CondRetEsperada , CondRetObtido, "Retorno errado ao obter tamanho bar."); + } + /*Fim da ativa: Testar Bar tamanhoBAR*/ + + /*Testar Destruir Bar*/ + + else if( strcmp ( ComandoTeste , DESTRUIR_BAR_CMD) == 0) + { + NumLidos = LER_LerParametros( "ii" , &inxpec, &CondRetEsperada); + if ( NumLidos != 2 ) + return TST_CondRetParm; + + CondRetObtido = Bar_DestruirBar(BarCap[inxpec]); + + return TST_CompararInt( CondRetEsperada , CondRetObtido, "Retorno errado ao destruir BAR."); + } + + /*Fim da ativa: Testar Destuir Bar*/ + return TST_CondRetNaoConhec ; + } /* Fim função: TPec Efetuar operações de teste específicas para Peca */ + +void DestruirValor( void * pValor ) + { + free( pValor ) ; + } \ No newline at end of file diff --git a/TESTLIS.C b/TESTLIS.C new file mode 100644 index 0000000..a55bece --- /dev/null +++ b/TESTLIS.C @@ -0,0 +1,449 @@ +/*************************************************************************** +* $MCI Módulo de implementação: TLIS Teste lista de símbolos +* +* Arquivo gerado: TestLIS.c +* Letras identificadoras: TLIS +* +* Nome da base de software: Arcabouço para a automação de testes de programas redigidos em C +* Arquivo da base de software: D:\AUTOTEST\PROJETOS\LISTA.BSW +* +* Projeto: INF 1301 / 1628 Automatização dos testes de módulos C +* Gestor: LES/DI/PUC-Rio +* Autores: avs +* +* $HA Histórico de evolução: +* Versão Autor Data Observações +* 4 avs 01/fev/2006 criar linguagem script simbólica +* 3 avs 08/dez/2004 uniformização dos exemplos +* 2 avs 07/jul/2003 unificação de todos os módulos em um só projeto +* 1 avs 16/abr/2003 início desenvolvimento +* +***************************************************************************/ + +#include +#include +#include + +#include "TST_Espc.h" + +#include "Generico.h" +#include "LerParm.h" + +#include "Lista.h" + + +static const char RESET_LISTA_CMD [ ] = "=resetteste" ; +static const char CRIAR_LISTA_CMD [ ] = "=criarlista" ; +static const char DESTRUIR_LISTA_CMD [ ] = "=destruirlista" ; +static const char ESVAZIAR_LISTA_CMD [ ] = "=esvaziarlista" ; +static const char INS_ELEM_ANTES_CMD [ ] = "=inselemantes" ; +static const char INS_ELEM_APOS_CMD [ ] = "=inselemapos" ; +static const char OBTER_VALOR_CMD [ ] = "=obtervalorelem" ; +static const char EXC_ELEM_CMD [ ] = "=excluirelem" ; +static const char IR_INICIO_CMD [ ] = "=irinicio" ; +static const char IR_FIM_CMD [ ] = "=irfinal" ; +static const char AVANCAR_ELEM_CMD [ ] = "=avancarelem" ; +static const char PROCURA_VALOR_CMD [ ] = "=procurarvalor" ; +static const char OBTER_TAMANHO_CMD [ ] = "=obtertamanho" ; + +#define TRUE 1 +#define FALSE 0 + +#define VAZIO 0 +#define NAO_VAZIO 1 + +#define DIM_VT_LISTA 10 +#define DIM_VALOR 100 + +LIS_tppLista vtListas[ DIM_VT_LISTA ] ; + +/***** Protótipos das funções encapuladas no módulo *****/ + + static void DestruirValor( void * pValor ) ; + + static int ValidarInxLista( int inxLista , int Modo ) ; + +/***** Código das funções exportadas pelo módulo *****/ + + +/*********************************************************************** +* +* $FC Função: TLIS &Testar lista +* +* $ED Descrição da função +* Podem ser criadas até 10 listas, identificadas pelos índices 0 a 10 +* +* Comandos disponíveis: +* +* =resetteste +* - anula o vetor de listas. Provoca vazamento de memória +* =criarlista inxLista +* =destruirlista inxLista +* =esvaziarlista inxLista +* =inselemantes inxLista string CondRetEsp +* =inselemapos inxLista string CondRetEsp +* =obtervalorelem inxLista string CondretPonteiro +* =excluirelem inxLista CondRetEsp +* =irinicio inxLista +* =irfinal inxLista +* =avancarelem inxLista numElem CondRetEsp +* =procurarvalor inxLista string CondretPonteiro +* +***********************************************************************/ + + TST_tpCondRet TST_EfetuarComando( char * ComandoTeste ) + { + + int inxLista = -1 , + numLidos = -1 , + CondRetEsp = -1 ; + + TST_tpCondRet CondRet ; + + int CondRetObtido = LIS_CondRetOK; + + char StringDado[ DIM_VALOR ] ; + char * pDado ; + + int ValEsp = -1 ; + + int i,num ; + + int numElem = -1 ; + + StringDado[ 0 ] = 0 ; + + /* Efetuar reset de teste de lista */ + + if ( strcmp( ComandoTeste , RESET_LISTA_CMD ) == 0 ) + { + + for( i = 0 ; i < DIM_VT_LISTA ; i++ ) + { + vtListas[ i ] = NULL ; + } /* for */ + + return TST_CondRetOK ; + + } /* fim ativa: Efetuar reset de teste de lista */ + + /* Testar CriarLista */ + + else if ( strcmp( ComandoTeste , CRIAR_LISTA_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "i" , + &inxLista ) ; + + if ( ( numLidos != 1 ) + || ( ! ValidarInxLista( inxLista , VAZIO ))) + { + return TST_CondRetParm ; + } /* if */ + + vtListas[ inxLista ] = + LIS_CriarLista( DestruirValor ) ; + + return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] , + "Erro em ponteiro de nova lista." ) ; + + } /* fim ativa: Testar CriarLista */ + + /* Testar Esvaziar lista lista */ + + else if ( strcmp( ComandoTeste , ESVAZIAR_LISTA_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "i" , + &inxLista ) ; + + if ( ( numLidos != 1 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO ))) + { + return TST_CondRetParm ; + } /* if */ + + LIS_EsvaziarLista( vtListas[ inxLista ] ) ; + + return TST_CondRetOK ; + + } /* fim ativa: Testar Esvaziar lista lista */ + + /* Testar Destruir lista */ + + else if ( strcmp( ComandoTeste , DESTRUIR_LISTA_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "i" , + &inxLista ) ; + + if ( ( numLidos != 1 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO ))) + { + return TST_CondRetParm ; + } /* if */ + + LIS_DestruirLista( vtListas[ inxLista ] ) ; + vtListas[ inxLista ] = NULL ; + + return TST_CondRetOK ; + + } /* fim ativa: Testar Destruir lista */ + + /* Testar inserir elemento antes */ + + else if ( strcmp( ComandoTeste , INS_ELEM_ANTES_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "isi" , + &inxLista , StringDado , &CondRetEsp ) ; + + if ( ( numLidos != 3 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + pDado = ( char * ) malloc( strlen( StringDado ) + 1 ) ; + if ( pDado == NULL ) + { + return TST_CondRetMemoria ; + } /* if */ + + strcpy( pDado , StringDado ) ; + + + CondRet = LIS_InserirElementoAntes( vtListas[ inxLista ] , pDado ) ; + + if ( CondRet != LIS_CondRetOK ) + { + free( pDado ) ; + } /* if */ + + return TST_CompararInt( CondRetEsp , CondRet , + "Condicao de retorno errada ao inserir antes." ) ; + + } /* fim ativa: Testar inserir elemento antes */ + + /* Testar inserir elemento apos */ + + else if ( strcmp( ComandoTeste , INS_ELEM_APOS_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "isi" , + &inxLista , StringDado , &CondRetEsp ) ; + + if ( ( numLidos != 3 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + pDado = ( char * ) malloc( strlen( StringDado ) + 1 ) ; + if ( pDado == NULL ) + { + return TST_CondRetMemoria ; + } /* if */ + + strcpy( pDado , StringDado ) ; + + + CondRet = LIS_InserirElementoApos( vtListas[ inxLista ] , pDado ) ; + + if ( CondRet != LIS_CondRetOK ) + { + free( pDado ) ; + } /* if */ + + return TST_CompararInt( CondRetEsp , CondRet , + "Condicao de retorno errada ao inserir apos." ) ; + + } /* fim ativa: Testar inserir elemento apos */ + + /* Testar excluir simbolo */ + + else if ( strcmp( ComandoTeste , EXC_ELEM_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "ii" , + &inxLista , &CondRetEsp ) ; + + if ( ( numLidos != 2 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + return TST_CompararInt( CondRetEsp , + LIS_ExcluirElemento( vtListas[ inxLista ] ) , + "Condição de retorno errada ao excluir." ) ; + + } /* fim ativa: Testar excluir simbolo */ + + /* Testar obter valor do elemento corrente */ + + else if ( strcmp( ComandoTeste , OBTER_VALOR_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "isi" , + &inxLista , StringDado , &ValEsp ) ; + + if ( ( numLidos != 3 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + pDado = ( char * ) LIS_ObterValor( vtListas[ inxLista ] ) ; + + if ( ValEsp == 0 ) + { + return TST_CompararPonteiroNulo( 0 , pDado , + "Valor não deveria existir." ) ; + } /* if */ + + if ( pDado == NULL ) + { + return TST_CompararPonteiroNulo( 1 , pDado , + "Dado tipo um deveria existir." ) ; + } /* if */ + + return TST_CompararString( StringDado , pDado , + "Valor do elemento errado." ) ; + + } /* fim ativa: Testar obter valor do elemento corrente */ + + /* Testar ir para o elemento inicial */ + + else if ( strcmp( ComandoTeste , IR_INICIO_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "i" , &inxLista ) ; + + if ( ( numLidos != 1 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + IrInicioLista( vtListas[ inxLista ] ) ; + + return TST_CondRetOK ; + + } /* fim ativa: Testar ir para o elemento inicial */ + + /* LIS &Ir para o elemento final */ + + else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "i" , &inxLista ) ; + + if ( ( numLidos != 1 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + IrFinalLista( vtListas[ inxLista ] ) ; + + return TST_CondRetOK ; + + } /* fim ativa: LIS &Ir para o elemento final */ + + /* LIS &Avançar elemento */ + + else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 ) + { + + numLidos = LER_LerParametros( "iii" , &inxLista , &numElem , + &CondRetEsp ) ; + + if ( ( numLidos != 3 ) + || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + return TST_CompararInt( CondRetEsp , LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) , + "Condicao de retorno errada ao avancar" ) ; + + } /* fim ativa: LIS &Avançar elemento */ + + else if (strcmp ( ComandoTeste , OBTER_TAMANHO_CMD ) == 0 ) + { + numLidos = LER_LerParametros( "iii" ,&inxLista,&ValEsp, &CondRetEsp ) ; + + if ( ( numLidos != 3 )||( ! ValidarInxLista( inxLista , NAO_VAZIO )) ) + { + return TST_CondRetParm ; + } /* if */ + + CondRetObtido = LIS_ObterTamanho( vtListas[ inxLista ], &num ); + + CondRet = TST_CompararInt( ValEsp , num ,"Valor do elemento errado, diferente do esperado" ) ; + + if ( CondRet != TST_CondRetOK ) + return CondRet ; + + + return TST_CondRetOK(CondRetObtido, CondRetEsp, "Retorno errado ao obter o tamanho da lista."); + } + + return TST_CondRetNaoConhec ; + + } /* Fim função: TLIS &Testar lista */ + + +/***** Código das funções encapsuladas no módulo *****/ + + +/*********************************************************************** +* +* $FC Função: TLIS -Destruir valor +* +***********************************************************************/ + + void DestruirValor( void * pValor ) + { + + free( pValor ) ; + + } /* Fim função: TLIS -Destruir valor */ + + +/*********************************************************************** +* +* $FC Função: TLIS -Validar indice de lista +* +***********************************************************************/ + + int ValidarInxLista( int inxLista , int Modo ) + { + + if ( ( inxLista < 0 ) + || ( inxLista >= DIM_VT_LISTA )) + { + return FALSE ; + } /* if */ + + if ( Modo == VAZIO ) + { + if ( vtListas[ inxLista ] != 0 ) + { + return FALSE ; + } /* if */ + } else + { + if ( vtListas[ inxLista ] == 0 ) + { + return FALSE ; + } /* if */ + } /* if */ + + return TRUE ; + + } /* Fim função: TLIS -Validar indice de lista */ + +/********** Fim do módulo de implementação: TLIS Teste lista de símbolos **********/ + diff --git a/Teste.script b/Teste.script new file mode 100644 index 0000000..b0afe22 --- /dev/null +++ b/Teste.script @@ -0,0 +1,36 @@ +// Script: TesteLista.script +// Autor: Arndt von Staa, Tassio Miranda +// Data: 23/10/2015 +// + +==Criar BAR Branco +=criarbar 1 'b' 0 + +==Criar BAR Preto +=criarbar 2 'p' 0 + +==Obter Cor do BAR Branco +=obtercorbar 1 'b' 0 + +==Obter Cor do BAR Preto +=obtercorbar 2 'p' 0 + +==Aumentar o BAR Branco em 2 peças +=addbar 1 0 +=addbar 1 0 + +==Obter Tamaho do BAR Branco com 2 pecas +=obtertamanhobar 1 2 0 + +==Remover 2 peças do BAR Branco +=removerbar 1 0 +=removerbar 1 0 + +==Obter Tamaho do BAR Branco com 0 pecas +=obtertamanhobar 1 0 0 + +==Destruir BAR Branco +=destruirbar 1 0 + +==Destruir BAR Preto +=destruirbar 2 0 diff --git a/testlista.script b/testlista.script new file mode 100644 index 0000000..49a66d9 --- /dev/null +++ b/testlista.script @@ -0,0 +1,137 @@ +// Script: TesteLista.script +// Autor: Arndt von Staa, Felipe Vieira +// Data: 30/ago/2015 +// + +== Inicializar valores +=declararparm lista0 int 0 +=declararparm lista1 int 1 +=declararparm lista2 int 2 +=declararparm lista3 int 3 +=declararparm lista4 int 4 +=declararparm lista5 int 5 + +=declararparm str0 string "abcdefg" +=declararparm str1 string "qwerty" +=declararparm str2 string "xxx" +=declararparm str3 string "xpto" +=declararparm str4 string "1234" +=declararparm str5 string "oi!" + + +=declararparm OK int 0 +=declararparm ListaVazia int 1 +=declararparm FimLista int 2 +=declararparm NaoAchou int 3 +=declararparm FaltouMemoria int 4 + +=declararparm pNULL int 0 +=declararparm pNaoNULL int 1 + +== Criar a lista 0 +=criarlista lista0 + +== Verificar ObterValor relativo a lista vazia +=obtervalorelem lista0 "???" pNULL + +== Inserir elemento em lista vazia +=inselemantes lista0 str0 OK +=obtervalorelem lista0 str0 pNaoNULL + +== Inserir elemento após primeiro +=inselemapos lista0 str1 OK +=obtervalorelem lista0 str1 pNaoNULL + +== Inserir elemento antes do último +=inselemantes lista0 str2 OK +=obtervalorelem lista0 str2 pNaoNULL + +== Excluir elemento do meio +=obtervalorelem lista0 str2 pNaoNULL +=excluirelem lista0 OK + +== Excluir elemento do início +=obtervalorelem lista0 str0 pNaoNULL +=excluirelem lista0 OK + +== Excluir elemento final, único +=obtervalorelem lista0 str1 pNaoNULL +=excluirelem lista0 OK + +== Ver se a lista ficou vazia +=obtervalorelem lista0 "???" pNULL + +== Destruir a lista +=destruirlista lista0 + +== Criar uma lista com dois elementos +=criarlista lista1 +=inselemapos lista1 str0 OK +=inselemapos lista1 str1 OK + +== Esvaziar a lista e ver se ficou vazia +=esvaziarlista lista1 +=obtervalorelem lista1 "???" pNULL + +== Destruir a lista +=destruirlista lista1 + +== Criar uma lista com quatro elementos +=criarlista lista2 +=inselemapos lista2 str0 OK +=inselemapos lista2 str1 OK +=inselemapos lista2 str2 OK +=inselemapos lista2 str3 OK + +== Obter Tamanho da Lista Nao Vazia +=obtertamanho lista2 4 OK + +== Verificar a lista de trás para diante +=obtervalorelem lista2 str3 pNaoNULL +=avancarelem lista2 -1 OK +=obtervalorelem lista2 str2 pNaoNULL +=avancarelem lista2 -1 OK +=obtervalorelem lista2 str1 pNaoNULL +=avancarelem lista2 -1 OK +=obtervalorelem lista2 str0 pNaoNULL +=avancarelem lista2 -1 FimLista + +== Verificar a lista de frente para trás +=obtervalorelem lista2 str0 pNaoNULL +=avancarelem lista2 1 OK +=obtervalorelem lista2 str1 pNaoNULL +=avancarelem lista2 1 OK +=obtervalorelem lista2 str2 pNaoNULL +=avancarelem lista2 1 OK +=obtervalorelem lista2 str3 pNaoNULL +=avancarelem lista2 1 FimLista + +== Verificar a lista andando demais de trás para diante +=avancarelem lista2 -10 FimLista +=obtervalorelem lista2 str0 pNaoNULL + +== Verificar a lista andando demais de frente para trás +=avancarelem lista2 10 FimLista +=obtervalorelem lista2 str3 pNaoNULL + +== Destruir a lista +=destruirlista lista2 + +== Criar lista com 3 elementos +=criarlista lista3 +=inselemapos lista3 str0 OK +=inselemapos lista3 str1 OK +=inselemapos lista3 str2 OK + +== Ir Inicio da lista e obter string 0 +=irinicio lista3 +=obtervalorelem lista3 str0 pNaoNULL + +== Ir Final da lista e obter a strig 2 +=irfinal lista3 +=obtervalorelem lista3 str2 pNaoNULL + +== Destruir a lista +=destruirlista lista3 + +// fim From 221e6168c2db8e97495272f5a5176963cc9c8963 Mon Sep 17 00:00:00 2001 From: Tassio Date: Wed, 28 Oct 2015 20:23:04 -0200 Subject: [PATCH 2/2] asdads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Salva a sua main felipe esse é o meu. --- main.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 144 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index f10c500..905a00d 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,10 @@ void displayJogo(LIS_tppLista estrutura); LIS_tppLista carregaJogo(FILE** fp); void salvarJogo(LIS_tppLista estrutura); + void finalizarPeca(TAB_tppTabuleiro *pTab, PF_tppFinalizadas *pPF, int num); + /* Conta a quantidade de peças a partir da 'qtd'ultimas casas */ + int contaUltimasCasas(TAB_tppTabuleiro *pTab, char cor, int qtd); + int jogadordaVez; int main (void) { @@ -26,11 +30,13 @@ int main (void) PF_tppFinalizadas pfbranca, pfpreta; // pecas finalizadas BAR_tppCapturadas barbranca, barpreta; // pecas capturadas LIS_tppLista casas, casa; // lista de casas auxiliar usada no jogo - int dado1, dado2, dado3, dado4; // dados da partida + int dado1, dado2; // dados da partida tppDadoPontos dp; + int flag = 0; char preto = 'p', branco = 'b'; - int tampfb = 0, tampfp = 0, temp, tamanho, tambarb, tambarp; // tamanho da estrutura de pecas finalizadas, elas que determinam o termino do jogo - int casaEscolhida, opt[3] = {0,0,0}, contOpt = 0, i, j, k, opcao, opcaorestante; + int tampfb = 0, tampfp = 0,tamanho, tambarb, tambarp, ultCasas; // tamanho da estrutura de pecas finalizadas, elas que determinam o termino do jogo + int casaEscolhida, opt[3] = {0,0,0}, contOpt = 0, i, k = 0; + int opcao, opcaorestante; void* aux; char jogadordaVez, corObtida; int resp; @@ -116,11 +122,12 @@ int main (void) if(dado1 == dado2) goto JOGARDADO; // Dado1 corresponde ao jogador branco e dado2 corresponde ao jogador preto jogadordaVez = (dado1 > dado2)? 'b':'p'; - while(tampfp < 15 || tampfb < 15) + while(tampfp < 15 || tampfb < 15) { LABEL1: - printf("Jogador da vez eh o %s \n", (jogadordaVez == 'b')? "Branco" : "Preto"); + printf("Jogador da vez eh o %s \n", QUESTION "Branco" : "Preto"); printf("1: Jogar dados \n0: Salvar e Sair \n"); + flag = 0; scanf("%d", &resp); if(resp == 0) { @@ -136,10 +143,14 @@ int main (void) } displayJogo(Principal); printf("Jogador da vez eh o %s \n", QUESTION "Branco" : "Preto"); - printf("Dados : %d %d \n", dado1, dado2); + if(dado1 == dado2) + printf("Dados : %d %d %d %d \n", dado1, dado2, dado1, dado2); + else + printf("Dados : %d %d \n", dado1, dado2); // checa se a bar está com alguma peça, se sim, calcula as opções q ele tem com os dados jogados BAR_ObterTamanhoBar(barbranca, &tambarb); BAR_ObterTamanhoBar(barpreta,&tambarp); +DOBRADOBAR: if(((jogadordaVez == 'b') && (tambarb > 0)) || ((jogadordaVez == 'p') && (tambarp > 0))) // o jogador da vez tem peça no bar? { // calcula as opções do jogador @@ -246,6 +257,7 @@ int main (void) LIS_AvancarElementoCorrente(casas,QUESTION opt[opcao-1] -1: -opt[opcao-1] +1 ); casa = (LIS_tppLista)LIS_ObterValor(casas); aux = LIS_ObterValor(casa); + tamanho = LIS_ObterTamanho(casa); Pec_CriarPeca(&pecaAux, QUESTION branco : preto); if(tamanho == 1) { @@ -277,10 +289,10 @@ int main (void) // obtem o novo tamanho do BAR BAR_ObterTamanhoBar(barbranca, &tambarb); BAR_ObterTamanhoBar(barpreta,&tambarp); + opt[opcao - 1] = 0; if(((jogadordaVez == 'b') && (tambarb > 0)) || ((jogadordaVez == 'p') && (tambarp > 0))) { displayJogo(Principal); - opcaorestante = (opt[opcao - 1] == dado1)? dado2 : dado1; for( i = 0; i < 2; i++) { if(opt[i] == 0) continue; else break; @@ -307,8 +319,9 @@ int main (void) } goto LABEL1; } - printf("Dado Restante : %d \n", opcaorestante); - opt[opcao-1] = 0; + opcaorestante = (opt[opcao - 1] == dado1)? dado2 : dado1; + if((dado1 == dado2) && !flag) printf("Dados Restantes : %d %d %d \n", dado1, dado2, dado2); + else printf("Dado Restante : %d \n", opcaorestante); // mover a peça do bar para o tabuleiro printf("1: Mover a peca do BAR para a casa %d \n", QUESTION opcaorestante : 25 - opcaorestante); ESCOLHAOPCAO4: @@ -326,10 +339,11 @@ int main (void) return 0; } QUESTION IrInicioLista(casas) : IrFinalLista(casas); - LIS_AvancarElementoCorrente(casas,QUESTION opcaorestante -1: opcaorestante +1 ); + LIS_AvancarElementoCorrente(casas,QUESTION opcaorestante -1: -opcaorestante +1 ); casa = (LIS_tppLista)LIS_ObterValor(casas); aux = LIS_ObterValor(casa); Pec_CriarPeca(&pecaAux, QUESTION branco : preto); + tamanho = LIS_ObterTamanho(casa); if(tamanho == 1) { Pec_ObterCor((tppPeca)aux, &corObtida); @@ -360,6 +374,15 @@ int main (void) // acabou a vez do jogador de tirar as peças do bar (trocar de jogador) BAR_ObterTamanhoBar(barbranca, &tambarb); BAR_ObterTamanhoBar(barpreta,&tambarp); + if((dado1 == dado2) && !flag) + { + displayJogo(Principal); + printf("Jogador da vez eh o %s \n", (jogadordaVez == 'b')? "Branco" : "Preto"); + printf("Dados : %d %d \n", dado1, dado2); + flag = 1; + for(i = 0; i < 2; i++) opt[i] = 0; + goto DOBRADOBAR; + } jogadordaVez = QUESTION 'p' : 'b'; contOpt = 0; for(i = 0; i < 3; i++) @@ -377,11 +400,77 @@ int main (void) printf("Erro ao jogar o dado (main) \n"); return 0; } + displayJogo(Principal); goto LABEL1; } goto OPCAORESTANTE; } - printf("Escolha de qual casa deseja andar \n"); +DOBRADO: + ultCasas = contaUltimasCasas(&tabuleiro, jogadordaVez, 6); + if((ultCasas + QUESTION tampfb : tampfp) == 15) + { + // ve se pode finalizar + IrInicioLista(casas); + LIS_AvancarElementoCorrente(casas, QUESTION dado1 -1 : -dado1 + 1); + casa = (LIS_tppLista)LIS_ObterValor(casas); + aux = LIS_ObterValor(casa); + contOpt = 2; + if(aux != NULL) + { + Pec_ObterCor((tppPeca)aux, &corObtida); + if(corObtida == jogadordaVez) + { + opt[contOpt] = dado1; + contOpt++; + } + } + if((aux == NULL) || corObtida != jogadordaVez) + { + ultCasas = contaUltimasCasas(&tabuleiro, jogadordaVez, dado1); + if((ultCasas + QUESTION tampfb : tampfp) == 15) + { + while((aux == NULL) || corObtida != jogadordaVez) + { + LIS_AvancarElementoCorrente(casas, QUESTION 1 : -1); + casa = (LIS_tppLista)LIS_ObterValor(casas); + aux = LIS_ObterValor(casa); + k++; + } + opt[contOpt] = k; + contOpt++; + } + } + IrInicioLista(casas); + LIS_AvancarElementoCorrente(casas, QUESTION dado2 -1 : -dado2 + 1); + casa = (LIS_tppLista)LIS_ObterValor(casas); + aux = LIS_ObterValor(casa); + if(aux != NULL) + { + Pec_ObterCor((tppPeca)aux, &corObtida); + if(corObtida == jogadordaVez) + { + opt[contOpt] = dado2; + contOpt++; + } + } + if((aux == NULL) || corObtida != jogadordaVez) + { + ultCasas = contaUltimasCasas(&tabuleiro, jogadordaVez, dado2); + if((ultCasas + QUESTION tampfb : tampfp) == 15) + { + while((aux == NULL) || corObtida != jogadordaVez) + { + LIS_AvancarElementoCorrente(casas, QUESTION 1 : -1); + casa = (LIS_tppLista)LIS_ObterValor(casas); + aux = LIS_ObterValor(casa); + k++; + } + opt[contOpt] = k; + contOpt++; + } + } + } + printf("Escolha de qual casa deseja andar \n"); ESCOLHADECASA: scanf("%d", &casaEscolhida); IrInicioLista(casas); @@ -425,7 +514,6 @@ int main (void) } // a casa é valida // agora é saber as opçoes que o jogador tem - // ordena os dados, dado1 < dado2 LIS_AvancarElementoCorrente(casas, QUESTION dado1 : -dado1); // avanca para a posicao dado1 casa = (LIS_tppLista)LIS_ObterValor(casas); aux = LIS_ObterValor(casa); @@ -482,16 +570,22 @@ int main (void) } } } + // o bizu está aqui,... para finalziar as peças for(i = 0; i < 3; i++) { if(((jogadordaVez == 'b') && (opt[i] + casaEscolhida > 24)) || ((casaEscolhida - opt[i] < 1) && (jogadordaVez == 'p'))) opt[i] = 0; } - if(opt[0] == 0) + if((opt[0] == 0) && (opt[1] == 0)) { printf("Nao ha opcoes, escolha outra casa \n"); goto ESCOLHADECASA; } + if((opt[0] == 0) && (opt[1] != 0)) + { + opt[0] = opt[1]; + opt[1] = 0; + } for(i = 0; opt[i] != 0; i++) { if(opt[i] == 0) continue; @@ -552,7 +646,8 @@ int main (void) OPCAORESTANTE: displayJogo(Principal); opcaorestante = (opt[opcao - 1] == dado1)? dado2 : dado1; - printf("Dado Restante : %d \n", opcaorestante); + if((dado1 == dado2) && !flag) printf("Dados Restantes : %d %d %d\n", dado1, dado2, dado1); + else printf("Dado Restante : %d \n", opcaorestante); opt[opcao-1] = 0; // jogador escolhe outra casa e repete-se o procedimento ESCOLHADECASA1: @@ -690,7 +785,13 @@ int main (void) } } displayJogo(Principal); -JOGARDADO1: + if((dado1 == dado2) && !flag) + { + printf("Dados : %d %d \n", dado1, dado2); + flag = 1; + for(i = 0; i < 2; i++) opt[i] = 0; + goto DOBRADO; + } if(DAD_NumPular(&dado1) != DAD_CondRetOK) { printf("Erro ao jogar o dado (main) \n"); @@ -702,8 +803,6 @@ int main (void) printf("Erro ao jogar o dado (main) \n"); return 0; } - // se os dois valores forem iguais - if(dado1 == dado2) goto JOGARDADO1; jogadordaVez = QUESTION 'p' : 'b'; contOpt = 0; for(i = 0; i < 3; i++) @@ -1098,6 +1197,34 @@ LIS_tppLista carregaJogo(FILE** fp) return estrutura; fclose(*fp); } +void finalizarPeca(TAB_tppTabuleiro *pTab, PF_tppFinalizadas *pPF, int num) +{ + LIS_tppLista casas, casa; + char corpf; + TAB_ObterCasas(*pTab, &casas); + PF_ObterCorPF(*pPF, &corpf); + (corpf == 'b')? IrInicioLista(casas) : IrFinalLista(casas); + LIS_AvancarElementoCorrente(casas,(corpf == 'b')? num - 1 : -num + 1); + casa = (LIS_tppLista)LIS_ObterValor(casas); + LIS_ExcluirElemento(casa); + PF_AdicionarPeca(*pPF); +} +int contaUltimasCasas(TAB_tppTabuleiro *pTab, char cor, int qtd) +{ + int cont = 0, i; + LIS_tppLista casa, casas; + TAB_ObterCasas(*pTab, &casas); + (cor == 'b')? IrInicioLista(casas) : IrFinalLista(casas); + for(i = 0; i < qtd; i++) + { + casa = (LIS_tppLista)LIS_ObterValor(casas); + cont += LIS_ObterTamanho(casa); + LIS_AvancarElementoCorrente(casas, (cor == 'b')? 1:-1); + } + return cont; +} + +