feat: add tdd

This commit is contained in:
dancingCycle 2023-01-02 17:45:33 +01:00
parent 9ede7ca889
commit 26694a270d
6 changed files with 71 additions and 3 deletions

View File

@ -4,6 +4,8 @@
#include <errno.h>
#include <string.h>
#include "write-location-file.h"
int main()
{
FILE *fp;
@ -36,6 +38,8 @@ int main()
fprintf(fp, "%8s,%8s\n", lat, lon);
fclose(fp);
write_location_file();
printf("\nDone!\n");
return 0;
}

View File

@ -1,9 +1,12 @@
#put the most commonly desired target first (default)
all: main.o
gcc main.o -o write
main.o: main.c
all: main.o write-location-file.o
gcc main.o write-location-file.o -o write
main.o: main.c write-location-file.h
gcc -I . -c main.c
write-location-file.o: write-location-file.c write-location-file.h
gcc -I . -c write-location-file.c
clean:
rm -rf *.o
rm -rf write
rm -rf *.csv
rm -rf a.out

View File

@ -0,0 +1,7 @@
# tdd
* test write-location-file
```
gcc -Wall write-location-file-test.c write-location-file.c && ./a.out
```

View File

@ -0,0 +1,18 @@
/*write-location-file-test.c*/
#include "write-location-file.h"
/*use printf*/
//#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
static void test(){
//printf("write_location_file() return %d:\n",write_location_file());
assert(write_location_file()==0 && "test()");
}
int main(){
test();
}

View File

@ -0,0 +1,33 @@
/*write-location-file.c*/
#include "write-location-file.h"
#include<stdio.h>
/*use macro extern int errno*/
#include <errno.h>
#include <string.h>
int write_location_file(){
FILE *fp;
printf("\nwrite-location-file() Start...\n");
fp = fopen("location-file.csv", "w");
if (fp==NULL)
{
/*failed to open file and associate stream*/
fprintf(stderr, "Value of errno: %d\n", errno);
fprintf(stderr, "Error opening file: %s\n", strerror(errno));
}
/*latitude e.g. 52.26594*/
/*longitude e.g. 10.52673*/
fprintf(fp, "52.26594,10.52673\n");
fclose(fp);
printf("\nwrite-location-file() Done!\n");
return 0;
}

View File

@ -0,0 +1,3 @@
/*write-location-file.h*/
int write_location_file();