From fb456880a7c9d0329e7925c47e0cef33fcd68f67 Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 26 Dec 2024 00:57:09 +0200 Subject: [PATCH] tests --- CMakeLists.txt | 92 +++++++++++++++++++++++++++ src/check_raw_string.c | 34 ++++++++++ src/fillit.c | 11 ++++ src/test!_check.c | 38 +++++++++++ src/test!_print_one_string.c | 31 +++++++++ src/test!_print_table.c | 30 +++++++++ src/to_letters.c | 37 +++++++++++ tests/color_letters.c | 42 +++++++++++++ tests/rand_test.py | 46 ++++++++++++++ tests/sample.fillit | 21 +++++++ tests/sample1.fillit | 19 ++++++ tests/sample2.fillit | 34 ++++++++++ tests/sample3.fillit | 19 ++++++ tests/sample4.fillit | 39 ++++++++++++ tests/sample5.fillit | 4 ++ tests/sample6.fillit | 119 +++++++++++++++++++++++++++++++++++ 16 files changed, 616 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/check_raw_string.c create mode 100644 src/fillit.c create mode 100644 src/test!_check.c create mode 100644 src/test!_print_one_string.c create mode 100644 src/test!_print_table.c create mode 100644 src/to_letters.c create mode 100644 tests/color_letters.c create mode 100755 tests/rand_test.py create mode 100644 tests/sample.fillit create mode 100644 tests/sample1.fillit create mode 100644 tests/sample2.fillit create mode 100644 tests/sample3.fillit create mode 100644 tests/sample4.fillit create mode 100644 tests/sample5.fillit create mode 100644 tests/sample6.fillit diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b52e1ba --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,92 @@ +cmake_minimum_required(VERSION 3.5.2) +project(fillit) + +set(CMAKE_CXX_STANDARD 11) + +include_directories(inc) +include_directories(libft) + +set(SOURCE_FILES + libft/ft_atoi.c + libft/ft_bzero.c + libft/ft_isalnum.c + libft/ft_isalpha.c + libft/ft_isascii.c + libft/ft_isdigit.c + libft/ft_isprint.c + libft/ft_itoa.c + libft/ft_lst_at.c + libft/ft_lstadd.c + libft/ft_lstadd_back.c + libft/ft_lstdel.c + libft/ft_lstdelone.c + libft/ft_lstfind.c + libft/ft_lstiter.c + libft/ft_lstmap.c + libft/ft_lstnew.c + libft/ft_lststrsplit.c + libft/ft_memalloc.c + libft/ft_memccpy.c + libft/ft_memchr.c + libft/ft_memcmp.c + libft/ft_memcpy.c + libft/ft_memdel.c + libft/ft_memmove.c + libft/ft_memset.c + libft/ft_putchar.c + libft/ft_putchar_fd.c + libft/ft_putendl.c + libft/ft_putendl_fd.c + libft/ft_putnbr.c + libft/ft_putnbr_fd.c + libft/ft_putstr.c + libft/ft_putstr_fd.c + libft/ft_realloc.c + libft/ft_strcat.c + libft/ft_strchr.c + libft/ft_strclr.c + libft/ft_strcmp.c + libft/ft_strcpy.c + libft/ft_strdel.c + libft/ft_strdup.c + libft/ft_strequ.c + libft/ft_striter.c + libft/ft_striteri.c + libft/ft_strjoin.c + libft/ft_strlcat.c + libft/ft_strlen.c + libft/ft_strmap.c + libft/ft_strmapi.c + libft/ft_strncat.c + libft/ft_strncmp.c + libft/ft_strncpy.c + libft/ft_strnequ.c + libft/ft_strnew.c + libft/ft_strnstr.c + libft/ft_strrchr.c + libft/ft_strsplit.c + libft/ft_strstr.c + libft/ft_strsub.c + libft/ft_strtrim.c + libft/ft_tolower.c + libft/ft_toupper.c + libft/ft_lstpop.c + libft/libft.h + src/check_raw_string.c + src/dancing_links.c + src/fillit.c + src/get_types.c + src/glue_figure.c + src/main.c + src/move_up_left.c + src/read_file.c + src/string_to_table.c + src/test!_check.c + src/test!_print_one_string.c + src/test!_print_table.c + src/to_letters.c + src/get_amount.c + tests/sample.fillit + tests/sample1.fillit) + +add_executable(fillit ${SOURCE_FILES}) \ No newline at end of file diff --git a/src/check_raw_string.c b/src/check_raw_string.c new file mode 100644 index 0000000..9376456 --- /dev/null +++ b/src/check_raw_string.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* check_raw_string.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/15 18:32:54 by gtertysh #+# #+# */ +/* Updated: 2016/12/15 18:32:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int check_raw_string(char *raw_string) +{ + int n_count; + + n_count = 0; + if (*raw_string == 0 || *raw_string == '\n') + return (1); + while(*raw_string) + { + if (*raw_string == '\n') + n_count++; + if ((n_count + 1) % 4 == 0) + if (*(raw_string + 1) != '\0') + if (*(raw_string + 1) != '\n' && !(*(raw_string + 2) == '.' || *(raw_string + 2) == '#')) + return (1); + raw_string++; + + } + if (n_count < 3) + return (1); + return (0); +} \ No newline at end of file diff --git a/src/fillit.c b/src/fillit.c new file mode 100644 index 0000000..cea1c54 --- /dev/null +++ b/src/fillit.c @@ -0,0 +1,11 @@ +#include "fillit.h" + +unsigned int ft_sqrt_ceil(unsigned int num) +{ + unsigned int i; + + i = 1; + while (i * i < num) + i++; + return (i); +} \ No newline at end of file diff --git a/src/test!_check.c b/src/test!_check.c new file mode 100644 index 0000000..6f89662 --- /dev/null +++ b/src/test!_check.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test!_check.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/14 17:26:13 by gtertysh #+# #+# */ +/* Updated: 2016/12/20 19:02:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../inc/fillit.h" + +// Test func. Compare figures from file +// with templates +void test_check(char **ttr, t_ttrmn *templates) +{ + int i; + int j; + + i = 0; + while (ttr[i]) + { + j = 0; + while(j < 19) + { + if ((ft_memcmp(ttr[i], templates[j].t, 17) == 0)) + { + printf(" match!\n"); + print_one_string(templates[j]); + break; + } + j++; + } + i++; + } +} diff --git a/src/test!_print_one_string.c b/src/test!_print_one_string.c new file mode 100644 index 0000000..d215baf --- /dev/null +++ b/src/test!_print_one_string.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test!_print_one_string.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/14 17:09:23 by gtertysh #+# #+# */ +/* Updated: 2016/12/14 17:09:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../inc/fillit.h" + +// Test func. Print table but one string contain whole figure. +void print_one_string(t_ttrmn ttr) +{ + int i; + + i = 0; + while (ttr.t[i]) + { + ft_putchar(ttr.t[i]); + if ((i + 1) % 4 == 0) + ft_putchar('\n'); + i++; + } + printf("x = %d, y = %d\n", ttr.width, ttr.height); + printf("x1[%d] y1[%d]\nx2[%d] y2[%d]\nx3[%d] y3[%d]\nx4[%d] y4[%d]\n", ttr.c[0].x, ttr.c[0].y, ttr.c[1].x, ttr.c[1].y, ttr.c[2].x, ttr.c[2].y, ttr.c[3].x, ttr.c[3].y); + ft_putstr("\n"); +} \ No newline at end of file diff --git a/src/test!_print_table.c b/src/test!_print_table.c new file mode 100644 index 0000000..475b8e2 --- /dev/null +++ b/src/test!_print_table.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test!_print_table.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/14 17:07:19 by gtertysh #+# #+# */ +/* Updated: 2016/12/14 17:07:22 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../inc/fillit.h" + +// Test func. Print string table, +// each line - line of tetromino figure. +void print_table(char **table) +{ + int i; + + i = 0; + while (table[i]) + { + ft_putstr(table[i]); + ft_putstr("\n"); + if ((i + 1) % 4 == 0) + ft_putchar('\n'); + i++; + } +} \ No newline at end of file diff --git a/src/to_letters.c b/src/to_letters.c new file mode 100644 index 0000000..76a187d --- /dev/null +++ b/src/to_letters.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* to_letters.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/14 17:21:37 by gtertysh #+# #+# */ +/* Updated: 2016/12/14 17:21:39 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../inc/fillit.h" + +// convert "#" symbols to letters +// rewrite for new method with structures +void to_letters(char **ttr) +{ + char ch; + int i; + int j; + + i = 0; + ch = 'A'; + while(ttr[i]) + { + j = 0; + while(ttr[i][j]) + { + if(ttr[i][j] == '#') + ttr[i][j] = ch; + j++; + } + i++; + ch++; + } +} \ No newline at end of file diff --git a/tests/color_letters.c b/tests/color_letters.c new file mode 100644 index 0000000..2dc0055 --- /dev/null +++ b/tests/color_letters.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color_letters.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kyork +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/04 16:44:50 by kyork #+# #+# */ +/* Updated: 2016/10/05 15:41:53 by kyork ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#define CSI "\033[" +#include +#include + +int g_colors[] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, + 16 + 5, 16 + 12, 16 + 23, 16 + 30, 52 + 0, 52 + 5, 52 + 6, 52 + 12, 52 + 20, + 88 + 1, 88 + 6, 88 + 12, 160 + 12, 196 + 30, 160 + 21}; + +int main(void) +{ + char c; + ssize_t read_size; + + while (1) + { + read_size = read(0, &c, 1); + if (read_size == 0) + break ; + if ('A' <= c && c <= 'Z') + { + printf("%s48;5;%dm%c", CSI, g_colors[c - 'A'], c); + } + else if (c == '.') + printf("%sm%c", CSI, c); + else if (c == '\n') + printf("%sm%c", CSI, c); + else + printf("%c", c); + } +} diff --git a/tests/rand_test.py b/tests/rand_test.py new file mode 100755 index 0000000..2d9233e --- /dev/null +++ b/tests/rand_test.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +from __future__ import print_function + +tet_shapes = [ + '####\n....\n....\n....\n', + '#...\n#...\n#...\n#...\n', + '#...\n###.\n....\n....\n', + '##..\n#...\n#...\n....\n', + '###.\n..#.\n....\n....\n', + '.#..\n.#..\n##..\n....\n', + '..#.\n###.\n....\n....\n', + '#...\n#...\n##..\n....\n', + '###.\n#...\n....\n....\n', + '##..\n.#..\n.#..\n....\n', + '##..\n##..\n....\n....\n', + '.##.\n##..\n....\n....\n', + '#...\n##..\n.#..\n....\n', + '.#..\n###.\n....\n....\n', + '#...\n##..\n#...\n....\n', + '###.\n.#..\n....\n....\n', + '.#..\n##..\n.#..\n....\n', + '##..\n.##.\n....\n....\n', + '.#..\n##..\n#...\n....\n', +] + +import argparse +import random +import os + +parser = argparse.ArgumentParser(description="Generate random fillit problems") +parser.add_argument('count', metavar="count", type=int, default=10, nargs='?', + help="number of tetrominoes to output") +parser.add_argument('--seed', type=int, default=None, + help="mt_rand seed (to reproduce problems)") + +args = parser.parse_args() + +seed = args.seed +if seed is None: + seed = random.SystemRandom().randint(0, 2**19937-1) + +random.seed(seed) + +tets = [tet_shapes[random.randrange(len(tet_shapes))] for x in range(args.count)] + +[print(x, end=("" if i == len(tets) - 1 else "\n")) for i, x in enumerate(tets)] \ No newline at end of file diff --git a/tests/sample.fillit b/tests/sample.fillit new file mode 100644 index 0000000..84e79f4 --- /dev/null +++ b/tests/sample.fillit @@ -0,0 +1,21 @@ +.... +##.. +.#.. +.#.. + +.... +#### +.... +.... + +#... +###. +.... +.... + +.... +##.. +.##. +.... + + diff --git a/tests/sample1.fillit b/tests/sample1.fillit new file mode 100644 index 0000000..cfb9f31 --- /dev/null +++ b/tests/sample1.fillit @@ -0,0 +1,19 @@ +.... +##.. +.#.. +.#.. + +..#. +###. +.... +.... + +.... +##.. +##.. +.... + +#### +.... +.... +.... diff --git a/tests/sample2.fillit b/tests/sample2.fillit new file mode 100644 index 0000000..fa06f41 --- /dev/null +++ b/tests/sample2.fillit @@ -0,0 +1,34 @@ +#### +.... +.... +.... + +#### +.... +.... +.... + +#### +.... +.... +.... + +#### +.... +.... +.... + +#### +.... +.... +.... + +#### +.... +.... +.... + +#### +.... +.... +.... diff --git a/tests/sample3.fillit b/tests/sample3.fillit new file mode 100644 index 0000000..032b064 --- /dev/null +++ b/tests/sample3.fillit @@ -0,0 +1,19 @@ +.... +##.. +.#.. +.#.. + +.... +#### +.... +.... + +#... +###. +.... +.... + +.... +##.. +.##. +.... \ No newline at end of file diff --git a/tests/sample4.fillit b/tests/sample4.fillit new file mode 100644 index 0000000..d275539 --- /dev/null +++ b/tests/sample4.fillit @@ -0,0 +1,39 @@ +...# +...# +...# +...# + +.... +.... +.... +#### + +.### +...# +.... +.... + +.... +..## +.##. +.... + +.... +.##. +.##. +.... + +.... +.... +##.. +.##. + +##.. +.#.. +.#.. +.... + +.... +###. +.#.. +.... \ No newline at end of file diff --git a/tests/sample5.fillit b/tests/sample5.fillit new file mode 100644 index 0000000..d24b25d --- /dev/null +++ b/tests/sample5.fillit @@ -0,0 +1,4 @@ +.... +..## +.##. +.... \ No newline at end of file diff --git a/tests/sample6.fillit b/tests/sample6.fillit new file mode 100644 index 0000000..d7cc980 --- /dev/null +++ b/tests/sample6.fillit @@ -0,0 +1,119 @@ +...# +...# +...# +...# + +.... +.... +.... +#### + +.### +...# +.... +.... + +.... +..## +.##. +.... + +.... +.##. +.##. +.... + +.... +.... +##.. +.##. + +##.. +.#.. +.#.. +.... + +.... +###. +.#.. +.... + +...# +...# +...# +...# + +.... +.... +.... +#### + +.### +...# +.... +.... + +.... +..## +.##. +.... + +.... +.##. +.##. +.... + +.... +.... +##.. +.##. + +##.. +.#.. +.#.. +.... + +.... +###. +.#.. +.... + +...# +...# +...# +...# + +.... +.... +.... +#### + +.### +...# +.... +.... + +.... +..## +.##. +.... + +.... +.##. +.##. +.... + +.... +.... +##.. +.##. + +##.. +.#.. +.#.. +.... + +.... +###. +.#.. +.... \ No newline at end of file