Révision 103
Ajouté par Titouan PODGORSKI il y a environ 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.
|
||
... | ... | |
|
||
}
|
||
|
||
int power(int n){
|
||
int i,res=1;
|
||
for(i=0;i<n;i++){
|
||
res*=10;
|
||
|
||
}
|
||
return res;
|
||
}
|
||
|
||
|
||
|
||
int decode_int(char a){
|
||
|
||
int b=a;
|
||
... | ... | |
int i,res=0;
|
||
for(i=0;i<n;i++){
|
||
|
||
res+=decode_int(ch[i])*pow(10,(n-i-1));
|
||
res+=decode_int(ch[i])*power(n-i-1);
|
||
}
|
||
return res;
|
||
}
|
||
|
||
float conversion_latitude_flottant(char *ch){
|
||
int i;
|
||
char t[4];
|
||
float res=decode_nombre(ch,2);
|
||
|
||
|
||
for(i=2;i<4;i++){
|
||
t[i-2]=ch[i];
|
||
}
|
||
res+=((float)decode_nombre(t,2)/60);
|
||
|
||
for(i=5;i<9;i++){
|
||
t[i-5]=ch[i];
|
||
}
|
||
|
||
res+=((float)decode_nombre(t,4)/360000);
|
||
|
||
return res;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
int trame_cmp(char *trame, char *type){
|
||
|
||
int i,test=1;
|
||
... | ... | |
printf ("Erreur Test unitaire trame_cmp.\n");
|
||
exit(-1);
|
||
}
|
||
test_decode_int();
|
||
test_decode_nombre();
|
||
test_conversion_latitude();
|
||
}
|
||
|
||
void test_conversion_latitude(void){
|
||
|
||
if (abs(conversion_latitude_flottant("4851.3100")-48.85861111)>0.00001){
|
||
printf ("Erreur Test unitaire conversion latitude.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void test_decode_int(void){
|
||
|
||
if (decode_int('1')!=1){
|
||
... | ... | |
|
||
void test_decode_nombre(void){
|
||
|
||
if (decode_nombre("123",3)!=123){
|
||
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
if (decode_nombre("123",2)!=12){
|
||
printf ("Erreur Test unitaire decode_nombre n?1 : %d\n",decode_nombre("123",2));
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("987654321",2)!=98){
|
||
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
printf ("Erreur Test unitaire decode_nombre n?2.\n");
|
||
exit(-1);
|
||
}
|
||
if (decode_nombre("66543",4)!=6654){
|
||
printf ("Erreur Test unitaire decode_nombre.\n");
|
||
printf ("Erreur Test unitaire decode_nombre n?3.\n");
|
||
exit(-1);
|
||
}
|
||
}
|
Formats disponibles : Unified diff
Implémentation de la fonctions conversion_latitude et test_conversion_latitude (Question 8)