Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AyOC - docentes
grupal-2c2024
Commits
3d4a3dc6
Commit
3d4a3dc6
authored
1 month ago
by
Stefano Miyel Ruberto
Browse files
Options
Download
Email Patches
Plain Diff
Agregadas macros de test-utils en TP1-a; Agregados pequenios casos de tests para TP1-b
parent
b1ef7eb7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
527 additions
and
664 deletions
+527
-664
TP1-a/src/Makefile
TP1-a/src/Makefile
+1
-1
TP1-a/src/lista_enlazada.c
TP1-a/src/lista_enlazada.c
+14
-27
TP1-a/src/test-utils.h
TP1-a/src/test-utils.h
+91
-0
TP1-a/src/tests_contar_espacios.c
TP1-a/src/tests_contar_espacios.c
+40
-123
TP1-a/src/tests_lista_enlazada.c
TP1-a/src/tests_lista_enlazada.c
+219
-278
TP1-a/src/tests_vector.c
TP1-a/src/tests_vector.c
+162
-235
No files found.
TP1-a/src/Makefile
View file @
3d4a3dc6
...
...
@@ -55,7 +55,7 @@ tests_contar_espacios: #COMPLETAR
# Para pensar: ¿por qué funciona esto (sin cuerpo)?
# Pista: https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
lista_enlazada.o
:
lista_enlazada.c
lista_enlazada.o
:
lista_enlazada.c
classify_chars.o
:
classify_chars.c
...
...
This diff is collapsed.
Click to expand it.
TP1-a/src/lista_enlazada.c
View file @
3d4a3dc6
#include "lista_enlazada.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
lista_t
*
nueva_lista
(
void
)
{}
lista_t
*
nueva_lista
(
void
)
{
}
uint32_t
longitud
(
lista_t
*
lista
)
{
uint32_t
longitud
(
lista_t
*
lista
)
{}
}
void
agregar_al_final
(
lista_t
*
lista
,
uint32_t
*
arreglo
,
uint64_t
longitud
)
{
}
void
agregar_al_final
(
lista_t
*
lista
,
uint32_t
*
arreglo
,
uint64_t
longitud
)
{
nodo_t
*
iesimo
(
lista_t
*
lista
,
uint32_t
i
)
{
}
}
uint64_t
cantidad_total_de_elementos
(
lista_t
*
lista
)
{
}
nodo_t
*
iesimo
(
lista_t
*
lista
,
uint32_t
i
)
{
}
uint64_t
cantidad_total_de_elementos
(
lista_t
*
lista
)
{
}
void
imprimir_lista
(
lista_t
*
lista
)
{
}
void
imprimir_lista
(
lista_t
*
lista
)
{}
// Función auxiliar para lista_contiene_elemento
int
array_contiene_elemento
(
uint32_t
*
array
,
uint64_t
size_of_array
,
uint32_t
elemento_a_buscar
)
{
}
int
lista_contiene_elemento
(
lista_t
*
lista
,
uint32_t
elemento_a_buscar
)
{
}
int
array_contiene_elemento
(
uint32_t
*
array
,
uint64_t
size_of_array
,
uint32_t
elemento_a_buscar
)
{}
int
lista_contiene_elemento
(
lista_t
*
lista
,
uint32_t
elemento_a_buscar
)
{}
// Devuelve la memoria otorgada para construir la lista indicada por el primer argumento.
// Tener en cuenta que ademas, se debe liberar la memoria correspondiente a cada array de cada elemento de la lista.
void
destruir_lista
(
lista_t
*
lista
)
{
}
\ No newline at end of file
// Devuelve la memoria otorgada para construir la lista indicada por el primer
// argumento. Tener en cuenta que ademas, se debe liberar la memoria
// correspondiente a cada array de cada elemento de la lista.
void
destruir_lista
(
lista_t
*
lista
)
{}
This diff is collapsed.
Click to expand it.
TP1-a/src/test-utils.h
0 → 100644
View file @
3d4a3dc6
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
static
size_t
test__count
=
0
;
static
size_t
test__succeed__count
=
0
;
#define TEST(name) \
void name##__impl(const char *test__name, bool *test__fallo, \
char assert_name[1024]); \
void name() { \
test__count++; \
char assert_name[1024] = {0}; \
const char *test__name = #name; \
bool test__fallo = false; \
printf("- %s", test__name); \
name##__impl(test__name, &test__fallo, assert_name); \
if (!test__fallo) { \
test__succeed__count++; \
printf(" OK\n"); \
} \
} \
void name##__impl(const char *test__name, bool *test__fallo, \
char assert_name[1024])
#define TEST_ASSERT(cond) \
if (!(cond)) { \
printf(" FAILED\n"); \
if (assert_name[0] == '\0') { \
strcpy(assert_name, #cond); \
} \
printf(" al probar %s\n", assert_name); \
printf(" fallo en %s:%d\n", __FILE__, __LINE__); \
printf(" Condición: %s\n", #cond); \
*test__fallo = true; \
return; \
} \
assert_name[0] = '\0'
#define TEST_ASSERT_EQUALS(type, expected, got) \
if ((type)(expected) != (type)(got)) { \
char format[1024]; \
printf(" FAILED\n"); \
if (assert_name[0] == '\0') { \
strcpy(assert_name, #expected " == " #got); \
} \
printf(" al probar %s\n", assert_name); \
printf(" fallo en %s:%d\n", __FILE__, __LINE__); \
printf(" Esperado: "); \
PRINT_VALUE(type, (type)(expected)); \
printf("\n"); \
printf(" Recibido: "); \
PRINT_VALUE(type, (type)(got)); \
printf("\n"); \
*test__fallo = true; \
return; \
} \
assert_name[0] = '\0'
/* Dumb generic printing mechanism */
/* Note: When defining the uint64_t, I have a warning that it seems depends on
* the architecture we're compiling the function.*/
static
void
print_int32_t
(
int32_t
v
)
{
printf
(
"%d"
,
v
);
}
static
void
print_uint32_t
(
uint32_t
v
)
{
printf
(
"%u"
,
v
);
}
static
void
print_uint64_t
(
uint64_t
v
)
{
printf
(
"%lu"
,
v
);
}
static
void
print_string
(
char
*
v
)
{
printf
(
"%s"
,
v
);
}
static
void
print_float
(
float
v
)
{
printf
(
"%.2f"
,
v
);
}
static
void
print_double
(
double
v
)
{
printf
(
"%.2f"
,
v
);
}
#define PRINT_VALUE(type, value) \
_Generic(*((type *)NULL), \
int32_t: print_int32_t, \
uint32_t: print_uint32_t, \
uint64_t: print_uint64_t, \
char *: print_string, \
float: print_float, \
double: print_double)(value)
static
inline
void
tests_end
()
{
printf
(
"Pasaron %ld de %ld tests
\n
"
,
test__succeed__count
,
test__count
);
if
(
test__count
==
test__succeed__count
)
{
printf
(
"¡Pasaron todos los tests!
\n
"
);
exit
(
0
);
}
else
{
printf
(
"Fallaron algunos tests.
\n
"
);
exit
(
1
);
}
}
This diff is collapsed.
Click to expand it.
TP1-a/src/tests_contar_espacios.c
View file @
3d4a3dc6
#include "contar_espacios.h"
#include "test-utils.h"
#include <stdio.h>
#include <stdlib.h>
void
test_longitud
(
void
)
{
uint32_t
len
=
longitud_de_string
(
NULL
);
if
(
len
!=
0
)
{
printf
(
"Fallo en test_longitud NULL
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
"Soy un string"
);
if
(
len
!=
13
)
{
printf
(
"Fallo en test_longitud 2
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
""
);
if
(
len
!=
0
)
{
printf
(
"Fallo en test_longitud vacío
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
"exactas-uba-/-/-"
);
if
(
len
!=
16
)
{
printf
(
"Fallo en test_longitud 4
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
"un string muy
\n
muy muy muy
\n
largooooooooooooooooooooooooooooooooooooooooooooooooooo"
);
if
(
len
!=
84
)
{
printf
(
"Fallo en test_longitud 5
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
"un
\t
string
\t
con
\t
simbolos
\t
escapados"
);
if
(
len
!=
32
)
{
printf
(
"Fallo en test_longitud tabs
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
"
\n
"
);
if
(
len
!=
1
)
{
printf
(
"Fallo en test_longitud 7
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
" "
);
if
(
len
!=
1
)
{
printf
(
"Fallo en test_longitud espacio
\n
"
);
exit
(
1
);
}
len
=
longitud_de_string
(
"!
\"
#$%&/()="
);
if
(
len
!=
10
)
{
printf
(
"Fallo en test_longitud simbolos
\n
"
);
exit
(
1
);
}
// Test posible: Un string con un \0 en el medio -- Cortar antes el string
#include <string.h>
TEST
(
test_longitud
)
{
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
longitud_de_string
(
NULL
));
TEST_ASSERT_EQUALS
(
uint32_t
,
13
,
longitud_de_string
(
"Soy un string"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
longitud_de_string
(
""
));
TEST_ASSERT_EQUALS
(
uint32_t
,
16
,
longitud_de_string
(
"exactas-uba-/-/-"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
84
,
longitud_de_string
(
"un string muy
\n
muy muy muy "
"
\n
largooooooooooooooooooooooooooooooooooooooooooooooooooo"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
32
,
longitud_de_string
(
"un
\t
string
\t
con
\t
simbolos
\t
escapados"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
1
,
longitud_de_string
(
"
\n
"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
1
,
longitud_de_string
(
" "
));
TEST_ASSERT_EQUALS
(
uint32_t
,
10
,
longitud_de_string
(
"!
\"
#$%&/()="
));
// Test posible: Un string con un \0 en el medio -- Cortar antes el string
}
void
test_contar_espacios
(
void
)
{
uint32_t
cant_espacios
=
contar_espacios
(
NULL
);
if
(
cant_espacios
!=
0
)
{
printf
(
"Fallo en test_contar_espacios NULL
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
"orga2 se gu ndo cuatrimestre"
);
if
(
cant_espacios
!=
4
)
{
printf
(
"Fallo en test_contar_espacios 2
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
""
);
if
(
cant_espacios
!=
0
)
{
printf
(
"Fallo en test_contar_espacios vacío
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
"unstringmuylargooooooooooooooooooooooooooooooooooooooooooooooooooo"
);
if
(
cant_espacios
!=
0
)
{
printf
(
"Fallo en test_contar_espacios 4
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
" pruebita"
);
if
(
cant_espacios
!=
10
)
{
printf
(
"Fallo en test_contar_espacios 5
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
"otra-pruebita "
);
if
(
cant_espacios
!=
10
)
{
printf
(
"Fallo en test_contar_espacios 6
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
"ultima pruebita"
);
if
(
cant_espacios
!=
3
)
{
printf
(
"Fallo en test_contar_espacios 7
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
" "
);
if
(
cant_espacios
!=
7
)
{
printf
(
"Fallo en test_contar_espacios 8
\n
"
);
exit
(
1
);
}
cant_espacios
=
contar_espacios
(
"te prometo que
\n
es el ultimo test"
);
if
(
cant_espacios
!=
7
)
{
printf
(
"Fallo en test_contar_espacios 9
\n
"
);
exit
(
1
);
}
TEST
(
test_contar_espacios
)
{
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
contar_espacios
(
NULL
));
TEST_ASSERT_EQUALS
(
uint32_t
,
4
,
contar_espacios
(
"orga2 se gu ndo cuatrimestre"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
contar_espacios
(
""
));
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
contar_espacios
(
"unstringmuylargoooooooooooooooooooooooooo"
"ooooooooooooooooooooooooo"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
10
,
contar_espacios
(
" pruebita"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
10
,
contar_espacios
(
"otra-pruebita "
));
TEST_ASSERT_EQUALS
(
uint32_t
,
3
,
contar_espacios
(
"ultima pruebita"
));
TEST_ASSERT_EQUALS
(
uint32_t
,
7
,
contar_espacios
(
" "
));
TEST_ASSERT_EQUALS
(
uint32_t
,
7
,
contar_espacios
(
"te prometo que
\n
es el ultimo test"
));
}
int
main
()
{
printf
(
"= Tests de contar_espacios:
\n
"
);
printf
(
"=========================================
\n
"
);
printf
(
"= Tests de contar_espacios:
\n
"
);
printf
(
"=========================================
\n
"
);
test_longitud
();
test_contar_espacios
();
test_longitud
();
test_contar_espacios
();
printf
(
"¡Pasaron todos los
tests
!
\n
"
);
exit
(
0
)
;
tests
_end
(
);
return
0
;
}
This diff is collapsed.
Click to expand it.
TP1-a/src/tests_lista_enlazada.c
View file @
3d4a3dc6
#include "lista_enlazada.h"
#include <stdlib.h>
#include <stdio.h>
#include "test-utils.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
void
imprimir_array
(
int
*
array
,
size_t
cantidad
)
{
printf
(
"{ "
);
for
(
size_t
i
=
0
;
i
<
cantidad
;
i
++
)
{
printf
(
"%d "
,
array
[
i
]);
}
printf
(
"}
\n
"
);
void
imprimir_array
(
int
*
array
,
size_t
cantidad
)
{
printf
(
"{ "
);
for
(
size_t
i
=
0
;
i
<
cantidad
;
i
++
)
{
printf
(
"%d "
,
array
[
i
]);
}
printf
(
"}
\n
"
);
}
bool
arrays_son_iguales
(
uint32_t
*
a1
,
uint64_t
longitud
,
uint32_t
*
a2
,
uint64_t
longitud2
)
{
if
(
longitud
!=
longitud2
)
{
return
false
;
}
return
memcmp
(
a1
,
a2
,
longitud
)
==
0
;
bool
arrays_son_iguales
(
uint32_t
*
a1
,
uint64_t
longitud
,
uint32_t
*
a2
,
uint64_t
longitud2
)
{
if
(
longitud
!=
longitud2
)
{
return
false
;
}
return
memcmp
(
a1
,
a2
,
longitud
*
sizeof
(
uint32_t
))
==
0
;
}
void
test_crear_lista
(
void
)
{
lista_t
*
lista_nueva
=
nueva_lista
();
assert
(
lista_nueva
!=
NULL
);
assert
(
lista_nueva
->
head
==
NULL
);
free
(
lista_nueva
);
printf
(
"¡Pasó el test test_crear_lista!
\n
"
);
TEST
(
test_crear_lista
)
{
lista_t
*
lista_nueva
=
nueva_lista
();
TEST_ASSERT
(
lista_nueva
!=
NULL
);
TEST_ASSERT
(
lista_nueva
->
head
==
NULL
);
free
(
lista_nueva
);
}
void
test_longitud_lista_vacia_es_cero
(
void
)
{
lista_t
*
lista
=
nueva_lista
();
assert
(
longitud
(
lista
)
==
0
);
free
(
lista
);
printf
(
"¡Pasó el test test_longitud_lista_vacia_es_cero!
\n
"
);
TEST
(
test_longitud_lista_vacia_es_cero
)
{
lista_t
*
lista
=
nueva_lista
();
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
longitud
(
lista
));
free
(
lista
);
}
void
test_agregar_al_final
(
void
)
{
lista_t
*
mi_lista
=
nueva_lista
();
uint32_t
*
array
=
calloc
(
10
,
sizeof
(
uint32_t
));
nodo_t
*
head_lista
=
calloc
(
1
,
sizeof
(
nodo_t
));
for
(
uint32_t
i
=
0
;
i
<
10
;
i
++
)
{
array
[
i
]
=
((
100
-
i
)
*
2
)
+
45
;
}
head_lista
->
arreglo
=
array
;
head_lista
->
longitud
=
10
;
mi_lista
->
head
=
head_lista
;
uint32_t
arr1
[]
=
{
32
,
7
,
2
,
1
,
272
,
50
,
34
,
67
,
45
,
99
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
assert
(
longitud
(
mi_lista
)
==
2
);
uint32_t
arr2
[]
=
{
2
,
56
,
76
,
5
,
1
,
9
,
0
,
45
,
67
,
87
,
43
,
23
,
56
,
76
,
87
,
86
,
101
,
9
,
3
,
345
,
21
};
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
assert
(
longitud
(
mi_lista
)
==
3
);
uint32_t
arr3
[]
=
{
40
,
34
,
21
};
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
assert
(
longitud
(
mi_lista
)
==
4
);
uint32_t
arr4
[]
=
{
3
};
agregar_al_final
(
mi_lista
,
arr4
,
ARRAY_SIZE
(
arr4
));
assert
(
longitud
(
mi_lista
)
==
5
);
uint32_t
arr5
[]
=
{
2
,
45
,
767
,
54
,
64
,
5
,
786
,
2
};
agregar_al_final
(
mi_lista
,
arr5
,
ARRAY_SIZE
(
arr5
));
assert
(
longitud
(
mi_lista
)
==
6
);
uint32_t
arr6
[]
=
{};
agregar_al_final
(
mi_lista
,
arr6
,
ARRAY_SIZE
(
arr6
));
// assert(longitud(mi_lista) == 6); // TODO: Ver si se agrega o si no se agrega el nodo
bool
res
=
true
;
nodo_t
*
it
=
mi_lista
->
head
;
int
j
=
0
;
while
(
it
!=
NULL
)
{
if
(
j
==
0
)
{
for
(
size_t
i
=
0
;
i
<
10
;
i
++
)
{
if
(
it
->
arreglo
[
i
]
!=
((
100
-
i
)
*
2
)
+
45
)
{
res
=
false
;
break
;
}
}
}
else
if
(
j
==
1
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr1
,
ARRAY_SIZE
(
arr1
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
2
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr2
,
ARRAY_SIZE
(
arr2
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
3
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr3
,
ARRAY_SIZE
(
arr3
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
4
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr4
,
ARRAY_SIZE
(
arr4
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
5
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr5
,
ARRAY_SIZE
(
arr5
))))
{
res
=
false
;
break
;
}
TEST
(
test_agregar_al_final
)
{
lista_t
*
mi_lista
=
nueva_lista
();
uint32_t
*
array
=
calloc
(
10
,
sizeof
(
uint32_t
));
nodo_t
*
head_lista
=
calloc
(
1
,
sizeof
(
nodo_t
));
for
(
uint32_t
i
=
0
;
i
<
10
;
i
++
)
{
array
[
i
]
=
((
100
-
i
)
*
2
)
+
45
;
}
head_lista
->
arreglo
=
array
;
head_lista
->
longitud
=
10
;
mi_lista
->
head
=
head_lista
;
uint32_t
arr1
[]
=
{
32
,
7
,
2
,
1
,
272
,
50
,
34
,
67
,
45
,
99
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
TEST_ASSERT_EQUALS
(
uint32_t
,
2
,
longitud
(
mi_lista
));
uint32_t
arr2
[]
=
{
2
,
56
,
76
,
5
,
1
,
9
,
0
,
45
,
67
,
87
,
43
,
23
,
56
,
76
,
87
,
86
,
101
,
9
,
3
,
345
,
21
};
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
TEST_ASSERT_EQUALS
(
uint32_t
,
3
,
longitud
(
mi_lista
));
uint32_t
arr3
[]
=
{
40
,
34
,
21
};
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
TEST_ASSERT_EQUALS
(
uint32_t
,
4
,
longitud
(
mi_lista
));
uint32_t
arr4
[]
=
{
3
};
agregar_al_final
(
mi_lista
,
arr4
,
ARRAY_SIZE
(
arr4
));
TEST_ASSERT_EQUALS
(
uint32_t
,
5
,
longitud
(
mi_lista
));
uint32_t
arr5
[]
=
{
2
,
45
,
767
,
54
,
64
,
5
,
786
,
2
};
agregar_al_final
(
mi_lista
,
arr5
,
ARRAY_SIZE
(
arr5
));
TEST_ASSERT_EQUALS
(
uint32_t
,
6
,
longitud
(
mi_lista
));
uint32_t
arr6
[]
=
{};
agregar_al_final
(
mi_lista
,
arr6
,
ARRAY_SIZE
(
arr6
));
// TEST_ASSERT_EQUALS(uint32_t, 6, longitud(mi_lista)); // TODO: Ver si se
// agrega o si no se agrega el nodo
bool
res
=
true
;
nodo_t
*
it
=
mi_lista
->
head
;
int
j
=
0
;
while
(
it
!=
NULL
)
{
if
(
j
==
0
)
{
for
(
size_t
i
=
0
;
i
<
10
;
i
++
)
{
if
(
it
->
arreglo
[
i
]
!=
((
100
-
i
)
*
2
)
+
45
)
{
res
=
false
;
break
;
}
it
=
it
->
next
;
j
++
;
}
}
else
if
(
j
==
1
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr1
,
ARRAY_SIZE
(
arr1
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
2
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr2
,
ARRAY_SIZE
(
arr2
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
3
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr3
,
ARRAY_SIZE
(
arr3
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
4
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr4
,
ARRAY_SIZE
(
arr4
))))
{
res
=
false
;
break
;
}
}
else
if
(
j
==
5
)
{
if
(
!
(
arrays_son_iguales
(
it
->
arreglo
,
it
->
longitud
,
arr5
,
ARRAY_SIZE
(
arr5
))))
{
res
=
false
;
break
;
}
}
if
(
res
==
false
)
{
printf
(
"Fallo en agregar_al_final
\n
"
);
exit
(
1
);
}
destruir_lista
(
mi_lista
);
it
=
it
->
next
;
j
++
;
}
printf
(
"¡Pasó el test test-agregar_al_final!
\n
"
);
TEST_ASSERT
(
res
==
true
);
destruir_lista
(
mi_lista
);
}
void
test_agregar_al_final_agrega_el_primer_nodo
(
void
)
{
lista_t
*
mi_lista
=
nueva_lista
();
uint32_t
arr
[]
=
{
222
,
23
,
4
,
33
,
1288
};
agregar_al_final
(
mi_lista
,
arr
,
ARRAY_SIZE
(
arr
));
assert
(
mi_lista
->
head
!=
NULL
);
assert
(
longitud
(
mi_lista
)
==
1
);
destruir_lista
(
mi_lista
);
printf
(
"¡Pasó el test test_agregar_al_final_agrega_el_primer_nodo!
\n
"
);
TEST
(
test_agregar_al_final_agrega_el_primer_nodo
)
{
lista_t
*
mi_lista
=
nueva_lista
();
uint32_t
arr
[]
=
{
222
,
23
,
4
,
33
,
1288
};
agregar_al_final
(
mi_lista
,
arr
,
ARRAY_SIZE
(
arr
));
TEST_ASSERT
(
mi_lista
->
head
!=
NULL
);
TEST_ASSERT_EQUALS
(
uint32_t
,
1
,
longitud
(
mi_lista
));
destruir_lista
(
mi_lista
);
}
void
test_iesimo_retorna_nodo_i
(
void
)
{
TEST
(
test_iesimo_retorna_nodo_i
)
{
lista_t
*
mi_lista
=
nueva_lista
();
uint32_t
arr1
[]
=
{
222
,
23
,
4
,
33
,
1288
};
uint32_t
arr2
[]
=
{
223
,
24
,
5
,
34
,
1289
};
uint32_t
arr3
[]
=
{
232
,
33
,
5
,
43
,
2288
};
lista_t
*
mi_lista
=
nueva_lista
();
uint32_t
arr1
[]
=
{
222
,
23
,
4
,
33
,
1288
};
uint32_t
arr2
[]
=
{
223
,
24
,
5
,
34
,
1289
};
uint32_t
arr3
[]
=
{
232
,
33
,
5
,
43
,
2288
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
)
);
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
)
);
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
)
);
nodo_t
*
nodo_inicial
=
iesimo
(
mi_lista
,
0
);
nodo_t
*
nodo_medio
=
iesimo
(
mi_lista
,
1
);
nodo_t
*
nodo_final
=
iesimo
(
mi_lista
,
2
);
nodo_t
*
nodo_inicial
=
iesimo
(
mi_lista
,
0
);
nodo_t
*
nodo_medio
=
iesimo
(
mi_lista
,
1
);
nodo_t
*
nodo_final
=
iesimo
(
mi_lista
,
2
);
assert
(
arrays_son_iguales
(
nodo_inicial
->
arreglo
,
nodo_inicial
->
longitud
,
arr1
,
ARRAY_SIZE
(
arr1
)));
assert
(
arrays_son_iguales
(
nodo_medio
->
arreglo
,
nodo_medio
->
longitud
,
arr2
,
ARRAY_SIZE
(
arr2
)));
assert
(
arrays_son_iguales
(
nodo_final
->
arreglo
,
nodo_final
->
longitud
,
arr3
,
ARRAY_SIZE
(
arr3
)));
destruir_lista
(
mi_lista
);
printf
(
"¡Pasó el test test_iesimo_retorna_nodo_i!
\n
"
);
TEST_ASSERT
(
arrays_son_iguales
(
nodo_inicial
->
arreglo
,
nodo_inicial
->
longitud
,
arr1
,
ARRAY_SIZE
(
arr1
)));
TEST_ASSERT
(
arrays_son_iguales
(
nodo_medio
->
arreglo
,
nodo_medio
->
longitud
,
arr2
,
ARRAY_SIZE
(
arr2
)));
TEST_ASSERT
(
arrays_son_iguales
(
nodo_final
->
arreglo
,
nodo_final
->
longitud
,
arr3
,
ARRAY_SIZE
(
arr3
)));
destruir_lista
(
mi_lista
);
}
void
test_cantidad_total_de_elementos
(
void
)
{
lista_t
*
mi_lista
=
nueva_lista
();
assert
(
cantidad_total_de_elementos
(
mi_lista
)
==
0
);
//uint32_t* array = malloc(sizeof(uint32_t) * 12);
uint32_t
*
array
=
calloc
(
12
,
sizeof
(
uint32_t
));
//nodo_t* head_lista = malloc(sizeof(nodo_t));
nodo_t
*
head_lista
=
calloc
(
1
,
sizeof
(
nodo_t
));
for
(
size_t
i
=
0
;
i
<
12
;
i
++
)
{
array
[
i
]
=
i
;
}
head_lista
->
arreglo
=
array
;
head_lista
->
longitud
=
12
;
head_lista
->
next
=
NULL
;
mi_lista
->
head
=
head_lista
;
assert
(
cantidad_total_de_elementos
(
mi_lista
)
==
12
);
uint32_t
arr1
[
3
]
=
{
32
,
7
,
2
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
uint32_t
arr2
[
2
]
=
{
2
,
56
};
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
uint32_t
arr3
[
4
]
=
{
40
,
34
,
21
,
16
};
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
uint32_t
arr4
[
2
]
=
{
3
,
8
};
agregar_al_final
(
mi_lista
,
arr4
,
ARRAY_SIZE
(
arr4
));
uint32_t
arr5
[
1
]
=
{
2
};
agregar_al_final
(
mi_lista
,
arr5
,
ARRAY_SIZE
(
arr5
));
uint64_t
suma
=
cantidad_total_de_elementos
(
mi_lista
);
if
(
suma
!=
24
)
{
printf
(
"Fallo en cantidad_total_de_elementos
\n
"
);
exit
(
1
);
}
uint32_t
arr6
[
6
]
=
{
6
,
3
,
4
,
7
,
3
,
1
};
agregar_al_final
(
mi_lista
,
arr6
,
ARRAY_SIZE
(
arr6
));
suma
=
cantidad_total_de_elementos
(
mi_lista
);
if
(
suma
!=
30
)
{
printf
(
"Fallo en cantidad_total_de_elementos
\n
"
);
exit
(
1
);
}
destruir_lista
(
mi_lista
);
printf
(
"¡Pasó el test test_cantidad_total_de_elementos!
\n
"
);
}
void
test_lista_contiene_elemento
(
void
)
{
lista_t
*
mi_lista
=
nueva_lista
();
assert
(
lista_contiene_elemento
(
mi_lista
,
222
)
==
0
);
uint32_t
*
array
=
calloc
(
12
,
sizeof
(
uint32_t
));
nodo_t
*
head_lista
=
calloc
(
1
,
sizeof
(
nodo_t
));
for
(
size_t
i
=
0
;
i
<
12
;
i
++
)
{
array
[
i
]
=
i
;
}
head_lista
->
arreglo
=
array
;
head_lista
->
longitud
=
12
;
head_lista
->
next
=
NULL
;
mi_lista
->
head
=
head_lista
;
assert
(
lista_contiene_elemento
(
mi_lista
,
13
)
==
0
);
assert
(
lista_contiene_elemento
(
mi_lista
,
8
)
==
1
);
uint32_t
arr1
[
3
]
=
{
32
,
7
,
2
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
uint32_t
arr2
[
2
]
=
{
2
,
56
};
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
uint32_t
arr3
[
4
]
=
{
40
,
34
,
21
,
16
};
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
uint32_t
arr4
[
2
]
=
{
3
,
8
};
agregar_al_final
(
mi_lista
,
arr4
,
ARRAY_SIZE
(
arr4
));
uint32_t
arr5
[
1
]
=
{
2
};
agregar_al_final
(
mi_lista
,
arr5
,
ARRAY_SIZE
(
arr5
));
int
result1
=
lista_contiene_elemento
(
mi_lista
,
32
);
if
(
result1
!=
1
)
{
printf
(
"Test 1 -- Fallo en lista_contiene_elemento
\n
"
);
exit
(
1
);
}
int
result2
=
lista_contiene_elemento
(
mi_lista
,
2
);
if
(
result2
!=
1
)
{
printf
(
"Test 2 -- Fallo en lista_contiene_elemento
\n
"
);
exit
(
1
);
}
int
result3
=
lista_contiene_elemento
(
mi_lista
,
100
);
if
(
result3
!=
0
)
{
printf
(
"Test 3 -- Fallo en lista_contiene_elemento
\n
"
);
exit
(
1
);
}
int
result4
=
lista_contiene_elemento
(
mi_lista
,
88
);
if
(
result4
!=
0
)
{
printf
(
"Test 4 -- Fallo en lista_contiene_elemento
\n
"
);
exit
(
1
);
}
int
result5
=
lista_contiene_elemento
(
mi_lista
,
99
);
if
(
result5
!=
0
)
{
printf
(
"Test 5 -- Fallo en lista_contiene_elemento
\n
"
);
exit
(
1
);
}
int
result6
=
lista_contiene_elemento
(
mi_lista
,
56
);
if
(
result6
!=
1
)
{
printf
(
"Test 6 -- Fallo en lista_contiene_elemento
\n
"
);
exit
(
1
);
}
destruir_lista
(
mi_lista
);
printf
(
"¡Pasó el test test_lista_contiene_elemento!
\n
"
);
TEST
(
test_cantidad_total_de_elementos
)
{
lista_t
*
mi_lista
=
nueva_lista
();
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
cantidad_total_de_elementos
(
mi_lista
));
uint32_t
*
array
=
calloc
(
12
,
sizeof
(
uint32_t
));
nodo_t
*
head_lista
=
calloc
(
1
,
sizeof
(
nodo_t
));
for
(
size_t
i
=
0
;
i
<
12
;
i
++
)
{
array
[
i
]
=
i
;
}
head_lista
->
arreglo
=
array
;
head_lista
->
longitud
=
12
;
head_lista
->
next
=
NULL
;
mi_lista
->
head
=
head_lista
;
TEST_ASSERT_EQUALS
(
uint64_t
,
12
,
cantidad_total_de_elementos
(
mi_lista
));
uint32_t
arr1
[
3
]
=
{
32
,
7
,
2
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
uint32_t
arr2
[
2
]
=
{
2
,
56
};
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
uint32_t
arr3
[
4
]
=
{
40
,
34
,
21
,
16
};
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
uint32_t
arr4
[
2
]
=
{
3
,
8
};
agregar_al_final
(
mi_lista
,
arr4
,
ARRAY_SIZE
(
arr4
));
uint32_t
arr5
[
1
]
=
{
2
};
agregar_al_final
(
mi_lista
,
arr5
,
ARRAY_SIZE
(
arr5
));
TEST_ASSERT_EQUALS
(
uint64_t
,
24
,
cantidad_total_de_elementos
(
mi_lista
));
uint32_t
arr6
[
6
]
=
{
6
,
3
,
4
,
7
,
3
,
1
};
agregar_al_final
(
mi_lista
,
arr6
,
ARRAY_SIZE
(
arr6
));
TEST_ASSERT_EQUALS
(
uint64_t
,
30
,
cantidad_total_de_elementos
(
mi_lista
));
destruir_lista
(
mi_lista
);
}
void
testear_todas_las_funciones
()
{
test_crear_lista
();
printf
(
"=========================================
\n
"
);
test_longitud_lista_vacia_es_cero
();
printf
(
"=========================================
\n
"
);
test_agregar_al_final
();
printf
(
"=========================================
\n
"
);
test_agregar_al_final_agrega_el_primer_nodo
();
printf
(
"=========================================
\n
"
);
test_iesimo_retorna_nodo_i
();
printf
(
"=========================================
\n
"
);
test_cantidad_total_de_elementos
();
printf
(
"=========================================
\n
"
);
test_lista_contiene_elemento
();
printf
(
"=========================================
\n
"
);
TEST
(
test_lista_contiene_elemento
)
{
lista_t
*
mi_lista
=
nueva_lista
();
TEST_ASSERT_EQUALS
(
int
,
0
,
lista_contiene_elemento
(
mi_lista
,
222
));
uint32_t
*
array
=
calloc
(
12
,
sizeof
(
uint32_t
));
nodo_t
*
head_lista
=
calloc
(
1
,
sizeof
(
nodo_t
));
for
(
size_t
i
=
0
;
i
<
12
;
i
++
)
{
array
[
i
]
=
i
;
}
head_lista
->
arreglo
=
array
;
head_lista
->
longitud
=
12
;
head_lista
->
next
=
NULL
;
mi_lista
->
head
=
head_lista
;
TEST_ASSERT_EQUALS
(
int
,
0
,
lista_contiene_elemento
(
mi_lista
,
13
));
TEST_ASSERT_EQUALS
(
int
,
1
,
lista_contiene_elemento
(
mi_lista
,
8
));
uint32_t
arr1
[
3
]
=
{
32
,
7
,
2
};
agregar_al_final
(
mi_lista
,
arr1
,
ARRAY_SIZE
(
arr1
));
uint32_t
arr2
[
2
]
=
{
2
,
56
};
agregar_al_final
(
mi_lista
,
arr2
,
ARRAY_SIZE
(
arr2
));
uint32_t
arr3
[
4
]
=
{
40
,
34
,
21
,
16
};
agregar_al_final
(
mi_lista
,
arr3
,
ARRAY_SIZE
(
arr3
));
uint32_t
arr4
[
2
]
=
{
3
,
8
};
agregar_al_final
(
mi_lista
,
arr4
,
ARRAY_SIZE
(
arr4
));
uint32_t
arr5
[
1
]
=
{
2
};
agregar_al_final
(
mi_lista
,
arr5
,
ARRAY_SIZE
(
arr5
));
TEST_ASSERT_EQUALS
(
int
,
1
,
lista_contiene_elemento
(
mi_lista
,
32
));
TEST_ASSERT_EQUALS
(
int
,
1
,
lista_contiene_elemento
(
mi_lista
,
2
));
TEST_ASSERT_EQUALS
(
int
,
0
,
lista_contiene_elemento
(
mi_lista
,
100
));
TEST_ASSERT_EQUALS
(
int
,
0
,
lista_contiene_elemento
(
mi_lista
,
88
));
TEST_ASSERT_EQUALS
(
int
,
0
,
lista_contiene_elemento
(
mi_lista
,
99
));
TEST_ASSERT_EQUALS
(
int
,
1
,
lista_contiene_elemento
(
mi_lista
,
56
));
destruir_lista
(
mi_lista
);
}
int
main
(
void
)
{
printf
(
"= Tests de lista_enlazada:
\n
"
);
printf
(
"=========================================
\n
"
);
testear_todas_las_funciones
();
printf
(
"¡Pasaron todos los tests!
\n
"
);
exit
(
0
);
}
\ No newline at end of file
printf
(
"= Tests de lista_enlazada:
\n
"
);
printf
(
"=========================================
\n
"
);
test_crear_lista
();
test_longitud_lista_vacia_es_cero
();
test_agregar_al_final
();
test_agregar_al_final_agrega_el_primer_nodo
();
test_iesimo_retorna_nodo_i
();
test_cantidad_total_de_elementos
();
test_lista_contiene_elemento
();
tests_end
();
return
0
;
}
This diff is collapsed.
Click to expand it.
TP1-a/src/tests_vector.c
View file @
3d4a3dc6
...
...
@@ -2,275 +2,202 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
void
test_nuevo_vector_crea_vector
(
void
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
assert
(
mi_vector
->
size
==
0
);
assert
(
mi_vector
->
capacity
==
2
);
assert
(
mi_vector
->
array
==
NULL
);
free
(
mi_vector
);
printf
(
"¡Pasó el test test_nuevo_vector_crea_vector
\n
"
);
#include "test-utils.h"
TEST
(
test_nuevo_vector_crea_vector
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
mi_vector
->
size
);
TEST_ASSERT_EQUALS
(
uint32_t
,
2
,
mi_vector
->
capacity
);
TEST_ASSERT
(
mi_vector
->
array
==
NULL
);
free
(
mi_vector
);
}
void
test_push_back_y_size
(
void
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
push_back
(
mi_vector
,
32
);
push_back
(
mi_vector
,
11
);
if
(
get_size
(
mi_vector
)
!=
2
)
{
printf
(
"Fallo en test_push_back_y_size
\n
"
);
exit
(
1
);
}
TEST
(
test_push_back_y_size
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
// TODO: Ver en cuánto aumenta la capacidad del vector para asertar correctamente el valor de la misma
assert
(
get_size
(
mi_vector
)
==
mi_vector
->
capacity
);
assert
(
mi_vector
->
capacity
==
2
);
push_back
(
mi_vector
,
32
);
push_back
(
mi_vector
,
11
);
push_back
(
mi_vector
,
5
);
assert
(
get_size
(
mi_vector
)
<=
mi_vector
->
capacity
);
assert
(
mi_vector
->
capacity
==
4
);
TEST_ASSERT_EQUALS
(
uint32_t
,
2
,
get_size
(
mi_vector
));
push_back
(
mi_vector
,
10
);
// TODO: Ver en cuánto aumenta la capacidad del vector para asertar
// correctamente el valor de la misma
TEST_ASSERT_EQUALS
(
uint32_t
,
mi_vector
->
capacity
,
get_size
(
mi_vector
));
TEST_ASSERT_EQUALS
(
uint32_t
,
2
,
mi_vector
->
capacity
);
if
(
get_size
(
mi_vector
)
!=
4
)
{
printf
(
"Fallo en test_push_back_y_size
\n
"
);
exit
(
1
);
}
push_back
(
mi_vector
,
5
);
TEST_ASSERT
(
get_size
(
mi_vector
)
<=
mi_vector
->
capacity
);
TEST_ASSERT_EQUALS
(
uint32_t
,
4
,
mi_vector
->
capacity
);
push_back
(
mi_vector
,
99
);
push_back
(
mi_vector
,
1
);
push_back
(
mi_vector
,
22
);
push_back
(
mi_vector
,
10
);
TEST_ASSERT_EQUALS
(
uint32_t
,
4
,
get_size
(
mi_vector
));
if
(
get_size
(
mi_vector
)
!=
7
||
mi_vector
->
capacity
!=
8
)
{
printf
(
"Fallo en test_push_back_y_size
\n
"
);
exit
(
1
);
}
push_back
(
mi_vector
,
99
);
push_back
(
mi_vector
,
1
);
push_back
(
mi_vector
,
22
);
fre
e
(
mi_vector
->
array
);
free
(
mi_vector
);
TEST_ASSERT_EQUALS
(
uint32_t
,
7
,
get_siz
e
(
mi_vector
)
);
TEST_ASSERT_EQUALS
(
uint32_t
,
8
,
mi_vector
->
capacity
);
printf
(
"¡Pasó el test test_push_back_y_size
\n
"
);
free
(
mi_vector
->
array
);
free
(
mi_vector
);
}
void
test_son_iguales
(
void
)
{
vector_t
*
mi_vectorA
=
nuevo_vector
();
push_back
(
mi_vectorA
,
1
);
push_back
(
mi_vectorA
,
2
);
push_back
(
mi_vectorA
,
3
);
vector_t
*
mi_vectorB
=
nuevo_vector
();
push_back
(
mi_vectorB
,
1
);
push_back
(
mi_vectorB
,
2
);
push_back
(
mi_vectorB
,
3
);
push_back
(
mi_vectorB
,
4
);
push_back
(
mi_vectorB
,
5
);
vector_t
*
mi_vectorC
=
nuevo_vector
();
push_back
(
mi_vectorC
,
1
);
push_back
(
mi_vectorC
,
2
);
push_back
(
mi_vectorC
,
3
);
vector_t
*
mi_vectorD
=
nuevo_vector
();
if
(
son_iguales
(
mi_vectorA
,
mi_vectorB
))
{
printf
(
"Test 1 -- Fallo en test_son_iguales
\n
"
);
exit
(
1
);
}
if
(
son_iguales
(
mi_vectorB
,
mi_vectorA
))
{
printf
(
"Test 2 -- Fallo en test_son_iguales
\n
"
);
exit
(
1
);
}
if
(
!
son_iguales
(
mi_vectorA
,
mi_vectorC
))
{
printf
(
"Test 3 -- Fallo en test_son_iguales
\n
"
);
exit
(
1
);
}
if
(
son_iguales
(
mi_vectorC
,
mi_vectorB
))
{
printf
(
"Test 4 -- Fallo en test_son_iguales
\n
"
);
exit
(
1
);
}
if
(
son_iguales
(
mi_vectorB
,
mi_vectorC
))
{
printf
(
"Test 5 -- Fallo en test_son_iguales
\n
"
);
exit
(
1
);
}
if
(
!
son_iguales
(
mi_vectorD
,
mi_vectorD
))
{
printf
(
"Test 6 -- Fallo en test_son_iguales
\n
"
);
exit
(
1
);
}
free
(
mi_vectorA
->
array
);
free
(
mi_vectorB
->
array
);
free
(
mi_vectorC
->
array
);
free
(
mi_vectorD
->
array
);
free
(
mi_vectorA
);
free
(
mi_vectorB
);
free
(
mi_vectorC
);
free
(
mi_vectorD
);
printf
(
"¡Pasó el test test_son_iguales
\n
"
);
TEST
(
test_son_iguales
)
{
vector_t
*
mi_vectorA
=
nuevo_vector
();
push_back
(
mi_vectorA
,
1
);
push_back
(
mi_vectorA
,
2
);
push_back
(
mi_vectorA
,
3
);
vector_t
*
mi_vectorB
=
nuevo_vector
();
push_back
(
mi_vectorB
,
1
);
push_back
(
mi_vectorB
,
2
);
push_back
(
mi_vectorB
,
3
);
push_back
(
mi_vectorB
,
4
);
push_back
(
mi_vectorB
,
5
);
vector_t
*
mi_vectorC
=
nuevo_vector
();
push_back
(
mi_vectorC
,
1
);
push_back
(
mi_vectorC
,
2
);
push_back
(
mi_vectorC
,
3
);
vector_t
*
mi_vectorD
=
nuevo_vector
();
TEST_ASSERT
(
son_iguales
(
mi_vectorA
,
mi_vectorB
)
==
0
);
TEST_ASSERT
(
son_iguales
(
mi_vectorB
,
mi_vectorA
)
==
0
);
TEST_ASSERT
(
son_iguales
(
mi_vectorA
,
mi_vectorC
)
==
1
);
TEST_ASSERT
(
son_iguales
(
mi_vectorC
,
mi_vectorB
)
==
0
);
TEST_ASSERT
(
son_iguales
(
mi_vectorB
,
mi_vectorC
)
==
0
);
TEST_ASSERT
(
son_iguales
(
mi_vectorD
,
mi_vectorD
)
==
1
);
free
(
mi_vectorA
->
array
);
free
(
mi_vectorB
->
array
);
free
(
mi_vectorC
->
array
);
free
(
mi_vectorD
->
array
);
free
(
mi_vectorA
);
free
(
mi_vectorB
);
free
(
mi_vectorC
);
free
(
mi_vectorD
);
}
void
test_iesimo
(
void
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
TEST
(
test_iesimo
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
push_back
(
mi_vector
,
2
*
i
);
}
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
if
(
iesimo
(
mi_vector
,
i
)
!=
2
*
i
)
{
printf
(
"Fallo en test_iesimo
\n
"
);
exit
(
1
);
}
}
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
push_back
(
mi_vector
,
2
*
i
);
}
assert
(
iesimo
(
mi_vector
,
222
)
==
0
);
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
TEST_ASSERT_EQUALS
(
uint32_t
,
2
*
i
,
iesimo
(
mi_vector
,
i
));
}
free
(
mi_vector
->
array
);
free
(
mi_vector
);
TEST_ASSERT_EQUALS
(
uint32_t
,
0
,
iesimo
(
mi_vector
,
222
));
printf
(
"¡Pasó el test test_iesimo
\n
"
);
free
(
mi_vector
->
array
);
free
(
mi_vector
);
}
TEST
(
test_copiar_iesimo
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
void
test_copiar_iesimo
(
void
)
{
vector_t
*
mi_vector
=
nuevo_vector
();
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
push_back
(
mi_vector
,
(
2
*
i
)
+
7
);
}
uint32_t
out
=
0
;
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
push_back
(
mi_vector
,
(
2
*
i
)
+
7
);
}
out
=
0
;
copiar_iesimo
(
mi_vector
,
i
,
&
out
);
uint32_t
out
=
0
;
if
(
out
!=
(
2
*
i
)
+
7
)
{
printf
(
"Fallo en test_copiar_iesimo
\n
"
);
exit
(
1
);
}
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
{
out
=
0
;
copiar_iesimo
(
mi_vector
,
i
,
&
out
);
TEST_ASSERT_EQUALS
(
uint32_t
,
(
2
*
i
)
+
7
,
out
);
}
}
free
(
mi_vector
->
array
);
free
(
mi_vector
);
printf
(
"¡Pasó el test test_copiar_iesimo
\n
"
);
free
(
mi_vector
->
array
);
free
(
mi_vector
);
}
void
test_vector_mas_grande_con_distinta_longitud_devuelve_el_mas_grande
(
void
)
{
vector_t
*
mi_vectorA
=
nuevo_vector
();
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
2
);
push_back
(
mi_vectorA
,
10
);
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
21
);
vector_t
*
mi_vectorB
=
nuevo_vector
();
push_back
(
mi_vectorB
,
11
);
push_back
(
mi_vectorB
,
3
);
push_back
(
mi_vectorB
,
30
);
push_back
(
mi_vectorB
,
300
);
push_back
(
mi_vectorB
,
311
);
push_back
(
mi_vectorB
,
31
);
vector_t
**
array_de_vectores
=
malloc
(
2
*
sizeof
(
vector_t
*
));
array_de_vectores
[
0
]
=
mi_vectorA
;
array_de_vectores
[
1
]
=
mi_vectorB
;
vector_t
*
vector_grande
=
vector_mas_grande
(
array_de_vectores
,
2
);
if
(
vector_grande
!=
mi_vectorB
)
{
printf
(
"Fallo en test_vector_mas_grande_con_distinta_longitud_devuelve_el_mas_grande
\n
"
);
exit
(
1
);
}
free
(
mi_vectorA
->
array
);
free
(
mi_vectorB
->
array
);
free
(
mi_vectorA
);
free
(
mi_vectorB
);
free
(
array_de_vectores
);
printf
(
"¡Pasó el test test_vector_mas_grande_con_distinta_longitud_devuelve_el_mas_grande
\n
"
);
TEST
(
test_vector_mas_grande_con_distinta_longitud_devuelve_el_mas_grande
)
{
vector_t
*
mi_vectorA
=
nuevo_vector
();
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
2
);
push_back
(
mi_vectorA
,
10
);
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
21
);
vector_t
*
mi_vectorB
=
nuevo_vector
();
push_back
(
mi_vectorB
,
11
);
push_back
(
mi_vectorB
,
3
);
push_back
(
mi_vectorB
,
30
);
push_back
(
mi_vectorB
,
300
);
push_back
(
mi_vectorB
,
311
);
push_back
(
mi_vectorB
,
31
);
vector_t
**
array_de_vectores
=
malloc
(
2
*
sizeof
(
vector_t
*
));
array_de_vectores
[
0
]
=
mi_vectorA
;
array_de_vectores
[
1
]
=
mi_vectorB
;
vector_t
*
vector_grande
=
vector_mas_grande
(
array_de_vectores
,
2
);
TEST_ASSERT
(
vector_grande
==
mi_vectorB
);
free
(
mi_vectorA
->
array
);
free
(
mi_vectorB
->
array
);
free
(
mi_vectorA
);
free
(
mi_vectorB
);
free
(
array_de_vectores
);
}
void
test_vector_mas_grande_con_misma_longitud_devuelve_el_primero
(
void
)
{
vector_t
*
mi_vectorA
=
nuevo_vector
();
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
2
);
push_back
(
mi_vectorA
,
10
);
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
21
);
push_back
(
mi_vectorA
,
199
);
vector_t
*
mi_vectorB
=
nuevo_vector
();
push_back
(
mi_vectorB
,
11
);
push_back
(
mi_vectorB
,
3
);
push_back
(
mi_vectorB
,
30
);
push_back
(
mi_vectorB
,
300
);
push_back
(
mi_vectorB
,
311
);
push_back
(
mi_vectorB
,
31
);
vector_t
**
array_de_vectores
=
malloc
(
2
*
sizeof
(
vector_t
*
));
array_de_vectores
[
0
]
=
mi_vectorA
;
array_de_vectores
[
1
]
=
mi_vectorB
;
vector_t
*
vector_grande
=
vector_mas_grande
(
array_de_vectores
,
2
);
if
(
vector_grande
!=
mi_vectorA
)
{
printf
(
"Fallo en test_vector_mas_grande_con_misma_longitud_devuelve_el_primero
\n
"
);
exit
(
1
);
}
free
(
mi_vectorA
->
array
);
free
(
mi_vectorB
->
array
);
free
(
mi_vectorA
);
free
(
mi_vectorB
);
free
(
array_de_vectores
);
printf
(
"¡Pasó el test test_vector_mas_grande_con_misma_longitud_devuelve_el_primero
\n
"
);
TEST
(
test_vector_mas_grande_con_misma_longitud_devuelve_el_primero
)
{
vector_t
*
mi_vectorA
=
nuevo_vector
();
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
2
);
push_back
(
mi_vectorA
,
10
);
push_back
(
mi_vectorA
,
3
);
push_back
(
mi_vectorA
,
21
);
push_back
(
mi_vectorA
,
199
);
vector_t
*
mi_vectorB
=
nuevo_vector
();
push_back
(
mi_vectorB
,
11
);
push_back
(
mi_vectorB
,
3
);
push_back
(
mi_vectorB
,
30
);
push_back
(
mi_vectorB
,
300
);
push_back
(
mi_vectorB
,
311
);
push_back
(
mi_vectorB
,
31
);
vector_t
**
array_de_vectores
=
malloc
(
2
*
sizeof
(
vector_t
*
));
array_de_vectores
[
0
]
=
mi_vectorA
;
array_de_vectores
[
1
]
=
mi_vectorB
;
vector_t
*
vector_grande
=
vector_mas_grande
(
array_de_vectores
,
2
);
TEST_ASSERT
(
vector_grande
==
mi_vectorA
);
free
(
mi_vectorA
->
array
);
free
(
mi_vectorB
->
array
);
free
(
mi_vectorA
);
free
(
mi_vectorB
);
free
(
array_de_vectores
);
}
void
test_vector_mas_grande_con_arreglo_vacio_retorna_null
(
void
)
{
vector_t
**
array_de_vectores
=
malloc
(
0
*
sizeof
(
vector_t
*
));
vector_t
*
vector_grande
=
vector_mas_grande
(
array_de_vectores
,
0
);
if
(
vector_grande
!=
NULL
)
{
printf
(
"Fallo en test_vector_mas_grande_con_arreglo_vacio_retorna_null
\n
"
);
exit
(
1
);
}
free
(
array_de_vectores
);
TEST
(
test_vector_mas_grande_con_arreglo_vacio_retorna_null
)
{
vector_t
**
array_de_vectores
=
NULL
;
vector_t
*
vector_grande
=
vector_mas_grande
(
array_de_vectores
,
0
);
printf
(
"¡Pasó el test test_
vector_
mas_
grande
_con_arreglo_nulo_retorna_null
\n
"
);
TEST_ASSERT
(
vector_grande
==
NULL
);
}
int
main
()
{
printf
(
"= Tests de vector:
\n
"
);
printf
(
"=========================================
\n
"
);
test_push_back_y_size
();
printf
(
"=========================================
\n
"
);
test_son_iguales
();
printf
(
"=========================================
\n
"
);
test_iesimo
();
printf
(
"=========================================
\n
"
);
test_copiar_iesimo
();
printf
(
"=========================================
\n
"
);
test_vector_mas_grande_con_distinta_longitud_devuelve_el_mas_grande
();
printf
(
"=========================================
\n
"
);
test_vector_mas_grande_con_misma_longitud_devuelve_el_primero
();
printf
(
"=========================================
\n
"
);
test_vector_mas_grande_con_arreglo_vacio_retorna_null
();
printf
(
"=========================================
\n
"
);
printf
(
"¡Pasaron todos los tests!
\n
"
);
exit
(
0
);
printf
(
"= Tests de vector:
\n
"
);
printf
(
"=========================================
\n
"
);
test_nuevo_vector_crea_vector
();
test_push_back_y_size
();
test_son_iguales
();
test_iesimo
();
test_copiar_iesimo
();
test_vector_mas_grande_con_distinta_longitud_devuelve_el_mas_grande
();
test_vector_mas_grande_con_misma_longitud_devuelve_el_primero
();
test_vector_mas_grande_con_arreglo_vacio_retorna_null
();
tests_end
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment