add brute force

This commit is contained in:
2018-12-08 19:35:02 -03:00
parent 7b0092126d
commit a595ed46ab
11 changed files with 194 additions and 27 deletions

101
test/100.pto Normal file
View File

@@ -0,0 +1,101 @@
100
4.70399 2.61546
4.11505 5.40782
5.38695 7.04457
7.28393 6.57592
7.22851 4.6192
9.30246 1.96946
3.27011 4.08827
4.38336 2.60827
3.58596 1.25516
2.83329 1.84097
1.57041 7.29407
1.08953 8.75504
6.11049 6.26775
4.42073 4.45547
2.51608 4.17832
7.5074 7.86617
7.39983 8.79166
8.37735 9.50368
8.28499 9.42695
8.54374 7.33608
9.44417 7.20781
8.43204 4.21497
8.43641 0.312691
8.99538 1.95157
9.00337 3.45095
1.18444 1.77786
0.619263 2.57976
1.1813 1.11385
2.43991 1.47131
2.72304 0.350919
3.56181 0.339801
4.39165 1.2697
3.30581 1.2275
2.79924 1.89947
3.74776 5.40936
4.26677 3.85951
4.34214 5.17149
3.46184 4.94453
2.15366 4.32258
1.98295 3.55355
1.30004 3.26112
1.66377 3.69903
1.707 4.2865
1.07164 7.35545
1.60081 6.9651
0.305693 7.65618
1.66486 7.6809
0.0521513 7.69084
0.488579 9.24692
1.66901 9.25729
1.35521 9.09874
1.34367 7.98094
2.70188 8.11911
2.11048 8.532
2.89328 9.40763
4.26524 7.32178
3.27553 6.72305
2.50356 6.35372
2.37225 6.40923
3.1371 5.97335
3.19697 5.73857
3.36636 6.2637
4.52454 6.5996
6.18448 5.30826
5.78067 5.81179
4.72225 6.57439
4.84385 9.4136
4.49361 9.59739
5.35009 8.95877
5.86514 8.11254
5.69065 6.91125
8.91671 9.17126
8.81438 9.74364
9.95562 9.5857
9.11793 9.58001
9.79628 9.12007
9.18419 8.51274
8.99504 6.68699
6.70575 5.62865
8.45891 6.25965
8.67494 5.68547
8.66115 3.10929
8.77804 4.7744
9.93093 3.45255
8.46596 3.4775
8.30869 4.83072
7.58965 4.04073
5.67133 2.20668
7.47257 1.87875
7.89039 2.16117
5.7009 1.01409
5.31577 1.66729
4.41841 0.812257
5.98034 0.690348
6.44768 0.604096
7.35945 0.788557
7.40586 0.891187
8.45234 1.65136
7.911 1.36198
9.56373 0.684329

6
test/5.pto Normal file
View File

@@ -0,0 +1,6 @@
5
2 3
7 9
1 100
1 1
5 10

View File

@@ -1,9 +1,10 @@
CC=gcc
CFLAGS=-Wall -I../src/include -DDEBUG -g
LDFLAGS=-lm
SRC=test.c
OBJ=$(SRC:.c=.o)
OBJ+=../src/random.o ../src/read_file.o
OBJ+=../src/read_file.o ../src/distance.o ../src/brute_force.o
all: test

View File

@@ -17,18 +17,75 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <float.h>
#include "points.h"
#include "read_file.h"
#include "brute_force.h"
/**
* Comparar 2 double para ver si son casi igual
* @param d1 El primer double
* @param d2 El segudno double
* @return Retorna 1 si son igual o 0 sino
*/
int compare_double(double d1, double d2) {
double precision = 0.000000001;
if (((d1 - precision) < d2) && ((d1 + precision) > d2)) {
return 1;
}
else {
return 0;
}
}
/**
* El programa de test
* @param argc La cantidad de argumentos
* @param argv Los argumentos
* @return Retorna 0 por exito o 1 si falló algun test
*/
int main(int argc, char **argv) {
//int pass;
int passed = 0;
int failed = 0;
point_t *points = NULL;
unsigned int n = 0;
double dist = DBL_MAX;
fprintf(stdout, "Running tests:\n");
if (read_file("test/100.pto", &points, &n) == 0) {
fprintf(stdout, "\tread file: passed\n");
passed++;
}
else {
fprintf(stdout, "\tread file: failed\n");
failed++;
}
if (failed > 0) {
fprintf(stdout, "\tbrute force: failed\n");
failed++;
}
else {
fprintf(stdout, "\tbrute force: ");
fflush(stdout);
brute_force(points, n, &dist);
if (compare_double(dist, 0.067687840)) {
fprintf(stdout, "passed\n");
passed++;
}
else {
fprintf(stdout, "failed\n");
failed++;
}
}
fprintf(stdout, "%d tests passed\n", passed);
fprintf(stdout, "%d tests failed\n", failed);
free(points);
if (failed == 0) {
return 0;
}