diff --git a/.gitignore b/.gitignore index dbfb6d8..d3b8018 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.csv -a.out +*a.out diff --git a/struct-location/location-test.c b/struct-location/location-test.c new file mode 100644 index 0000000..6cd2d28 --- /dev/null +++ b/struct-location/location-test.c @@ -0,0 +1,28 @@ +#include "location.h" + +/*use assert()*/ +#include + +/*use strcmp*/ +#include + +static void test_lct_lat(){ + struct location lctn; + strcpy(lctn.lat, "+052.26594"); + strcpy(lctn.lon, "+10.52673"); + struct location lctnGet=getLocation(lctn.lat, lctn.lon); + assert(strcmp(lctn.lat, lctnGet.lat)==0 && "test_lct_lat()"); +} + +static void test_lct_lon(){ + struct location lctn; + strcpy(lctn.lat, "+052.26594"); + strcpy(lctn.lon, "+10.52673"); + struct location lctnGet=getLocation(lctn.lat, lctn.lon); + assert(strcmp(lctn.lat, lctnGet.lat)==0 && "test_lct_lon()"); +} + +int main(){ + test_lct_lat(); + test_lct_lon(); +} diff --git a/struct-location/location.c b/struct-location/location.c new file mode 100644 index 0000000..dd5b2ab --- /dev/null +++ b/struct-location/location.c @@ -0,0 +1,16 @@ +#include "location.h" + +struct location getLocation(char lat[11], char lon[10]){ + struct location lctn; + int i,j; + + for(i=0; i<11; i++){ + lctn.lat[i] = lat[i]; + } + + for(j=0; j<10; j++){ + lctn.lon[j] = lon[j]; + } + + return lctn; +} diff --git a/struct-location/location.h b/struct-location/location.h new file mode 100644 index 0000000..1c96eee --- /dev/null +++ b/struct-location/location.h @@ -0,0 +1,9 @@ +/*use struct statement to define structure*/ +struct location { + /*latitide like +052.26594*/ + char lat[11]; + /*longiture like +10.52673*/ + char lon[10]; +}; + +struct location getLocation(char lat[11], char lon[10]); diff --git a/struct-location/readme.md b/struct-location/readme.md new file mode 100644 index 0000000..ee590c0 --- /dev/null +++ b/struct-location/readme.md @@ -0,0 +1,7 @@ +# tdd + +* test location + +``` +gcc -Wall location-test.c location.c && ./a.out +``` \ No newline at end of file