aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md146
-rw-r--r--src/mem/ft_memmem.c30
-rw-r--r--src/mem/ft_memset_pattern4.c5
-rw-r--r--test/include/libft_test.h3
-rw-r--r--test/src/mem/test_ft_calloc.c17
-rw-r--r--test/src/mem/test_ft_memccpy.c21
-rw-r--r--test/src/mem/test_ft_memchr.c11
-rw-r--r--test/src/mem/test_ft_memcmp.c18
-rw-r--r--test/src/mem/test_ft_memmem.c41
-rw-r--r--test/src/mem/test_ft_memmove.c15
-rw-r--r--test/src/mem/test_ft_memset_pattern4.c18
-rw-r--r--test/src/runner/test_runner_mem.c3
-rw-r--r--test/test_runner_mem.c12
13 files changed, 231 insertions, 109 deletions
diff --git a/README.md b/README.md
index 0d6b8cd..088da89 100644
--- a/README.md
+++ b/README.md
@@ -30,48 +30,44 @@ Much like the `.gitignore` file, you can put the files/directory to ignore when
### mem
-
-
-
-
| Name | Prototype | Description | Tested |
|--------------------|-------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|--------|
| ft_bzero | `void ft_bzero(void *s, size_t n)` | fill `n` bytes of `s` with 0 | [x] |
-| ft_calloc | `void *ft_calloc(size_t count, size_t size)` | allocate `count` element of `size` and initialize them to 0 | [ ] |
-| ft_memccpy | `void *ft_memccpy(void *dest, const void *src, int c, size_t n)` | copy `n` byte from `src` to `dest` until `c` is reached | [ ] |
-| ft_memchr | `void *ft_memchr(const void *s, int c, size_t n)` | return the address of the first occurance of `c` in `s` or NULL if `c` isn't found | [ ] |
-| ft_memcmp | `int ft_memcmp(const void *s1, const void *s2, size_t n)` | compare `n` byte of `s1` and `s2` | [ ] |
+| ft_calloc | `void *ft_calloc(size_t count, size_t size)` | allocate `count` element of `size` and initialize them to 0 | [x] |
+| ft_memccpy | `void *ft_memccpy(void *dest, const void *src, int c, size_t n)` | copy `n` byte from `src` to `dest` until `c` is reached | [x] |
+| ft_memchr | `void *ft_memchr(const void *s, int c, size_t n)` | return the address of the first occurance of `c` in `s` or NULL if `c` isn't found | [x] |
+| ft_memcmp | `int ft_memcmp(const void *s1, const void *s2, size_t n)` | compare `n` byte of `s1` and `s2` | [x] |
| ft_memcpy | `void *ft_memcpy(void *dest, const void *src, size_t n)` | copy `n` byte from `src` to `dest` | [x] |
-| ft_memmem | `void *ft_memmem(const void *big, size_t big_len, const void *little, size_t little_len)` | search `little` in `big` | [ ] |
-| ft_memmove | `void *ft_memmove(void *dst, const void *src, size_t len)` | copy `len` byte from `src` to `dst` and the copied memory can overlap | [ ] |
+| ft_memmem | `void *ft_memmem(const void *big, size_t big_len, const void *little, size_t little_len)` | search `little` in `big` | [x] |
+| ft_memmove | `void *ft_memmove(void *dst, const void *src, size_t len)` | copy `len` byte from `src` to `dst` and the copied memory can overlap | [x] |
| ft_memset | `void *ft_memset(void *s, int c, size_t n)` | set `n` byte of `s` to `c` | [x] |
-| ft_memset_pattern4 | `void ft_memset_pattern4(void *b, const void *pattern4, size_t len)` | set `len` byte of `b` to a reapeated pattern of 4 bytes | [ ] |
+| ft_memset_pattern4 | `void ft_memset_pattern4(void *b, const void *pattern4, size_t len)` | set `len` byte of `b` to a reapeated pattern of 4 bytes | [x] |
| ft_memswap | `void ft_memswap(void *a, void *b, size_t size)` | swap `a` and `b` memory | [x] |
### algo
-| Name | prototype | description | tested |
-|------|-----------|-------------|--------|
-| ft_bsearch | | | |
-| ft_compar_int | | | |
-| ft_heapsort | | | |
-| ft_is_set | | | |
-| ft_lfind | | | |
-| ft_lsearch | | | |
-| ft_mergesort | | | |
-| ft_qsort | | | |
-| ft_reverse | | | |
+| Name | Prototype | Description | Tested |
+|---------------|-----------|-------------|--------|
+| ft_bsearch | | | [ ] |
+| ft_compar_int | | | [ ] |
+| ft_heapsort | | | [ ] |
+| ft_is_set | | | [ ] |
+| ft_lfind | | | [ ] |
+| ft_lsearch | | | [ ] |
+| ft_mergesort | | | [ ] |
+| ft_qsort | | | [ ] |
+| ft_reverse | | | [ ] |
### bt
-| Name | prototype | description | tested |
-|------|-----------|-------------|--------|
+| Name | Prototype | Description | Tested |
+|--------------|-----------|-------------|--------|
| ft_btdestroy | | | |
-| ft_btnew | | | |
+| ft_btnew | | | |
### ctype
-| Name | Prototype | Description | tested |
+| Name | Prototype | Description | Tested |
|------------|-------------------------|----------------------------------------------------|--------|
| ft_isalnum | `int ft_isalnum(int c)` | c is alphanumeric | [x] |
| ft_isalpha | `int ft_isalpha(int c)` | c is alphabetic | [x] |
@@ -86,68 +82,68 @@ Much like the `.gitignore` file, you can put the files/directory to ignore when
### ht
-| Name | prototype | description | tested |
-|------|-----------|-------------|--------|
+| Name | Prototype | Description | Tested |
+|------------------|-----------|-------------|--------|
| ft_htcontent_new | | | |
-| ft_htdelone | | | |
-| ft_htdelone_key | | | |
-| ft_htdestroy | | | |
+| ft_htdelone | | | |
+| ft_htdelone_key | | | |
+| ft_htdestroy | | | |
| ft_htdestroy_all | | | |
| ft_htdestroy_key | | | |
-| ft_htget | | | |
-| ft_hthash | | | |
-| ft_htnew | | | |
-| ft_htset | | | |
+| ft_htget | | | |
+| ft_hthash | | | |
+| ft_htnew | | | |
+| ft_htset | | | |
### io
-| Name | prototype | description | tested |
-|------|-----------|-------------|--------|
-| ft_getchar | | | |
-| ft_next_line | | | |
-| ft_asprintf | | | |
-| ft_dprintf | | | |
-| ft_printf | | | |
-| ft_snprintf | | | |
-| ft_sprintf | | | |
-| ft_vasprintf | | | |
-| ft_vdprintf | | | |
-| ft_vprintf | | | |
-| ft_vsnprintf | | | |
-| ft_vsprintf | | | |
-| ft_putchar | | | | |
-| ft_putchar_fd | | | | |
-| ft_putendl | | | | |
-| ft_putendl_fd | | | | |
-| ft_putnbr | | | | |
-| ft_putnbr_fd | | | | |
-| ft_putstr | | | | |
-| ft_putstr_fd | | | | |
+| Name | Prototype | Description | Tested |
+|---------------|-----------|-------------|--------|
+| ft_getchar | | | |
+| ft_next_line | | | |
+| ft_asprintf | | | |
+| ft_dprintf | | | |
+| ft_printf | | | |
+| ft_snprintf | | | |
+| ft_sprintf | | | |
+| ft_vasprintf | | | |
+| ft_vdprintf | | | |
+| ft_vprintf | | | |
+| ft_vsnprintf | | | |
+| ft_vsprintf | | | |
+| ft_putchar | | | |
+| ft_putchar_fd | | | |
+| ft_putendl | | | |
+| ft_putendl_fd | | | |
+| ft_putnbr | | | |
+| ft_putnbr_fd | | | |
+| ft_putstr | | | |
+| ft_putstr_fd | | | |
### lst
-| Name | prototype | description | tested |
+| Name | Prototype | Description | Tested |
|------|-----------|-------------|--------|
-| ft_lstadd_back | | | | |
-| ft_lstadd_front | | | | |
-| ft_lstbsearch | | | | |
-| ft_lstclear | | | | |
-| ft_lstdelone | | | | |
-| ft_lstiter | | | | |
-| ft_lstlast | | | | |
-| ft_lstmap | | | | |
-| ft_lstnew | | | | |
-| ft_lstpop_front | | | | |
-| ft_lstremove_if | | | | |
-| ft_lstreverse | | | | |
-| ft_lstreverse_ret | | | | |
-| ft_lstsize | | | | |
-| ft_lstsort | | | | |
-| ft_lstsorted_merge | | | | |
+| ft_lstadd_back | | | |
+| ft_lstadd_front | | | |
+| ft_lstbsearch | | | |
+| ft_lstclear | | | |
+| ft_lstdelone | | | |
+| ft_lstiter | | | |
+| ft_lstlast | | | |
+| ft_lstmap | | | |
+| ft_lstnew | | | |
+| ft_lstpop_front | | | |
+| ft_lstremove_if | | | |
+| ft_lstreverse | | | |
+| ft_lstreverse_ret | | | |
+| ft_lstsize | | | |
+| ft_lstsort | | | |
+| ft_lstsorted_merge | | | |
### str
-| Name | prototype | description | tested |
+| Name | Prototype | Description | Tested |
|------|-----------|-------------|--------|
| ft_atoi | | | | |
| ft_atoi_strict | | | | |
diff --git a/src/mem/ft_memmem.c b/src/mem/ft_memmem.c
index b69efa0..fa1446c 100644
--- a/src/mem/ft_memmem.c
+++ b/src/mem/ft_memmem.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 01:54:55 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:13:23 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 21:04:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,41 +14,45 @@
#define BAD_TABLE_SIZE 256
-static void st_bad_table_init(size_t bad_table[BAD_TABLE_SIZE],
+static void st_bad_table_init(size_t bad_table[BAD_TABLE_SIZE],
const char *little, size_t little_len)
{
size_t i;
- ft_memset_pattern4(bad_table, &little_len, 4 * BAD_TABLE_SIZE);
i = 0;
- while (i < little_len)
+ while (i < BAD_TABLE_SIZE)
+ bad_table[i++] = little_len;
+ i = 0;
+ while (i < little_len - 1)
{
bad_table[(int)little[i]] = little_len - i - 1;
i++;
}
}
-static t_ftbool st_memcmp_end(const void *s1, const void *s2, size_t n)
+static int st_memcmp_end(const void *s1, const void *s2, size_t n)
{
while (n-- > 0)
- if (((t_ftbyte*)s1)[n] != ((t_ftbyte*)s2)[n])
- return (FALSE);
- return (TRUE);
+ if (*(t_ftbyte*)(s1 + n) != *(t_ftbyte*)(s2 + n))
+ return (*(t_ftbyte*)(s1 + n) - *(t_ftbyte*)(s2 + n));
+ return (0);
}
-void *ft_memmem(const void *big, size_t big_len,
+void *ft_memmem(const void *big, size_t big_len,
const void *little, size_t little_len)
{
size_t i;
size_t bad_table[BAD_TABLE_SIZE];
+ if (big_len < little_len || little_len == 0 || big_len == 0)
+ return (NULL);
st_bad_table_init(bad_table, little, little_len);
i = 0;
- while (i < big_len - little_len)
+ while (i <= big_len - little_len)
{
- if (st_memcmp_end((t_ftbyte*)big + i, little, little_len))
- return ((t_ftbyte*)big + i);
- i += bad_table[(int)(((t_ftbyte*)big)[i + big_len] - 1)];
+ if (st_memcmp_end(big + i, little, little_len) == 0)
+ return ((void*)big + i);
+ i += bad_table[*(t_ftbyte*)(big + i + little_len - 1)];
}
return (NULL);
}
diff --git a/src/mem/ft_memset_pattern4.c b/src/mem/ft_memset_pattern4.c
index d16f420..112ce6d 100644
--- a/src/mem/ft_memset_pattern4.c
+++ b/src/mem/ft_memset_pattern4.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:06:41 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:10:42 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 19:58:10 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,6 +20,7 @@ void ft_memset_pattern4(void *b, const void *pattern4, size_t len)
while (i-- > 0)
((int*)b)[i] = *(int*)pattern4;
i = len % 4;
+ len -= len % 4;
while (i-- > 0)
- ((int*)b)[len / 4 + i] = ((t_ftbyte*)pattern4)[i];
+ ((t_ftbyte*)b)[len + i] = ((t_ftbyte*)pattern4)[i];
}
diff --git a/test/include/libft_test.h b/test/include/libft_test.h
index ff99eec..f710c7d 100644
--- a/test/include/libft_test.h
+++ b/test/include/libft_test.h
@@ -4,6 +4,9 @@
# include <string.h>
# include <ctype.h>
# include <sys/wait.h>
+# ifdef __APPLE__
+# include <malloc/malloc.h>
+# endif
# include "unity.h"
# include "unity_fixture.h"
diff --git a/test/src/mem/test_ft_calloc.c b/test/src/mem/test_ft_calloc.c
index 1497728..9944f41 100644
--- a/test/src/mem/test_ft_calloc.c
+++ b/test/src/mem/test_ft_calloc.c
@@ -10,5 +10,22 @@ TEST_TEAR_DOWN(ft_calloc)
TEST(ft_calloc, basic)
{
+ char *ptr = NULL;
+ ptr = ft_calloc(45, sizeof(char));
+ TEST_ASSERT_NOT_NULL(ptr);
+#ifdef __APPLE__
+ TEST_ASSERT_GREATER_THAN(45 * sizeof(char) - 1, malloc_size(ptr));
+#endif
+ for (int i = 0; i < 45; i++)
+ TEST_ASSERT_EQUAL(0x0, ptr[i]);
+
+ int *ptrint = NULL;
+ ptrint = ft_calloc(10, sizeof(int));
+ TEST_ASSERT_NOT_NULL(ptr);
+#ifdef __APPLE__
+ TEST_ASSERT_GREATER_THAN(10 * sizeof(int) - 1, malloc_size(ptrint));
+#endif
+ for (int i = 0; i < 10; i++)
+ TEST_ASSERT_EQUAL(0x0, ptrint[i]);
}
diff --git a/test/src/mem/test_ft_memccpy.c b/test/src/mem/test_ft_memccpy.c
index 6b7a1a5..39925a1 100644
--- a/test/src/mem/test_ft_memccpy.c
+++ b/test/src/mem/test_ft_memccpy.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:34:13 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:40:18 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 19:35:17 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,24 @@ TEST_TEAR_DOWN(ft_memccpy)
TEST(ft_memccpy, basic)
{
+ char buf[32] = "bonjour";
+ char buf2[32] = {0};
+ char *ptr = ft_memccpy(buf2, buf, 0x0, 32);
+ TEST_ASSERT_EQUAL_PTR(&buf2[8], ptr);
+ for (int i = 0; i < 32; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf2[i]);
+
+ ptr = ft_memccpy(buf2, buf, 0x1, 32);
+ TEST_ASSERT_NULL(ptr);
+ for (int i = 0; i < 32; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf2[i]);
+
+ char buf3[10] = "aurevoir";
+ ptr = ft_memccpy(buf, buf3, 'e', 10);
+ TEST_ASSERT_EQUAL_PTR(buf + 4, ptr);
+ for (int i = 0; i < 4; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf3[i]);
+ for (int i = 4; i < 32; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf2[i]);
}
diff --git a/test/src/mem/test_ft_memchr.c b/test/src/mem/test_ft_memchr.c
index c0b2ae6..135edfb 100644
--- a/test/src/mem/test_ft_memchr.c
+++ b/test/src/mem/test_ft_memchr.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:33:14 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:40:28 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 19:38:17 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,14 @@ TEST_TEAR_DOWN(ft_memchr)
TEST(ft_memchr, basic)
{
+ char *a = "bonjour";
+ char *ptr = ft_memchr(a, 'j', sizeof(a));
+ TEST_ASSERT_EQUAL_PTR(a + 3, ptr);
+
+ ptr = ft_memchr(a, 'z', sizeof(a));
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memchr(a, '\0', sizeof(a));
+ TEST_ASSERT_EQUAL_PTR(a + 7, ptr);
}
diff --git a/test/src/mem/test_ft_memcmp.c b/test/src/mem/test_ft_memcmp.c
index 363b06a..81871a1 100644
--- a/test/src/mem/test_ft_memcmp.c
+++ b/test/src/mem/test_ft_memcmp.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:32:16 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:40:36 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 19:41:08 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,21 @@ TEST_TEAR_DOWN(ft_memcmp)
TEST(ft_memcmp, basic)
{
+ char buf1[32] = "bonjour";
+ char buf2[32] = "bonjoure";
+ int res = ft_memcmp(buf1, buf2, 32);
+ TEST_ASSERT_LESS_THAN(0, res);
+
+ res = ft_memcmp(buf2, buf1, 32);
+ TEST_ASSERT_GREATER_THAN(0, res);
+
+ res = ft_memcmp(buf2, buf1, 7);
+ TEST_ASSERT_EQUAL(0, res);
+ res = ft_memcmp(buf2, buf1, 6);
+ TEST_ASSERT_EQUAL(0, res);
+ res = ft_memcmp(buf2, buf1, 3);
+ TEST_ASSERT_EQUAL(0, res);
+ res = ft_memcmp(buf2, buf1, 0);
+ TEST_ASSERT_EQUAL(0, res);
}
diff --git a/test/src/mem/test_ft_memmem.c b/test/src/mem/test_ft_memmem.c
index 6492657..67514a5 100644
--- a/test/src/mem/test_ft_memmem.c
+++ b/test/src/mem/test_ft_memmem.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:33:50 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:41:09 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 21:04:22 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,44 @@ TEST_TEAR_DOWN(ft_memmem)
TEST(ft_memmem, basic)
{
+ char haystack[32] = "bonjour";
+ char *ptr;
+ ptr = ft_memmem(haystack, sizeof(haystack), "jour\0", 5);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "jour", 4);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "jo", 2);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "j", 1);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "yo", 2);
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "\0", 1);
+ TEST_ASSERT_EQUAL_PTR(haystack + 7, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "bon", 3);
+ TEST_ASSERT_EQUAL_PTR(haystack, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "on", 2);
+ TEST_ASSERT_EQUAL_PTR(haystack + 1, ptr);
+}
+
+TEST(ft_memmem, invalid_len)
+{
+ char buf[32] = {0};
+
+ void *ptr = ft_memmem(buf, 2, "jour", 4);
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memmem(buf, 0, "jour", 4);
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memmem(buf, 2, "jour", 0);
+ TEST_ASSERT_NULL(ptr);
}
diff --git a/test/src/mem/test_ft_memmove.c b/test/src/mem/test_ft_memmove.c
index adbb3b0..158cda9 100644
--- a/test/src/mem/test_ft_memmove.c
+++ b/test/src/mem/test_ft_memmove.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:34:21 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:41:18 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 19:49:07 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,18 @@ TEST_TEAR_DOWN(ft_memmove)
TEST(ft_memmove, basic)
{
+ char buf1[32] = "bonjour";
+ char *ptr = ft_memmove(buf1, buf1 + 2, 29);
+ TEST_ASSERT_EQUAL_PTR(buf1, ptr);
+ TEST_ASSERT_EQUAL_STRING("njour", buf1);
+
+ ptr = ft_memmove(buf1 + 2, buf1, 29);
+ TEST_ASSERT_EQUAL_PTR(buf1 + 2, ptr);
+ TEST_ASSERT_EQUAL_STRING("njour", ptr);
+ TEST_ASSERT_EQUAL_STRING("njnjour", buf1);
+
+ ptr = ft_memmove(buf1, buf1, 32);
+ TEST_ASSERT_EQUAL_PTR(buf1, ptr);
+ TEST_ASSERT_EQUAL_STRING("njnjour", ptr);
}
diff --git a/test/src/mem/test_ft_memset_pattern4.c b/test/src/mem/test_ft_memset_pattern4.c
index 9a0f109..0e2806a 100644
--- a/test/src/mem/test_ft_memset_pattern4.c
+++ b/test/src/mem/test_ft_memset_pattern4.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:32:43 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:41:36 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 19:57:48 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,21 @@ TEST_TEAR_DOWN(ft_memset_pattern4)
TEST(ft_memset_pattern4, basic)
{
+ char buf[17] = {0};
+ char *pattern4 = "1234";
+ ft_memset_pattern4(buf, pattern4, 16);
+ TEST_ASSERT_EQUAL_STRING("1234123412341234", buf);
+
+ char buf1[10] = {0};
+ ft_memset_pattern4(buf1, "1234", 9);
+ TEST_ASSERT_EQUAL_STRING("123412341", buf1);
+
+ char buf2[11] = {0};
+ ft_memset_pattern4(buf2, "1234", 10);
+ TEST_ASSERT_EQUAL_STRING("1234123412", buf2);
+
+ char buf3[12] = {0};
+ ft_memset_pattern4(buf3, "1234", 11);
+ TEST_ASSERT_EQUAL_STRING("12341234123", buf3);
}
diff --git a/test/src/runner/test_runner_mem.c b/test/src/runner/test_runner_mem.c
index 155008b..093d064 100644
--- a/test/src/runner/test_runner_mem.c
+++ b/test/src/runner/test_runner_mem.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/13 03:36:16 by cacharle #+# #+# */
-/* Updated: 2020/02/13 03:39:11 by cacharle ### ########.fr */
+/* Updated: 2020/02/13 20:40:24 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -45,6 +45,7 @@ TEST_GROUP_RUNNER(ft_memcpy)
TEST_GROUP_RUNNER(ft_memmem)
{
RUN_TEST_CASE(ft_memmem, basic);
+ RUN_TEST_CASE(ft_memmem, invalid_len);
}
TEST_GROUP_RUNNER(ft_memmove)
diff --git a/test/test_runner_mem.c b/test/test_runner_mem.c
deleted file mode 100644
index 21f9f1e..0000000
--- a/test/test_runner_mem.c
+++ /dev/null
@@ -1,12 +0,0 @@
-test_ft_bzero.c
-test_ft_calloc.c
-test_ft_memalloc.c
-test_ft_memccpy.c
-test_ft_memchr.c
-test_ft_memcmp.c
-test_ft_memcpy.c
-test_ft_memmem.c
-test_ft_memmove.c
-test_ft_memset.c
-test_ft_memset_pattern4.c
-test_ft_memswap.c