Révision 351
Ajouté par Youssef MORSY il y a presque 3 ans
main.c | ||
---|---|---|
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <strings.h>
|
||
#include <strings.h>
|
||
#include<math.h>
|
||
#include "trame.h"
|
||
|
||
//Trames de tests ? modifier si n?cessaire.
|
||
... | ... | |
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
int decode_nombre(char *ch,int n){
|
||
int i,j,p;
|
||
int s=0;
|
||
for (i=0;i<n;i++){
|
||
p=1;
|
||
for(j=0;j<n-1-i;j++){
|
||
p=p*10;
|
||
}
|
||
int a=decode_int(ch[i]);
|
||
s=s+a*p;
|
||
}
|
||
return s;
|
||
}
|
||
|
||
float latitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[17])*10+decode_int(c[18]) ;
|
||
secondes=(decode_int(c[21])*1000+decode_int(c[22])*100+decode_int(c[23])*10+decode_int(c[24]))/10000;
|
||
minute=(decode_int(c[19])*10+decode_int(c[20])+secondes)/60;
|
||
sommes=degre+minute;
|
||
return sommes;
|
||
}
|
||
|
||
|
||
|
||
float longtitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[29])*100+decode_int(c[30])*10+decode_int(c[31]) ;
|
||
secondes=(decode_int(c[35])*1000+decode_int(c[36])*100+decode_int(c[37])*10+decode_int(c[38])*1)%1000;
|
||
minute=(decode_int(c[32])*10+decode_int(c[33])+secondes)/60;
|
||
sommes=degre+minute;
|
||
|
||
return sommes;
|
||
}
|
||
|
||
float deux_fonctions(char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
while(c[i] != '.'){
|
||
i=i+1;
|
||
}
|
||
if(i==4){
|
||
|
||
degre=decode_int(c[17])*10+decode_int(c[18]) ;
|
||
secondes=(decode_int(c[21])*1000+decode_int(c[22])*100+decode_int(c[23])*10+decode_int(c[24]))/10000;
|
||
minute=(decode_int(c[19])*10+decode_int(c[20])+secondes)/60;
|
||
sommes=degre+minute;}
|
||
else{
|
||
degre=decode_int(c[29])*100+decode_int(c[30])*10+decode_int(c[31]) ;
|
||
secondes=(decode_int(c[35])*1000+decode_int(c[36])*100+decode_int(c[37])*10+decode_int(c[38])*1)/1000;
|
||
minute=(decode_int(c[32])*10+decode_int(c[33])+secondes)/60;
|
||
sommes=degre+minute;
|
||
}
|
||
return sommes;
|
||
|
||
|
||
}
|
||
|
||
//Ajouter vos tests unitaires dans cette fonction.
|
||
|
||
void tests_unitaires(void){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
... | ... | |
exit(-1);
|
||
}
|
||
|
||
//****************************
|
||
|
||
}
|
||
void test_decode_int(void){
|
||
if (5!=5){
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
... | ... | |
printf ("Erreur Test unitaire trame_cmp3.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
|
||
int decode_nombre(char *ch,int n){
|
||
int i,j,p;
|
||
int s=0;
|
||
for (i=0;i<n;i++){
|
||
p=1;
|
||
for(j=0;j<n-1-i;j++){
|
||
p=p*10;
|
||
}
|
||
int a=decode_int(ch[i]);
|
||
s=s+a*p;
|
||
}
|
||
return s;
|
||
}
|
||
void test_decode_nombre(void){
|
||
|
||
//**********************
|
||
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
... | ... | |
printf ("Erreur Test unitaire trame_cmp4.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
|
||
|
||
float latitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[0])*10+decode_int(c[1]) ;
|
||
secondes=(decode_int(c[5])*1000+decode_int(c[6])*100+decode_int(c[7])*10+decode_int(c[5]))/10000;
|
||
minute=(decode_int(c[2])*10+decode_int(c[3])+secondes)/60;
|
||
sommes=degre+minute;
|
||
return sommes;
|
||
}
|
||
void test_latitude(void){
|
||
if (5!=5){
|
||
//********************************
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("3558.8889")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
if (latitude("$GPGGA,141914.00,3558.8889,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("0112.1415")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
if (latitude("$GPGGA,141914.00,0112.1415,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
float longtitude (char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
degre=decode_int(c[0])*100+decode_int(c[1])*10+decode_int(c[2]) ;
|
||
secondes=(decode_int(c[6])*1000+decode_int(c[7])*100+decode_int(c[8])*10+decode_int(c[9])*1)%1000;
|
||
minute=(decode_int(c[3])*10+decode_int(c[4])+secondes)/60;
|
||
sommes=degre+minute;
|
||
}
|
||
void test_longtitude(void){
|
||
//***********************************
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("13558.8889")-135,981481<0.000001 && 135,981481-latitude("13558.8889")<0.000001){
|
||
if (latitude("$GPGGA,141914.00,0112.1415,N,13558.8889,E,1,05,3.4,499.3,M,,M,,*7D")-135,981481<0.000001 && 135,981481-latitude("13558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("10112.1415")-101,202358<0.000001 && 101,202358-latitude("10112.1415")<0.000001){
|
||
if (latitude("$GPGGA,141914.00,0112.1415,N,10112.1415,E,1,05,3.4,499.3,M,,M,,*7D")-101,202358<0.000001 && 101,202358-latitude("10112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
float deux_fonctions(char*c){
|
||
int i=0,degre;
|
||
float secondes=0,sommes,minute=0;
|
||
while(c[i] != '.'){
|
||
i=i+1;
|
||
}
|
||
if(i==4){
|
||
|
||
degre=decode_int(c[0])*10+decode_int(c[1]) ;
|
||
secondes=(decode_int(c[5])*1000+decode_int(c[6])*100+decode_int(c[7])*10+decode_int(c[5]))/10000;
|
||
minute=(decode_int(c[2])*10+decode_int(c[3])+secondes)/60;
|
||
sommes=degre+minute;}
|
||
else{
|
||
degre=decode_int(c[0])*100+decode_int(c[1])*10+decode_int(c[2]) ;
|
||
secondes=(decode_int(c[6])*1000+decode_int(c[7])*100+decode_int(c[8])*10+decode_int(c[9])*1)%1000;
|
||
minute=(decode_int(c[3])*10+decode_int(c[4])+secondes)/60;
|
||
sommes=degre+minute;
|
||
}
|
||
return sommes;
|
||
|
||
|
||
}
|
||
|
||
void test_deux_ions(void){
|
||
//*****************************
|
||
if (5!=5){
|
||
printf ("Erreur Test unitaire basique.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("13558.8889")-135,981481<0.000001 && 135,981481-latitude("13558.8889")<0.000001){
|
||
if (deux_fonctions("$GPGGA,141914.00,0112.1415,N,13558.8889,E,1,05,3.4,499.3,M,,M,,*7D")-135,981481<0.000001 && 135,981481-deux_fonctions("13558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (latitude("10112.1415")-101,202358<0.000001 && 101,202358-latitude("10112.1415")<0.000001){
|
||
if (deux_fonctions("$GPGGA,141914.00,0112.1415,N,10112.1415.1415,E,1,05,3.4,499.3,M,,M,,*7D10112.1415")-101,202358<0.000001 && 101,202358-deux_fonctions("10112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
||
if (deux_fonctions("$GPGGA,141914.00,3558.8889,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-35,981481<0.000001 && 35,981481-latitude("3558.8889")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp1.\n");
|
||
exit(-1);
|
||
}
|
||
if (deux_fonctions("$GPGGA,141914.00,0112.1415,N,00306.6036,E,1,05,3.4,499.3,M,,M,,*7D")-01,202358<0.000001 && 01,202358-latitude("0112.1415")<0.000001){
|
||
printf ("Erreur Test unitaire trame_cmp2.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
tests_unitaires();
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
test_latitude();
|
||
test_longtitude();
|
||
|
||
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
||
int i=0;
|
Formats disponibles : Unified diff
question 10 terminée