-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kay Freyer
committed
Nov 12, 2024
1 parent
e731f0e
commit 4d73f58
Showing
9 changed files
with
179 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env zsh | ||
|
||
GTEST_COLOR=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,40 @@ | ||
// #include "test_libft.hpp" | ||
|
||
// t_list *create_list_2(int length) { | ||
// if (length <= 0) { | ||
// return NULL; | ||
// } | ||
// t_list *lst = new t_list{.content = (void*)1, .next = nullptr}; | ||
// t_list *head = lst; | ||
// while (length > 1) { | ||
// head->next = new t_list{.content = (void*)1, .next = nullptr}; | ||
// head = head->next; | ||
// length--; | ||
// } | ||
|
||
// const char* last = "last"; | ||
// head->content = (void*)last; | ||
// return lst; | ||
// } | ||
|
||
// void clear_list_2(t_list *lst) { | ||
// while (lst) { | ||
// t_list *tmp = lst; | ||
// lst = lst->next; | ||
// delete tmp; | ||
// } | ||
// } | ||
|
||
// struct FtLstaddBackParams { | ||
// t_list* lst; | ||
// t_list* new_node; | ||
// }; | ||
|
||
|
||
// class FtLstaddBackTest : public testing::TestWithParam<FtLstaddBackParams> {}; | ||
|
||
|
||
// TEST_P(FtLstaddBackTest, HandleVariousInputs) { | ||
// FtLstaddBackParams params = GetParam(); | ||
// t_list *lst = params.lst; | ||
// t_list *new_node = params.new_node; | ||
// ft_lstadd_back(&lst, new_node); | ||
|
||
// t_list *head = lst; | ||
// while (head->next) { | ||
// head = head->next; | ||
// } | ||
// EXPECT_STREQ((char*)(head->content), "new"); | ||
// clear_list_2(lst); | ||
// } | ||
|
||
// INSTANTIATE_TEST_SUITE_P( | ||
// FtLstaddBackTests, | ||
// FtLstaddBackTest, | ||
// ::testing::Values( | ||
// // FtLstlastParams{create_list_last_element_eq_length(0)}, | ||
// // FtLstlastParams{create_list_last_element_eq_length(1)}, | ||
// // FtLstlastParams{create_list_last_element_eq_length(5)}, | ||
// FtLstaddBackParams{create_list_2(0), new t_list{.content = (void *)"new", .next=nullptr}}, | ||
// FtLstaddBackParams{create_list_2(1), new t_list{.content = (void *)"new", .next=nullptr}}, | ||
// FtLstaddBackParams{create_list_2(3), new t_list{.content = (void *)"new", .next=nullptr}} | ||
// ) | ||
// ); | ||
#include "test_libft.hpp" | ||
|
||
struct FtLstaddBackParams { | ||
std::vector<int> lst_entries; | ||
}; | ||
|
||
class FtLstaddBackTest : public testing::TestWithParam<FtLstaddBackParams> {}; | ||
|
||
TEST_P(FtLstaddBackTest, HandleVariousInputs) { | ||
FtLstaddBackParams params = GetParam(); | ||
|
||
std::vector<int> lst_entries = params.lst_entries; | ||
t_list* lst = NULL; | ||
for (int i = 0; i < lst_entries.size() ; i++ ) { | ||
ft_lstadd_back(&lst, ft_lstnew(&lst_entries[i])); | ||
} | ||
|
||
t_list* head = lst; | ||
int i = 0; | ||
while (head) { | ||
EXPECT_EQ(lst_entries[i++], *(int*)(head->content)); | ||
head = head->next; | ||
} | ||
|
||
head = lst; | ||
while (head) { | ||
lst = head; | ||
head = head->next; | ||
free(lst); | ||
} | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
FtLstaddBackTests, | ||
FtLstaddBackTest, | ||
::testing::Values( | ||
FtLstaddBackParams{{1, 2, 3}}, | ||
FtLstaddBackParams{{}} | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
// #include "test_libft.hpp" | ||
#include "test_libft.hpp" | ||
#include <gtest/gtest.h> | ||
|
||
// struct FtLstaddFrontParams { | ||
// t_list **lst; | ||
// t_list *new_node; | ||
// }; | ||
struct FtLstaddFrontParams { | ||
std::vector<int> lst_entries; | ||
std::vector<int> new_entries; | ||
}; | ||
|
||
// class FtLstaddFrontTest : public testing::TestWithParam<std::tuple<t_list*, t_list*>> {}; | ||
class FtLstaddFrontTest : public testing::TestWithParam<FtLstaddFrontParams> {}; | ||
|
||
// INSTANTIATE_TEST_SUITE_P( | ||
// FtLstaddFrontTests, FtLstaddFrontTest, | ||
// ::testing::Values( | ||
// std::make_tuple(new t_list{.content = (void *)1, .next = nullptr}, | ||
// new t_list{.content = (void *)2, .next = nullptr}), | ||
// std::make_tuple(new t_list{.content=(void*)3, .next=nullptr}, | ||
// new t_list{.content=(void*)4, .next=nullptr}) | ||
// ) | ||
// ); | ||
INSTANTIATE_TEST_SUITE_P( | ||
FtLstaddFrontTests, FtLstaddFrontTest, | ||
::testing::Values( | ||
FtLstaddFrontParams{{1, 2, 3}, {4}}, | ||
FtLstaddFrontParams{{1, 2, 3}, {4, 5}}, | ||
FtLstaddFrontParams{{}, {4, 5}} | ||
) | ||
); | ||
|
||
// TEST_P(FtLstaddFrontTest, FtTestLstaddFront) { | ||
// t_list* lst = std::get<0>(GetParam()); | ||
// t_list* newElem = std::get<1>(GetParam()); | ||
// t_list* old_lst = lst; | ||
|
||
// ft_lstadd_front(&lst, newElem); | ||
TEST_P(FtLstaddFrontTest, FtTestLstaddFront) { | ||
FtLstaddFrontParams params = GetParam(); | ||
|
||
// EXPECT_EQ(lst, newElem); | ||
// EXPECT_EQ(newElem->next, old_lst); | ||
std::vector<int> lst_entries = params.lst_entries; | ||
t_list* lst = NULL; | ||
for (int i = 0; i < lst_entries.size() ; i++ ) { | ||
ft_lstadd_back(&lst, ft_lstnew(&lst_entries[i])); | ||
} | ||
|
||
// // ft_lstclear(&lst, free); | ||
// } | ||
std::vector<int> new_entries = params.new_entries; | ||
for (int i = 0; i < new_entries.size() ; i++ ) { | ||
ft_lstadd_front(&lst, ft_lstnew(&new_entries[i])); | ||
EXPECT_EQ(new_entries[i], *(int*)lst->content); | ||
} | ||
|
||
t_list* head = lst; | ||
while (head) { | ||
lst = head; | ||
head = head->next; | ||
free(lst); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,40 @@ | ||
// #include "test_libft.hpp" | ||
|
||
|
||
// t_list *create_list_last_element_eq_length(int length) { | ||
// if (length <= 0) { | ||
// return NULL; | ||
// } | ||
// t_list *lst = new t_list{.content = (void*)1, .next = nullptr}; | ||
// t_list *head = lst; | ||
// while (length > 1) { | ||
// head->next = new t_list{.content = (void*)1, .next = nullptr}; | ||
// head = head->next; | ||
// length--; | ||
// } | ||
|
||
// const char* last = "last"; | ||
// head->content = (void*)last; | ||
// return lst; | ||
// } | ||
|
||
// void clear_list_3(t_list *lst) { | ||
// while (lst) { | ||
// t_list *tmp = lst; | ||
// lst = lst->next; | ||
// delete tmp; | ||
// } | ||
// } | ||
|
||
// struct FtLstlastParams { | ||
// t_list* lst; | ||
// }; | ||
|
||
|
||
// class FtLstlastTest : public testing::TestWithParam<FtLstlastParams> { | ||
// public: | ||
// ~FtLstlastTest() { | ||
// FtLstlastParams params = GetParam(); | ||
// clear_list_3(params.lst); | ||
// } | ||
// }; | ||
|
||
|
||
// TEST_P(FtLstlastTest, HandleVariousInputs) { | ||
// FtLstlastParams params = GetParam(); | ||
// t_list *lst = params.lst; | ||
// t_list *got = ft_lstlast(lst); | ||
// if (lst) { | ||
// EXPECT_STREQ((char*)(got->content), "last"); | ||
// } else { | ||
// EXPECT_EQ(got, nullptr); | ||
// } | ||
// } | ||
|
||
// INSTANTIATE_TEST_SUITE_P( | ||
// FtLstlastTests, | ||
// FtLstlastTest, | ||
// ::testing::Values( | ||
// FtLstlastParams{create_list_last_element_eq_length(0)}, | ||
// FtLstlastParams{create_list_last_element_eq_length(1)}, | ||
// FtLstlastParams{create_list_last_element_eq_length(5)}, | ||
// FtLstlastParams{create_list_last_element_eq_length(3)} | ||
// ) | ||
// ); | ||
#include "test_libft.hpp" | ||
|
||
struct FtLstlastParams { | ||
std::vector<int> lst_entries; | ||
}; | ||
|
||
|
||
class FtLstlastTest : public testing::TestWithParam<FtLstlastParams> {}; | ||
|
||
TEST_P(FtLstlastTest, HandleVariousInputs) { | ||
FtLstlastParams params = GetParam(); | ||
|
||
std::vector<int> lst_entries = params.lst_entries; | ||
t_list* lst = NULL; | ||
for (int i = 0; i < lst_entries.size() ; i++ ) { | ||
ft_lstadd_back(&lst, ft_lstnew(&lst_entries[i])); | ||
} | ||
|
||
if (lst_entries.size()) { | ||
EXPECT_EQ(lst_entries[lst_entries.size() - 1], *(int*)ft_lstlast(lst)->content); | ||
} else { | ||
EXPECT_EQ(nullptr, ft_lstlast(lst)); | ||
} | ||
|
||
t_list* head = lst; | ||
while (head) { | ||
lst = head; | ||
head = head->next; | ||
free(lst); | ||
} | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
FtLstlastTests, | ||
FtLstlastTest, | ||
::testing::Values( | ||
FtLstlastParams{{1, 2, 3}}, | ||
FtLstlastParams{{}} | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
// #include "test_libft.hpp" | ||
#include "test_libft.hpp" | ||
|
||
// struct FtLstnewParams { | ||
// void* content; | ||
// }; | ||
struct FtLstnewParams { | ||
void* content; | ||
}; | ||
|
||
// class FtLstnewTest : public ::testing::TestWithParam<FtLstnewParams> {}; | ||
class FtLstnewTest : public ::testing::TestWithParam<FtLstnewParams> {}; | ||
|
||
// TEST_P(FtLstnewTest, HandlesVariousContents) { | ||
// FtLstnewParams params = GetParam(); | ||
TEST_P(FtLstnewTest, HandlesVariousContents) { | ||
FtLstnewParams params = GetParam(); | ||
|
||
// t_list *n = ft_lstnew(params.content); | ||
// EXPECT_EQ(n->next, (void*)0); | ||
// EXPECT_EQ(n->content, params.content); | ||
// free(n); | ||
// } | ||
t_list *n = ft_lstnew(params.content); | ||
EXPECT_EQ(n->next, (void*)0); | ||
EXPECT_EQ(n->content, params.content); | ||
free(n); | ||
} | ||
|
||
// INSTANTIATE_TEST_SUITE_P(FtLstnewTests, FtLstnewTest, | ||
// ::testing::Values( | ||
// FtLstnewParams{(void*)0}, | ||
// FtLstnewParams{(void*)"Hello"} | ||
// ) | ||
// ); | ||
INSTANTIATE_TEST_SUITE_P(FtLstnewTests, FtLstnewTest, | ||
::testing::Values( | ||
FtLstnewParams{(void*)0}, | ||
FtLstnewParams{(void*)"Hello"} | ||
) | ||
); |
Oops, something went wrong.