void eleventhTestCase01(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxToPush; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } pAuxToPush = newEmployee(id[5],unsortedList[5],unsortedList[5],salary[5],sector[5]); r = list->push(list,i-1,pAuxToPush); utest_assertEqualsIntMsg(r,0,"Error in return value <push> if ok the correct value to return is 0"); free(list); free(pAuxToPush); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void seventhTestCase04(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxToSet; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } pAuxToSet = newEmployee(id[5],unsortedList[5],unsortedList[5],salary[5],sector[5]); r = list->set(NULL,0,pAuxToSet); utest_assertEqualsIntMsg(r,-1,"Error in return value <set> if the pointer to the new Element is NULL the correct value to return is -1"); free(list); }
/** \brief Carga 4 empleados para caso de prueba inicial * * \param pList ArrayList* array donde se caragran los empleados * \return void * */ void loader(ArrayList* pList) { pList->add(pList,newEmployee(1,"nahuel","Claret",2334689.5)); pList->add(pList,newEmployee(2,"Sheldom","Cooper",22.5)); pList->add(pList,newEmployee(3,"Barney","Stinson",25542.5)); pList->add(pList,newEmployee(4,"Pedro","Picapiedra",2992.5)); pList->size=4; }
void fifthTestCase01(void) { int i; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxGet; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } for(i=0; i < LENGTH; i++) { pAuxGet = list->get(list,i); utest_assertNotNullMsg(pAuxGet,"Error in return value <get> if ok the correct value to return is not NULL"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void twelfthTestCase02(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } for(i=0; i < LENGTH; i++) { r = list->indexOf(list,pAux[i]); utest_assertEqualsIntMsg(r,i,"Error in return value <indexOf> the correct value to return is the index"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void TableContractModel::setTableModelUp() { Role hackRole = newRole(0, 0, 0, 0, tr("Role description")); this->iInsertedRole.setValue(hackRole); if(!this->insertRows(0,1, QModelIndex())) qDebug() << "hackRole insert problems"; //setData(this->index(0, QModelIndex(), QVariant(), Qt::EditRole); Employee hackEmployee = newEmployee(tr("Employee's Name"), tr("000000-0000")); this->iInsertedEmployee.setValue(hackEmployee); if(!this->insertRows(1,1, QModelIndex())) qDebug() << "hackEmployee insert problems"; //setData(QModelIndex(), QVariant(), Qt::EditRole); Contract hackContract = newContract(hackRole.iRoleId, hackEmployee.iEmployeeId); this->iInsertedContract.setValue(hackContract); if(!this->insertRows(2,1, QModelIndex())) qDebug() << "hackContract insert problems"; //setData(QModelIndex(), QVariant(), Qt::EditRole); Work hackWork = newWork(hackContract.iContractId,0,0,0); this->iInsertedWork.setValue(hackWork); if(!this->insertRows(3,1, QModelIndex())) qDebug() << "hackWork insert problems"; //setData(QModelIndex(), QVariant(), Qt::EditRole); }
Employee* pushEmployee(int* Index, ArrayList* lista) { int auxId; int auxInt; int auxIndex; char auxName[52]; char auxLastname[52]; int i; Employee* auxEmployee = NULL; Employee* isEmployee; if(lista != NULL) { auxInt = getInt(&auxIndex, "Ingrese el indice: ", "ERROR: Numero no valido", 0, 1001); if(auxInt !=0) { return NULL; } *Index = auxIndex; datosEmployee(&auxId, auxName, auxLastname); for(i=0; i<lista->len(lista); i++) { isEmployee = (Employee*) al_get(lista, i); if(isEmployee->id == auxId) { printf("Ya existe alguien con ese id!\n"); return auxEmployee; } } auxEmployee = newEmployee(auxId, auxName, auxLastname); } return auxEmployee; }
void seventeenthTestCase02(void) { int i; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxGet[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } list->sort(list, compareEmployee,0); for(i=0; i < LENGTH; i++) { pAuxGet[i] = list->get(list,i); utest_assertNotNullMsg(pAuxGet[i],"Error in return value <get> if ok the correct value to return is not NULL"); } for (i=0;i < LENGTH;i++) { utest_assertEqualsFloatMsg(((Employee*)pAuxGet[i])->salary,salarySortedUp[i],"Error value in <.salary> after sort"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void eighthTestCase02(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } for(i=LENGTH-1; i >=0 ; i--) { r = list->remove(list,0); utest_assertEqualsIntMsg(r,0,"Error in return value <remove(list,0)> if ok the correct value to return is 0"); } utest_assertEqualsIntMsg(list->size,0,"Error in the size of the array, after remove all the elements the correct value is 0"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void TableContractModel::addEmployee(QString aName, QString aSocialSecurityNumber) { Employee hackEmployee = newEmployee(aName,aSocialSecurityNumber); this->iInsertedEmployee.setValue(hackEmployee); if(!this->insertRows(typeRow(1),1, QModelIndex())) qDebug() << "addEmployee insert problems"; }
void seventhTestCase02(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxToSet; Employee* pAuxGet; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } pAuxToSet = newEmployee(id[5],unsortedList[5],unsortedList[5],salary[5],sector[5]); for(i=0; i < LENGTH; i++) { r = list->set(list,i,pAuxToSet); utest_assertEqualsIntMsg(r,0,"Error in return value <set> if ok the correct value to return is 0"); } for (i=0;i < LENGTH;i++) { pAuxGet = list->get(list,i); utest_assertEqualsIntMsg(((Employee*)pAuxGet)->id,id[5],"Error value in <.id>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet)->name,unsortedList[5],2,"Error value in <.name>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet)->lastName,unsortedList[5],2,"Error value in <.lastName>"); utest_assertEqualsFloatMsg(((Employee*)pAuxGet)->salary,salary[5],"Error value in <.salary>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet)->sector,sector[5],"Error value in <.sector>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet)->isEmpty,0,"Error value in <.isEmpty> the correct value is: (0)"); } free(list); free(pAuxToSet); for(i=0; i < LENGTH; i++) free(pAux[i]); }
Employee * readEmployeeRecord(FILE *fp) // we pass the file pointer in { char *name,*title; int years; double salary; name = readString(fp); //name is a string, not a token if (feof(fp)) { return 0; } // no record, return the null pointer name = name; title = readToken(fp); years = readInt(fp); salary = readReal(fp); return newEmployee(name,title,years,salary); }
/** \brief SOlicita los datos para un nuevo empleado * * \param pList ArrayList* Recibe el arraylist del cual se usaran algunos datos como el size * \return eEmployee* devuelve un empleado para que el mismo se cargue con newEmployee * */ eEmployee* loadEmployee(ArrayList* pList) { eEmployee* returnAux=NULL; char name[20]; char lastName[20]; float salary; // int a=*(id); if(pList!=NULL) { if(getString(name,"Ingrese el nombre:",1,20)!=-1&&getString(lastName,"Ingrese apellido: ",1,20)!=-1) { printf("Ingrese el sueldo: "); scanf("%f",&salary); returnAux=newEmployee(pList->size+1,name,lastName,salary); } } return returnAux; }
void twelfthTestCase04(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->indexOf(list,NULL); utest_assertEqualsIntMsg(r,-1,"Error in return value <indexOf> if the pointer to Element is NULL the correct value to return is -1"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void eighthTestCase03(void) { int i, r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->set(list,9); utest_assertEqualsIntMsg(r,-1,"Error in return value <remove> if the index is invalid the correct value to return is -1"); free(list); }
void seventeenthTestCase01(void) { int i,r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->sort(list, compareEmployee,1); utest_assertEqualsIntMsg(r, 0 ,"Error in return value of <sort> if the list is contained the correct value is 1"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void seventeenthTestCase04(void) { int i,r; ArrayList* list; Employee* pAux[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->add(list,pAux[i]); } r = list->sort(list, NULL,1); utest_assertEqualsIntMsg(r, -1 ,"Error in return value of <sort> if the pointer to Function is Null the correct value is -1"); free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
void eleventhTestCase02(void) { int i; ArrayList* list; Employee* pAux[LENGTH]; Employee* pAuxGet[LENGTH]; list = al_newArrayList(); for(i=0; i < LENGTH; i++) { pAux[i] = newEmployee(id[i],unsortedList[i],unsortedList[i],salary[i],sector[i]); list->push(list,i,pAux[i]); pAuxGet[i] = list->get(list,i); utest_assertNotNullMsg(pAuxGet[i],"Error in return value <get> if ok the correct value to return is not NULL"); } for (i=0;i < LENGTH;i++) { utest_assertEqualsIntMsg(((Employee*)pAuxGet[i])->id,id[i],"Error value in <.id>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet[i])->name,unsortedList[i],2,"Error value in <.name>"); utest_assertEqualsStringMsg(((Employee*)pAuxGet[i])->lastName,unsortedList[i],2,"Error value in <.lastName>"); utest_assertEqualsFloatMsg(((Employee*)pAuxGet[i])->salary,salary[i],"Error value in <.salary>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet[i])->sector,sector[i],"Error value in <.sector>"); utest_assertEqualsIntMsg(((Employee*)pAuxGet[i])->isEmpty,0,"Error value in <.isEmpty> the correct value is: (0)"); } free(list); for(i=0; i < LENGTH; i++) free(pAux[i]); }
int run2(void) { // Genero personas para usar en el ArrayList Employee* p0 = newEmployee(14, "JUAN1" ,"LOPEZ", 133.22,5); Employee* p1 = newEmployee(14, "JUAN2" ,"LOPEZ", 233.22,5); Employee* p2 = newEmployee(14, "JUAN3" ,"LOPEZ", 333.22,5); Employee* p3 = newEmployee(14, "JUAN4" ,"LOPEZ", 433.22,5); printEmployee(p0); printEmployee(p1); printEmployee(p2); printEmployee(p3); //__________________________________________ printf("\r\nCargo ArraList...\r\n"); ArrayList* lista = al_newArrayList(); lista->add(lista,p0); lista->add(lista,p1); lista->add(lista,p2); al_add(lista,p3); // forma no orientada a objetos printArrayListEmployee(lista); printf("\r\nRemuevo index 2\r\n"); lista->remove(lista,2); printArrayListEmployee(lista); printf("\r\nContiene p0 ?\r\n"); if(lista->contains(lista,p0)) printf("SI"); else printf("NO"); printf("\r\nContiene p2 ?\r\n"); if(lista->contains(lista,p2)) printf("SI"); else printf("NO"); printf("\r\nAgrego p2 en la posicion 1\r\n"); lista->set(lista,1,p2); // vuelvo a agregar p2 printArrayListEmployee(lista); printf("\r\nClonamos array\r\n"); ArrayList* lista2 = lista->clone(lista); printf("Lista original:%p\r\n",lista); printArrayListEmployee(lista); printf("Lista Clonada:%p\r\n",lista2); printArrayListEmployee(lista2); lista2->sort(lista2, compareEmployee,1); printf("Lista Clonada Ordenada por Edad (UP):%p\r\n",lista2); printArrayListEmployee(lista2); lista2->sort(lista2, compareEmployee,0); printf("Lista Clonada Ordenada por Edad (DOWN):%p\r\n",lista2); printArrayListEmployee(lista); printf("\r\nlista clonada contiene lista?:"); if(lista->containsAll(lista,lista2)) printf("SI"); else printf("NO"); printf("\r\n\r\nPosicion de p2:"); int index = lista->indexOf(lista,p2); printf("%d\r\n",index); printf("\r\nPosicion de p1:"); index = lista->indexOf(lista,p1); printf("%d\r\n",index); printf("\r\n\r\nHacemos push de p1 en la posicion 1\r\n"); lista->push(lista,1,p1); printArrayListEmployee(lista); printf("\r\nObtenemos sub-lista de 1 a 2\r\n"); ArrayList* subLista = lista->subList(lista,1,2); printArrayListEmployee(subLista); printf("\r\n\r\nHacemos pop de p1 en la posicion 1\r\n"); Employee* p1Aux = lista->pop(lista,1); printf("Elemento pop(): %s\r\n",p1Aux->name); printArrayListEmployee(lista); printf("\r\nClear array\r\n"); lista->clear(lista); printArrayListEmployee(lista); printf("\r\nEsta vacio?\r\n"); if(lista->isEmpty(lista)) printf("SI"); else printf("NO"); // Test expansion/contraccion del size printf("\r\n\r\nTest size\r\n"); int j; for(j=0; j<1100; j++) { Employee* pAux = malloc(sizeof(Employee)); sprintf(pAux->name,"Juan %d",j); pAux->salary=j; lista->add(lista,pAux); } printf("Cantidad de elementos:%d\r\n",lista->len(lista)); //printArrayListPersonas(lista); for(j=0; j<1100; j++) { lista->pop(lista,0); } printf("Cantidad de elementos:%d\r\n",lista->len(lista)); //printArrayListPersonas(lista); //____________________________________ printf("\r\nLibero memoria y termino\r\n"); free(p0); free(p1); free(p2); free(p3); lista->deleteArrayList(lista); lista2->deleteArrayList(lista2); system("PAUSE"); return 0; }
int main() { int r,i; int *auxInt = malloc(sizeof(int)); float *auxFloat = malloc(sizeof(float)); int *auxIndex = malloc(sizeof(int)); int choice; Employee *pEmployee = malloc(sizeof(Employee)); Employee *pEmployee2 = malloc(sizeof(Employee)); ArrayList *nomina; ArrayList *nominaCloned; ArrayList *nominaFilter; nomina = al_newArrayList(); r = importFile(nomina,"Nomina.txt"); do { choice = menu("\n*************** TP 4 - CANEPA ***************\n\n" "1- Agregar empleado\n2- Modificar empleado\n" "3- Borrar empleado\n4- Listar\n" "5- PUSH empleado\n6- Listar por salario\n" "7- Listar por Nombre\n8- Filtrar salarios\n" "9- Borrar todos\n10- Guardar y Salir\n"); switch(choice) { case 1: system("cls"); pEmployee = newEmployee(); pEmployee2 = searchEmployee(nomina,auxIndex,pEmployee->id); if(pEmployee2 == NULL) { nomina->add(nomina,pEmployee); } else { printf("Error. El legajo ya existe."); printEmployee(pEmployee2,*auxIndex); } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); break; case 2: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"Ingrese el legajo a editar: ","ERROR",1, 99999999); pEmployee = searchEmployee(nomina,auxIndex,*auxInt); if(pEmployee == NULL) { printf("El legajo no existe."); } else { pEmployee2 = editEmployee(pEmployee); printf("Valor Original:\nPosicion: %d\tLegajo: %d\tNombre:%s\tSalario:%.2f\tSector: %d\n\n",*auxIndex,pEmployee->id,pEmployee->name,pEmployee->salary,pEmployee->sector); printf("Nuevo valor: \nPosicion: %d\tLegajo: %d\tNombre:%s\tSalario:%.2f\tSector: %d\n\n",*auxIndex,pEmployee2->id,pEmployee2->name,pEmployee2->salary,pEmployee2->sector); if(validaDecision("Confirma modificacion? S/N ")==0) nomina->set(nomina,*auxIndex,pEmployee2); } system("pause"); break; case 3: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"Ingrese el legajo a eliminar: ","ERROR",1, 99999999); pEmployee = searchEmployee(nomina,auxIndex,*auxInt); if(pEmployee == NULL) { printf("El legajo no existe."); } else { printf("Se eliminira:\nPosicion: %d\tLegajo: %d\tNombre:%s\tSalario:%.2f\tSector: %d\n\n",*auxIndex,pEmployee->id,pEmployee->name,pEmployee->salary,pEmployee->sector); if(validaDecision("Confirma eliminacion? S/N ")==0) nomina->pop(nomina,*auxIndex); } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); break; case 4: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } Employee *pEmployeeOr = malloc(sizeof(Employee)); for(i=0;i<nomina->size;i++) { pEmployeeOr = nomina->get(nomina,i); printEmployee(pEmployeeOr,i); } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); break; case 5: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } pEmployee = newEmployee(); getInt(auxInt,"\nIngrese la posicion donde desea ingresar: ","ERROR",0, nomina->size); nomina->push(nomina,*auxInt,pEmployee); r = nomina->len(nomina); printf("\nCantidad de empleados: %d\n\n",r); system("pause"); break; case 6: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"\n1: Ascendente\n0: Descendente\n\nElija el orden: ","ERROR",0, 1); nominaCloned = nomina->clone(nomina); r = nomina->containsAll(nomina,nominaCloned); if(r != 0) { for(i=0;i<nominaCloned->size;i++) { pEmployee = nominaCloned->get(nominaCloned,i); printEmployee(pEmployee,i); } } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); nominaCloned->deleteArrayList(nominaCloned); break; case 7: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getInt(auxInt,"\n1: Ascendente\n0: Descendente\n\nElija el orden: ","ERROR",0, 1); nominaCloned = nomina->clone(nomina); r = nominaCloned->sort(nominaCloned,compareEmployeeName,*auxInt); r = nomina->containsAll(nomina,nominaCloned); if(r != 0) { for(i=0;i<nominaCloned->size;i++) { pEmployee = nominaCloned->get(nominaCloned,i); printEmployee(pEmployee,i); } } r = nomina->len(nomina); printf("Cantidad de empleados: %d\n\n",r); system("pause"); nominaCloned->deleteArrayList(nominaCloned); break; case 8: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } getFloat(auxFloat,"\nSalarios mayores a:","ERROR",1, 99999999); nominaCloned = nomina->clone(nomina); nominaCloned->sort(nominaCloned,compareEmployee,0); //sort descendente por salario r = nomina->containsAll(nomina,nominaCloned); *auxInt = -1; if(r != 0) { for(i=0;i<nominaCloned->size;i++) { pEmployee = nominaCloned->get(nominaCloned,i); if(pEmployee->salary >= *auxFloat) { *auxInt = i; } } } if(*auxInt >= 0) { nominaFilter = nominaCloned->subList(nominaCloned,0,*auxInt); for(i=0;i<nominaFilter->size;i++) { pEmployee = nominaFilter->get(nominaFilter,i); printEmployee(pEmployee,i); } } r = nominaFilter->len(nominaFilter); printf("Cantidad de empleados con salario mayor a %.2f: %d\n\n",*auxFloat,r); system("pause"); nominaCloned->deleteArrayList(nominaCloned); nominaFilter->deleteArrayList(nominaFilter); break; case 9: system("cls"); if(nomina->isEmpty(nomina) != 0) { printf("Error. Primero ingrese empleados."); break; } nomina->clear(nomina); system("pause"); break; case 10: system("cls"); createTxt(nomina); nomina->deleteArrayList(nomina); break; default: system("cls"); printf("\nOpcion invalida. Reingrese.\n"); system("pause"); break; } system("cls"); } while (choice != 10); return 0; }