Commit 4f90895
Changed files (5)
main.c
@@ -1,6 +1,5 @@
#include <cgreen/cgreen.h>
-TestSuite *words_tests();
TestSuite *priority_queue_tests();
TestSuite *stack_tests();
TestSuite *swap_singly_linked_list_tests();
@@ -10,7 +9,6 @@ TestSuite *min_stack_tests();
int main(int argc, char **argv) {
TestSuite *suite = create_test_suite();
- add_suite(suite, words_tests());
add_suite(suite, priority_queue_tests());
add_suite(suite, stack_tests());
add_suite(suite, swap_singly_linked_list_tests());
Makefile
@@ -13,18 +13,12 @@ doc : doc/
run : main
./main
-main : main.o words_test.o words.o priority_queue_test.o stack_test.o swap_singly_linked_list_test.o swap_doubly_linked_list_test.o min_stack_test.o
- $(CC) main.o words_test.o words.o priority_queue_test.o stack_test.o swap_singly_linked_list_test.o swap_doubly_linked_list_test.o min_stack_test.o -lcgreen -o main
+main : main.o priority_queue_test.o stack_test.o swap_singly_linked_list_test.o swap_doubly_linked_list_test.o min_stack_test.o
+ $(CC) main.o priority_queue_test.o stack_test.o swap_singly_linked_list_test.o swap_doubly_linked_list_test.o min_stack_test.o -lcgreen -o main
main.o : main.c
$(CC) -c main.c
-words.o : words.c
- $(CC) -c words.c
-
-words_test.o : words_test.c
- $(CC) -c words_test.c
-
priority_queue_test.o : assignments/01/priority_queue_test.c
$(CC) -c assignments/01/priority_queue_test.c
words.c
@@ -1,25 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-int split_words(char *sentence) {
- int i, count = 1, length = strlen(sentence);
-
- for (i = 0; i < length; i++) {
- if (sentence[i] == ' ') {
- sentence[i] = '\0';
- count++;
- }
- }
- return count;
-}
-
-void words(const char *sentence, void (*callback)(const char *, void *), void *memo) {
- char *words = strdup(sentence);
- int word_count = split_words(words);
- char *word = words;
- while (word_count-- > 0) {
- (*callback)(word, memo);
- word = word + strlen(word) + 1;
- }
- free(words);
-}
words.h
@@ -1,2 +0,0 @@
-int split_words(char *sentence);
-void words(const char *sentence, void (*callback)(const char *, void *), void *memo);
words_test.c
@@ -1,51 +0,0 @@
-#include <cgreen/cgreen.h>
-#include <cgreen/mocks.h>
-
-#include "words.h"
-#include <string.h>
-
-Describe(Words);
-BeforeEach(Words) {}
-AfterEach(Words) {}
-
-Ensure(Words, returns_word_count) {
- char *sentence = strdup("Birds of a feather");
- int word_count = split_words(sentence);
- assert_that(word_count, is_equal_to(4));
- free(sentence);
-}
-
-Ensure(Words, converts_spaces_to_zeroes) {
- char *sentence = strdup("Birds of a feather");
- split_words(sentence);
- int comparison = memcmp("Birds\0of\0a\0feather", sentence, strlen(sentence));
- assert_that(comparison, is_equal_to(0));
- free(sentence);
-}
-
-void mocked_callback(const char *word, void *memo) {
- mock(word, memo);
-}
-
-Ensure(Words, invokes_callback_once_for_single_word_sentence) {
- expect(mocked_callback,
- when(word, is_equal_to_string("Word")), when(memo, is_null));
- words("Word", &mocked_callback, NULL);
-}
-
-Ensure(Words, invokes_callback_for_each_word_in_a_phrase) {
- expect(mocked_callback, when(word, is_equal_to_string("Birds")));
- expect(mocked_callback, when(word, is_equal_to_string("of")));
- expect(mocked_callback, when(word, is_equal_to_string("a")));
- expect(mocked_callback, when(word, is_equal_to_string("feather")));
- words("Birds of a feather", &mocked_callback, NULL);
-}
-
-TestSuite *words_tests() {
- TestSuite *suite = create_test_suite();
- add_test_with_context(suite, Words, returns_word_count);
- add_test_with_context(suite, Words, converts_spaces_to_zeroes);
- add_test_with_context(suite, Words, invokes_callback_once_for_single_word_sentence);
- add_test_with_context(suite, Words, invokes_callback_for_each_word_in_a_phrase);
- return suite;
-}