aboutsummaryrefslogtreecommitdiff
path: root/test/src/lst/test_ft_lstbsearch.c
blob: 81f2578dc2f9c4fa9f0a3896e7874fdf3607207c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "libft_test.h"

TEST_GROUP(ft_lstbsearch);

TEST_SETUP(ft_lstbsearch)
{}

TEST_TEAR_DOWN(ft_lstbsearch)
{}

TEST(ft_lstbsearch, basic)
{
	t_ftlst *found = NULL;
	t_ftlst *lst = NULL;
	int a = 1;
	int b = 2;
	int c = 3;
	int d = 4;

	ft_lstpush_front(&lst, ft_lstnew(&c));
	ft_lstpush_front(&lst, ft_lstnew(&b));
	ft_lstpush_front(&lst, ft_lstnew(&a));
	ft_lstpush_front(&lst, ft_lstnew(&a));

	found = ft_lstbsearch(lst, ft_compar_int, &c);
	TEST_ASSERT_NOT_NULL(found);
	found = ft_lstbsearch(lst, ft_compar_int, &c);
	TEST_ASSERT_NOT_NULL(found);
	found = ft_lstbsearch(lst, ft_compar_int, &b);
	TEST_ASSERT_NOT_NULL(found);
	found = ft_lstbsearch(lst, ft_compar_int, &a);
	TEST_ASSERT_NOT_NULL(found);
	found = ft_lstbsearch(lst, ft_compar_int, &d);
	TEST_ASSERT_NULL(found);

	ft_lstdestroy(&lst, NULL);
}