Testcases and cleaner code
This commit is contained in:
parent
73b1e189c4
commit
47fd54f893
|
@ -12,7 +12,7 @@ _OBJ=$(SRC:.c=.o)
|
||||||
DEPS=$(patsubst %,$(INCDIR)/%,$(HEADERS))
|
DEPS=$(patsubst %,$(INCDIR)/%,$(HEADERS))
|
||||||
OBJ=$(patsubst %,$(OBJDIR)/%,$(_OBJ))
|
OBJ=$(patsubst %,$(OBJDIR)/%,$(_OBJ))
|
||||||
|
|
||||||
.PHONY: clean install uninstall fclean all re
|
.PHONY: clean install uninstall fclean all re test
|
||||||
|
|
||||||
all: $(BUILDDIR)/$(NAME)
|
all: $(BUILDDIR)/$(NAME)
|
||||||
|
|
||||||
|
@ -40,3 +40,13 @@ uninstall:
|
||||||
$(RM) $(DESTDIR)$(PREFIX)/bin/$(NAME)
|
$(RM) $(DESTDIR)$(PREFIX)/bin/$(NAME)
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|
||||||
|
SUCCESS=printf '\n\033[32m%s\033[m\n\n' "Success"
|
||||||
|
FAIL=printf '\n\033[31m%s\033[m\n\n' "Fail"
|
||||||
|
test: re
|
||||||
|
$(BUILDDIR)/$(NAME) && $(FAIL) || $(SUCCESS)
|
||||||
|
$(BUILDDIR)/$(NAME) "4 3 2 1 1 2 2 2 4 3 2 1 1 2 2 2 " && $(FAIL) || $(SUCCESS)
|
||||||
|
$(BUILDDIR)/$(NAME) "4 3 2 1 1 2 2 2 4 3 2 1 1 2 2 6" && $(FAIL) || $(SUCCESS)
|
||||||
|
$(BUILDDIR)/$(NAME) "4 3 2 1 1 2 2 2 4 3 2 1 1 2 2 a" && $(FAIL) || $(SUCCESS)
|
||||||
|
$(BUILDDIR)/$(NAME) "4 3 2 1 1 2 2 2 4 3 2 1 1 2 2 2" whatever && $(FAIL) || $(SUCCESS)
|
||||||
|
$(BUILDDIR)/$(NAME) "4 3 2 1 1 2 2 2 4 3 2 1 1 2 2 2" && $(SUCCESS) || $(FAIL)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: smatthes <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: smatthes <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/25 19:41:44 by smatthes #+# #+# */
|
/* Created: 2023/03/25 19:41:44 by smatthes #+# #+# */
|
||||||
/* Updated: 2023/03/26 20:31:24 by akarami ### ########.fr */
|
/* Updated: 2023/03/26 21:31:51 by akarami ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -23,9 +23,10 @@ int str_len(char *str)
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void put_error(void)
|
int put_error(int exit_code)
|
||||||
{
|
{
|
||||||
write(1, "Error\n", 6);
|
write(1, "Error\n", 6);
|
||||||
|
return (exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int *find_position(int **board, int n, int *pos)
|
int *find_position(int **board, int n, int *pos)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: smatthes <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: smatthes <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/25 19:45:42 by smatthes #+# #+# */
|
/* Created: 2023/03/25 19:45:42 by smatthes #+# #+# */
|
||||||
/* Updated: 2023/03/26 21:23:02 by akarami ### ########.fr */
|
/* Updated: 2023/03/26 21:28:15 by akarami ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -14,15 +14,22 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "include/handle_mem.h"
|
#include "include/handle_mem.h"
|
||||||
|
|
||||||
|
// Allocates memory and initialized with 0's
|
||||||
int **alloc_mem(int n)
|
int **alloc_mem(int n)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int j;
|
||||||
int **board;
|
int **board;
|
||||||
|
|
||||||
board = malloc(n * 8);
|
board = malloc(n * 8);
|
||||||
i = -1;
|
i = -1;
|
||||||
while (++i < n)
|
while (++i < n)
|
||||||
|
{
|
||||||
board[i] = malloc(n * 4);
|
board[i] = malloc(n * 4);
|
||||||
|
j = -1;
|
||||||
|
while (++j < n)
|
||||||
|
board[i][j] = 0;
|
||||||
|
}
|
||||||
return (board);
|
return (board);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: akarami <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: akarami <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/26 19:35:52 by akarami #+# #+# */
|
/* Created: 2023/03/26 19:35:52 by akarami #+# #+# */
|
||||||
/* Updated: 2023/03/26 19:59:09 by akarami ### ########.fr */
|
/* Updated: 2023/03/26 21:32:10 by akarami ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
# define GEN_UTIL_H
|
# define GEN_UTIL_H
|
||||||
|
|
||||||
int str_len(char *str);
|
int str_len(char *str);
|
||||||
void put_error(void);
|
int put_error(int exit_code);
|
||||||
void ft_putchar(char c);
|
void ft_putchar(char c);
|
||||||
int *find_position(int **board, int n, int *pos);
|
int *find_position(int **board, int n, int *pos);
|
||||||
void print_board(int **board, int n);
|
void print_board(int **board, int n);
|
||||||
|
|
15
ex00/main.c
15
ex00/main.c
|
@ -6,7 +6,7 @@
|
||||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/26 06:13:07 by tischmid #+# #+# */
|
/* Created: 2023/03/26 06:13:07 by tischmid #+# #+# */
|
||||||
/* Updated: 2023/03/26 20:58:51 by akarami ### ########.fr */
|
/* Updated: 2023/03/26 21:31:20 by akarami ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
void print_board(int **board, int n);
|
void print_board(int **board, int n);
|
||||||
|
|
||||||
|
/*
|
||||||
void init_board(int **board)
|
void init_board(int **board)
|
||||||
{
|
{
|
||||||
board[0][0] = 1;
|
board[0][0] = 1;
|
||||||
|
@ -39,6 +40,7 @@ void init_board(int **board)
|
||||||
board[3][3] = 3;
|
board[3][3] = 3;
|
||||||
board[3][3] = 3;
|
board[3][3] = 3;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -49,18 +51,11 @@ int main(int argc, char **argv)
|
||||||
n = 4;
|
n = 4;
|
||||||
borders = malloc(n * 4 * 4);
|
borders = malloc(n * 4 * 4);
|
||||||
board = alloc_mem(n);
|
board = alloc_mem(n);
|
||||||
init_board(board);
|
|
||||||
print_board(board, n);
|
print_board(board, n);
|
||||||
if (!handle_input(argc, argv, borders, n))
|
if (!handle_input(argc, argv, borders, n))
|
||||||
{
|
return (put_error(1));
|
||||||
put_error();
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (!backtrack(board, n, borders))
|
if (!backtrack(board, n, borders))
|
||||||
{
|
return (put_error(2));
|
||||||
put_error();
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
free_mem(borders, board, n);
|
free_mem(borders, board, n);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue