308 lines
7 KiB
C
308 lines
7 KiB
C
#define __USE_GNU
|
|
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "include/fileGestion.h"
|
|
#include "include/getArray.h"
|
|
#include "include/growthRate.h"
|
|
#include "include/power.h"
|
|
#include "include/simulateFlux.h"
|
|
#include "include/queue.h"
|
|
#include "include/average.h"
|
|
//#include "b2hd.h"
|
|
|
|
bool rawDataWriteFlag;
|
|
int nRowRawData = 500;
|
|
int nRowGR = 150;
|
|
int nCol = 1;
|
|
double freqEch = 250;
|
|
|
|
int nbRowBinFile = 900011;
|
|
int nbRowIgnore = 19;
|
|
|
|
Pqueue firstRawDataQueue;
|
|
// Captor 1 2 3 4 5 6 7 8
|
|
bool selectionCaptors[] = {true, false, true, false, false, false, true, false};
|
|
|
|
int cptData = 0;
|
|
int cptFile = 1;
|
|
int cptValue = 0;
|
|
|
|
double period = 0;
|
|
double invTimeBandWidth = 0;
|
|
|
|
bool test_queueCreateEmpty()
|
|
{
|
|
Pqueue new = queueCreateEmpty();
|
|
|
|
assert(queueGetCharLen(new) == 0);
|
|
assert(queueGetTabChar(new) == NULL);
|
|
assert(queueGetNextE(new) == NULL);
|
|
|
|
// queueDelAll(new);
|
|
queueRmFrstE(new);
|
|
|
|
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()
|
|
{
|
|
Pqueue new = queueCreateEmpty();
|
|
|
|
queueSetCharLen(new, 13);
|
|
|
|
assert(queueGetCharLen(new) == 13);
|
|
assert(queueGetTabChar(new) == NULL);
|
|
assert(queueGetNextE(new) == NULL);
|
|
|
|
// queueDelAll(new);
|
|
queueRmFrstE(new);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
bool test_queueSetTabChar()
|
|
{
|
|
// Set and Get tabChar are similar because use for same test
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
bool test_queueSetNextE()
|
|
{
|
|
Pqueue new = queueCreateEmpty(), next = queueCreateEmpty();
|
|
|
|
queueSetNextE(new, next);
|
|
|
|
assert(queueGetNextE(new) == next);
|
|
assert(queueGetNextE(next) == NULL);
|
|
|
|
queueDelAll(new);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
bool test_queueGetNextE()
|
|
{
|
|
Pqueue new = queueCreateEmpty(), next = queueCreateEmpty();
|
|
|
|
queueSetNextE(new, next);
|
|
|
|
assert(queueGetNextE(new) == next);
|
|
assert(queueGetNextE(next) == NULL);
|
|
|
|
queueDelAll(new);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
bool test_queueGetCharLen()
|
|
{
|
|
Pqueue new = queueCreateEmpty();
|
|
|
|
assert(queueGetCharLen(new) == 0);
|
|
|
|
queueSetCharLen(new, 13);
|
|
|
|
assert(queueGetCharLen(new) == 13);
|
|
|
|
queueDelAll(new);
|
|
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[])
|
|
{
|
|
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
if (argc == 1)
|
|
usage(argc, argv);
|
|
|
|
// start test
|
|
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
|
|
int ok = 1;
|
|
if (strcmp("queueCreateEmpty", argv[1]) == 0)
|
|
{
|
|
ok = test_queueCreateEmpty();
|
|
}
|
|
else if (strcmp("queueCreateE", argv[1]) == 0)
|
|
{
|
|
ok = test_queueCreateE();
|
|
}
|
|
else if (strcmp("queueSetCharLen", argv[1]) == 0)
|
|
{
|
|
ok = test_queueSetCharLen();
|
|
}
|
|
else if (strcmp("queueGetTabChar", argv[1]) == 0)
|
|
{
|
|
ok = test_queueGetTabChar();
|
|
}
|
|
else if (strcmp("queueSetNextE", argv[1]) == 0)
|
|
{
|
|
ok = test_queueSetNextE();
|
|
}
|
|
else if (strcmp("queueGetNextE", argv[1]) == 0)
|
|
{
|
|
ok = test_queueGetNextE();
|
|
}
|
|
else if (strcmp("queueGetCharLen", argv[1]) == 0)
|
|
{
|
|
ok = test_queueGetCharLen();
|
|
}
|
|
else if (strcmp("queueGetTabChar", argv[1]) == 0)
|
|
{
|
|
ok = test_queueGetTabChar();
|
|
}
|
|
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){
|
|
// ok = test_game_default_solution();
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
// print test result
|
|
if (ok == 0)
|
|
{
|
|
fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
} |