Traitement-signal-plantes/Code-C/ctest.c
2022-06-21 15:13:10 +02:00

184 lines
3.7 KiB
C

#define __USE_GNU
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "fileGestion.h"
#include "getArray.h"
#include "growthRate.h"
#include "power.c"
#include "simulateFlux.h"
#include "queue.h"
#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_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_queueGetTabChar()
{ // Define later
Pqueue new = queueCreateEmpty();
// const char tabChar[12] = "PetitNavire\0"
queueSetTabChar(new, 13, NULL);
assert(queueGetCharLen(new) == 13);
assert(queueGetTabChar(new) == NULL);
assert(queueGetNextE(new) == NULL);
// queueDelAll(new);
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;
}
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("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("update_flags",argv[1]) == 0){
// ok = test_game_update_flags();
// }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;
}
}