fp(check_list_val(lp));
}
+
+bool check_list_contains(List * lp, void *val)
+{
+ for(check_list_front(lp); !check_list_at_end(lp); check_list_advance(lp))
+ {
+ if(check_list_val(lp) == val)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
#ifndef CHECK_LIST_H
#define CHECK_LIST_H
+#include <stdbool.h>
+
typedef struct List List;
/* Create an empty list */
void check_list_apply(List * lp, void (*fp) (void *));
+/* Return true if the list contains the value, false otherwise */
+bool check_list_contains(List * lp, void *val);
+
#endif /* CHECK_LIST_H */
}
END_TEST
+START_TEST(test_contains)
+{
+ List *lp = check_list_create();
+
+ char otherData[] = "other";
+ char goalData[] = "goal";
+
+ ck_assert_msg (check_list_contains(lp, goalData) == false,
+ "The goal data should not be in the list yet");
+
+ int index;
+ for(index = 0; index < 10; index++)
+ {
+ check_list_add_end (lp, otherData);
+ ck_assert_msg (check_list_contains(lp, goalData) == false,
+ "The goal data should not be in the list yet");
+ }
+
+ check_list_add_end (lp, goalData);
+ ck_assert_msg (check_list_contains(lp, goalData) ,
+ "The goal data should be in the list");
+
+ check_list_free(lp);
+}
+END_TEST
Suite *make_list_suite (void)
{
tcase_add_test (tc, test_add_front_and_next);
tcase_add_test (tc, test_add_a_bunch);
tcase_add_test (tc, test_list_abuse);
+ tcase_add_test (tc, test_contains);
return s;
}