add test and modification on queue
This commit is contained in:
parent
8bd977ba62
commit
5e57356f85
|
@ -6,8 +6,8 @@ enable_testing()
|
||||||
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
||||||
|
|
||||||
add_executable(exect fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c)
|
add_executable(exect fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c)
|
||||||
|
|
||||||
# add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c)
|
# add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c)
|
||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
target_link_libraries(exect ${CMAKE_THREAD_LIBS_INIT} m)
|
target_link_libraries(exect ${CMAKE_THREAD_LIBS_INIT} m)
|
||||||
|
|
||||||
|
@ -18,10 +18,19 @@ add_executable(ctest fileGestion.c getArray.c average.c growthRate.c queue.c sim
|
||||||
target_link_libraries(ctest ${CMAKE_THREAD_LIBS_INIT} m)
|
target_link_libraries(ctest ${CMAKE_THREAD_LIBS_INIT} m)
|
||||||
|
|
||||||
add_test(test_queueCreateEmpty ./ctest queueCreateEmpty)
|
add_test(test_queueCreateEmpty ./ctest queueCreateEmpty)
|
||||||
add_test(test_queueSetCharLen ./ctest queueSetCharLen)
|
add_test(test_queueCreateE ./ctest queueCreateE)
|
||||||
|
|
||||||
|
add_test(test_queueSetCharLen ./ctest queueSetCharLen)
|
||||||
|
add_test(test_queueGetCharLen ./ctest queueGetCharLen)
|
||||||
|
|
||||||
|
add_test(test_queueSetTabChar ./ctest queueSetTabChar)
|
||||||
|
add_test(test_queueGetTabChar ./ctest queueGetTabChar)
|
||||||
|
|
||||||
# add_test(test_queueGetTabChar ./ctest queueGetTabChar)
|
|
||||||
add_test(test_queueSetNextE ./ctest queueSetNextE)
|
add_test(test_queueSetNextE ./ctest queueSetNextE)
|
||||||
add_test(test_queueGetNextE ./ctest queueGetNextE)
|
add_test(test_queueGetNextE ./ctest queueGetNextE)
|
||||||
|
|
||||||
add_test(test_queueGetCharLen ./ctest queueGetCharLen)
|
add_test(test_queueAddLastQ ./ctest queueAddLastQ)
|
||||||
|
add_test(test_queueRmLastE ./ctest queueRmLastE)
|
||||||
|
add_test(test_queueRmFrstE ./ctest queueRmFrstE)
|
||||||
|
add_test(test_queueNextDelFrst ./ctest queueNextDelFrst)
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,15 @@
|
||||||
* @param p array with all the values that will be used for the calcul
|
* @param p array with all the values that will be used for the calcul
|
||||||
* @param averageArray array where results are stocked
|
* @param averageArray array where results are stocked
|
||||||
*/
|
*/
|
||||||
void averageCalculation(long **p, double averageArray[]){
|
void averageCalculation(long **p, double averageArray[])
|
||||||
for(int i = 1; i < nCol; i++){
|
{
|
||||||
|
for (int i = 1; i < nCol; i++)
|
||||||
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
averageArray[i] = 0;
|
averageArray[i] = 0;
|
||||||
while(j < nRowRawData){
|
while (j < nRowRawData)
|
||||||
averageArray[i] += p[i][j];
|
{
|
||||||
|
averageArray[i - 1] += p[i][j];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
// printf("%f , %f\n", averageArray[i] , averageArray[i] / nRowRawData);
|
// printf("%f , %f\n", averageArray[i] , averageArray[i] / nRowRawData);
|
||||||
|
@ -27,15 +30,21 @@ void averageCalculation(long **p, double averageArray[]){
|
||||||
*
|
*
|
||||||
* @param rawDataFileName name of the raw data file to use to realize the calcul
|
* @param rawDataFileName name of the raw data file to use to realize the calcul
|
||||||
*/
|
*/
|
||||||
void averageFunction(char* rawDataFileName , double **aver){
|
void averageFunction(char *rawDataFileName, double **aver)
|
||||||
|
{
|
||||||
long **p = getRawDataArray(rawDataFileName);
|
long **p = getRawDataArray(rawDataFileName);
|
||||||
double averN[nCol - 1];
|
double averN[nCol - 1];
|
||||||
if(p !=NULL){
|
if (p != NULL)
|
||||||
if(p !=NULL){
|
{
|
||||||
if(aver == NULL){
|
if (p != NULL)
|
||||||
|
{
|
||||||
|
if (aver == NULL)
|
||||||
|
{
|
||||||
averageCalculation(p, averN);
|
averageCalculation(p, averN);
|
||||||
appendDataInFile("averageData.csv", averN, nCol - 1);
|
appendDataInFile("averageData.csv", averN, nCol - 1);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
averageCalculation(p, aver[1]);
|
averageCalculation(p, aver[1]);
|
||||||
appendDataInFile("averageData.csv", aver[1], nCol - 1);
|
appendDataInFile("averageData.csv", aver[1], nCol - 1);
|
||||||
}
|
}
|
||||||
|
|
142
Code-C/ctest.c
142
Code-C/ctest.c
|
@ -48,6 +48,22 @@ bool test_queueCreateEmpty()
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool test_queueCreateE()
|
||||||
|
{
|
||||||
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
|
Pqueue new = queueCreateE(12, tabChar);
|
||||||
|
|
||||||
|
const char *test = queueGetTabChar(new);
|
||||||
|
|
||||||
|
assert(queueGetCharLen(new) == 12);
|
||||||
|
assert(test != NULL);
|
||||||
|
assert(strcmp(test, tabChar) == 0);
|
||||||
|
assert(queueGetNextE(new) == NULL);
|
||||||
|
|
||||||
|
queueRmFrstE(new);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
bool test_queueSetCharLen()
|
bool test_queueSetCharLen()
|
||||||
{
|
{
|
||||||
Pqueue new = queueCreateEmpty();
|
Pqueue new = queueCreateEmpty();
|
||||||
|
@ -63,20 +79,38 @@ bool test_queueSetCharLen()
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_queueGetTabChar()
|
bool test_queueSetTabChar()
|
||||||
{ // Define later
|
{
|
||||||
|
// Set and Get tabChar are similar because use for same test
|
||||||
Pqueue new = queueCreateEmpty();
|
Pqueue new = queueCreateEmpty();
|
||||||
|
|
||||||
// const char tabChar[12] = "PetitNavire\0"
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
queueSetTabChar(new, 13, NULL);
|
queueSetTabChar(new, 12, tabChar);
|
||||||
|
const char *test = queueGetTabChar(new);
|
||||||
|
|
||||||
assert(queueGetCharLen(new) == 13);
|
assert(queueGetCharLen(new) == 12);
|
||||||
assert(queueGetTabChar(new) == NULL);
|
assert(test != NULL);
|
||||||
|
assert(strcmp(test, tabChar) == 0);
|
||||||
assert(queueGetNextE(new) == NULL);
|
assert(queueGetNextE(new) == NULL);
|
||||||
|
|
||||||
// queueDelAll(new);
|
|
||||||
queueRmFrstE(new);
|
queueRmFrstE(new);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool test_queueGetTabChar()
|
||||||
|
{
|
||||||
|
Pqueue new = queueCreateEmpty();
|
||||||
|
|
||||||
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
|
queueSetTabChar(new, 12, tabChar);
|
||||||
|
const char *test = queueGetTabChar(new);
|
||||||
|
|
||||||
|
assert(queueGetCharLen(new) == 12);
|
||||||
|
assert(test != NULL);
|
||||||
|
assert(strcmp(test, tabChar) == 0);
|
||||||
|
assert(queueGetNextE(new) == NULL);
|
||||||
|
|
||||||
|
queueRmFrstE(new);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +154,70 @@ bool test_queueGetCharLen()
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool test_queueAddLastQ()
|
||||||
|
{
|
||||||
|
Pqueue new = queueCreateEmpty(), next = NULL;
|
||||||
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
next = queueGetNextE(new);
|
||||||
|
|
||||||
|
assert(next != NULL);
|
||||||
|
assert(queueGetCharLen(next) == 12);
|
||||||
|
assert(strcmp(queueGetTabChar(next), tabChar) == 0);
|
||||||
|
assert(queueGetNextE(next) == NULL);
|
||||||
|
|
||||||
|
queueDelAll(new);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
bool test_queueRmLastE()
|
||||||
|
{
|
||||||
|
Pqueue new = queueCreateEmpty();
|
||||||
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
|
||||||
|
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
|
||||||
|
queueRmLastE(new);
|
||||||
|
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) == NULL);
|
||||||
|
|
||||||
|
queueDelAll(new);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool test_queueRmFrstE()
|
||||||
|
{
|
||||||
|
Pqueue new = queueCreateEmpty(), second;
|
||||||
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
second = queueGetNextE(new);
|
||||||
|
|
||||||
|
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
|
||||||
|
new = queueRmFrstE(new);
|
||||||
|
assert((new == second) && (queueGetNextE(new) != NULL) && (queueGetNextE(queueGetNextE(new)) == NULL));
|
||||||
|
|
||||||
|
queueDelAll(new);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool test_queueNextDelFrst()
|
||||||
|
{
|
||||||
|
Pqueue new = queueCreateEmpty(), second;
|
||||||
|
const char tabChar[12] = "PetitNavire\0";
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
queueAddLastQ(new, tabChar, 12);
|
||||||
|
second = queueGetNextE(new);
|
||||||
|
|
||||||
|
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
|
||||||
|
new = queueNextDelFrst(new);
|
||||||
|
assert((new == second) && (queueGetNextE(new) != NULL) && (queueGetNextE(queueGetNextE(new)) == NULL));
|
||||||
|
|
||||||
|
queueDelAll(new);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************** Main test start *****************/
|
||||||
|
|
||||||
void usage(int argc, char *argv[])
|
void usage(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
|
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
|
||||||
|
@ -135,7 +233,13 @@ int main(int argc, char *argv[])
|
||||||
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
|
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
if (strcmp("queueCreateEmpty", argv[1]) == 0)
|
if (strcmp("queueCreateEmpty", argv[1]) == 0)
|
||||||
|
{
|
||||||
ok = test_queueCreateEmpty();
|
ok = test_queueCreateEmpty();
|
||||||
|
}
|
||||||
|
else if (strcmp("queueCreateE", argv[1]) == 0)
|
||||||
|
{
|
||||||
|
ok = test_queueCreateE();
|
||||||
|
}
|
||||||
else if (strcmp("queueSetCharLen", argv[1]) == 0)
|
else if (strcmp("queueSetCharLen", argv[1]) == 0)
|
||||||
{
|
{
|
||||||
ok = test_queueSetCharLen();
|
ok = test_queueSetCharLen();
|
||||||
|
@ -159,8 +263,28 @@ int main(int argc, char *argv[])
|
||||||
else if (strcmp("queueGetTabChar", argv[1]) == 0)
|
else if (strcmp("queueGetTabChar", argv[1]) == 0)
|
||||||
{
|
{
|
||||||
ok = test_queueGetTabChar();
|
ok = test_queueGetTabChar();
|
||||||
// }else if(strcmp("update_flags",argv[1]) == 0){
|
}
|
||||||
// ok = test_game_update_flags();
|
else if (strcmp("queueSetTabChar", argv[1]) == 0)
|
||||||
|
{
|
||||||
|
ok = test_queueSetTabChar();
|
||||||
|
}
|
||||||
|
else if (strcmp("queueAddLastQ", argv[1]) == 0)
|
||||||
|
{
|
||||||
|
ok = test_queueAddLastQ();
|
||||||
|
}
|
||||||
|
else if (strcmp("queueRmLastE", argv[1]) == 0)
|
||||||
|
{
|
||||||
|
ok = test_queueRmLastE();
|
||||||
|
}
|
||||||
|
else if (strcmp("queueRmFrstE", argv[1]) == 0)
|
||||||
|
{
|
||||||
|
ok = test_queueRmFrstE();
|
||||||
|
}
|
||||||
|
else if (strcmp("queueNextDelFrst", argv[1]) == 0)
|
||||||
|
{
|
||||||
|
ok = test_queueNextDelFrst();
|
||||||
|
// }else if(strcmp("default_solution",argv[1]) == 0){
|
||||||
|
// ok = test_game_default_solution();
|
||||||
// }else if(strcmp("default_solution",argv[1]) == 0){
|
// }else if(strcmp("default_solution",argv[1]) == 0){
|
||||||
// ok = test_game_default_solution();
|
// ok = test_game_default_solution();
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,12 +150,15 @@ int main(int argc, char **argv)
|
||||||
pthread_t rawData;
|
pthread_t rawData;
|
||||||
if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0)
|
if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0)
|
||||||
{
|
{
|
||||||
perror("pthread_create() error");
|
perror("threadSimulflux() error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_t calcul;
|
pthread_t calcul;
|
||||||
pthread_create(&calcul, NULL, threadCalculGrowthRate, "threadCalcul");
|
if (pthread_create(&calcul, NULL, threadCalculAverage, "threadCalcul"))
|
||||||
|
{
|
||||||
|
perror("threadCalculAverage() error");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,15 +145,15 @@ Pqueue queueCreateE(int lenChar, const char *_tabChar)
|
||||||
Pqueue queueRmLastE(Pqueue elem)
|
Pqueue queueRmLastE(Pqueue elem)
|
||||||
{
|
{
|
||||||
assert(elem);
|
assert(elem);
|
||||||
Pqueue tmp = elem, previous = NULL;
|
Pqueue tmp = elem, current = NULL;
|
||||||
while (elem->pNextE != NULL)
|
while (tmp->pNextE != NULL)
|
||||||
{
|
{
|
||||||
previous = tmp;
|
current = tmp;
|
||||||
tmp = queueGetNextE(tmp);
|
tmp = queueGetNextE(tmp);
|
||||||
}
|
}
|
||||||
free(tmp->tabChar);
|
free(tmp->tabChar);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
previous->pNextE = NULL;
|
current->pNextE = NULL;
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,15 +161,18 @@ Pqueue queueRmLastE(Pqueue elem)
|
||||||
* @brief remove and free the first element of queue
|
* @brief remove and free the first element of queue
|
||||||
*
|
*
|
||||||
* @param elem target to remove (the element need to be the first)
|
* @param elem target to remove (the element need to be the first)
|
||||||
|
* @return next element of the queue
|
||||||
*/
|
*/
|
||||||
void queueRmFrstE(Pqueue elem)
|
Pqueue queueRmFrstE(Pqueue elem)
|
||||||
{
|
{
|
||||||
assert(elem);
|
assert(elem);
|
||||||
|
Pqueue next = queueGetNextE(elem);
|
||||||
if (elem->tabChar != NULL)
|
if (elem->tabChar != NULL)
|
||||||
{
|
{
|
||||||
free(elem->tabChar);
|
free(elem->tabChar);
|
||||||
}
|
}
|
||||||
free(elem);
|
free(elem);
|
||||||
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,16 +199,31 @@ Pqueue queueNextDelFrst(Pqueue elem)
|
||||||
void queueAddLastQ(Pqueue elem, const char *str, int len)
|
void queueAddLastQ(Pqueue elem, const char *str, int len)
|
||||||
{
|
{
|
||||||
assert(elem);
|
assert(elem);
|
||||||
assert(str);
|
bool str1 = true;
|
||||||
Pqueue next = elem, previous = NULL;
|
if (len == 0)
|
||||||
while (next->pNextE != NULL)
|
|
||||||
{
|
{
|
||||||
previous = next;
|
str = false;
|
||||||
next = queueGetNextE(next);
|
|
||||||
}
|
}
|
||||||
previous = next;
|
else
|
||||||
|
{
|
||||||
|
assert(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
Pqueue current = elem, next = NULL;
|
||||||
|
while (current->pNextE != NULL)
|
||||||
|
{
|
||||||
|
current = queueGetNextE(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str1 == true)
|
||||||
|
{
|
||||||
next = queueCreateE(len, str);
|
next = queueCreateE(len, str);
|
||||||
queueSetNextE(previous, next);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
next = queueCreateEmpty();
|
||||||
|
}
|
||||||
|
queueSetNextE(current, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -91,8 +91,9 @@ Pqueue queueRmLastE(Pqueue elem);
|
||||||
* @brief remove and free the first element of queue
|
* @brief remove and free the first element of queue
|
||||||
*
|
*
|
||||||
* @param elem target to remove (the element need to be the first)
|
* @param elem target to remove (the element need to be the first)
|
||||||
|
* @return the next element of elem
|
||||||
*/
|
*/
|
||||||
void queueRmFrstE(Pqueue elem);
|
Pqueue queueRmFrstE(Pqueue elem); // same of queueNextDelFrst()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief delete the first value and return the next value
|
* @brief delete the first value and return the next value
|
||||||
|
@ -100,7 +101,7 @@ void queueRmFrstE(Pqueue elem);
|
||||||
* @param elem
|
* @param elem
|
||||||
* @return Pqueue
|
* @return Pqueue
|
||||||
*/
|
*/
|
||||||
Pqueue queueNextDelFrst(Pqueue elem);
|
Pqueue queueNextDelFrst(Pqueue elem); // same of queueRmFrstE()
|
||||||
|
|
||||||
/************** print function **************/
|
/************** print function **************/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue