commit 38a6ee0725ddc4eb57357a2398bc82dc8b264c7e Author: Tom Willemse Date: Mon Oct 12 20:46:11 2020 -0700 Initial commit diff --git a/1/HelloWorldC/.gitignore b/1/HelloWorldC/.gitignore new file mode 100644 index 0000000..28abb99 --- /dev/null +++ b/1/HelloWorldC/.gitignore @@ -0,0 +1,8 @@ +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +CTestTestfile.cmake +HelloWorld +Makefile +HelloWorldExecutable +Testing diff --git a/1/HelloWorldC/CMakeLists.txt b/1/HelloWorldC/CMakeLists.txt new file mode 100644 index 0000000..d235a0c --- /dev/null +++ b/1/HelloWorldC/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.18) + +enable_testing() + +project(HelloWorld C) + +add_executable(HelloWorld main.c) + +find_library(CMocka cmocka) + +target_link_libraries(HelloWorld cmocka) + +add_test( + NAME HelloWorldTest + COMMAND HelloWorld) + +add_test( + NAME HelloWorldMemoryTest + COMMAND valgrind --error-exitcode=1 --leak-check=full $) diff --git a/1/HelloWorldC/main.c b/1/HelloWorldC/main.c new file mode 100644 index 0000000..a2906d9 --- /dev/null +++ b/1/HelloWorldC/main.c @@ -0,0 +1,297 @@ +#include +#include +#include +#include +#include +#include + +struct double_linked_list { + struct double_linked_list *prev; + struct double_linked_list *next; + char *data; +}; + +struct double_linked_list * +make_double_linked_list(char *data) +{ + struct double_linked_list *list = + (struct double_linked_list *)malloc(sizeof(struct double_linked_list)); + + list->data = data; + list->prev = NULL; + list->next = NULL; + + return list; +} + +void +insert_double_linked_list_before(struct double_linked_list *list, char *data) +{ + struct double_linked_list *prev = make_double_linked_list(data); + + if (list->prev != NULL) { + prev->prev = list->prev; + } + + list->prev = prev; +} + +void +insert_double_linked_list_after(struct double_linked_list *list, char *data) +{ + struct double_linked_list *next = make_double_linked_list(data); + + if (list->next != NULL) { + next->next = list->next; + } + + list->next = next; +} + +void +free_double_linked_list(struct double_linked_list *list) +{ + if (list != NULL) { + if (list->data != NULL) { + free(list->data); + } + + struct double_linked_list *prev = list->prev; + while (prev != NULL) { + struct double_linked_list *inner = prev; + prev = prev->prev; + + free(inner->data); + free(inner); + } + + struct double_linked_list *next = list->next; + while (next != NULL) { + struct double_linked_list *inner = next; + next = next->next; + + free(inner->data); + free(inner); + } + + free(list); + } +} + +static void +test_double_linked_list_initialized_prev_null(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + + assert_null(list->prev); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_initialized_next_null(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + + assert_null(list->next); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_initialized_with_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + + assert_string_equal(list->data, "foo"); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_before_prev_not_null(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *beforeData = (char *)malloc(sizeof(char) * 4); + strcpy(data, "bar"); + + insert_double_linked_list_before(list, beforeData); + + assert_non_null(list->prev); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_before_prev_is_inserted_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *beforeData = (char *)malloc(sizeof(char) * 4); + strcpy(beforeData, "bar"); + + insert_double_linked_list_before(list, beforeData); + + assert_string_equal(list->prev->data, "bar"); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_multiple_prev_adds_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *beforeBeforeData = (char *)malloc(sizeof(char) * 4); + strcpy(beforeBeforeData, "bar"); + char *beforeData = (char *)malloc(sizeof(char) * 4); + strcpy(beforeData, "qux"); + + insert_double_linked_list_before(list, beforeBeforeData); + insert_double_linked_list_before(list, beforeData); + + assert_non_null(list->prev->prev); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_multiple_prev_adds_data_with_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *beforeBeforeData = (char *)malloc(sizeof(char) * 4); + strcpy(beforeBeforeData, "bar"); + char *beforeData = (char *)malloc(sizeof(char) * 4); + strcpy(beforeData, "qux"); + + insert_double_linked_list_before(list, beforeBeforeData); + insert_double_linked_list_before(list, beforeData); + + assert_string_equal(list->prev->prev->data, "bar"); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_after_next_not_null(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *afterData = (char *)malloc(sizeof(char) * 4); + strcpy(data, "bar"); + + insert_double_linked_list_after(list, afterData); + + assert_non_null(list->next); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_after_next_is_inserted_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *afterData = (char *)malloc(sizeof(char) * 4); + strcpy(afterData, "bar"); + + insert_double_linked_list_after(list, afterData); + + assert_string_equal(list->next->data, "bar"); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_multiple_next_adds_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *afterAfterData = (char *)malloc(sizeof(char) * 4); + strcpy(afterAfterData, "bar"); + char *afterData = (char *)malloc(sizeof(char) * 4); + strcpy(afterData, "qux"); + + insert_double_linked_list_after(list, afterAfterData); + insert_double_linked_list_after(list, afterData); + + assert_non_null(list->next->next); + + free_double_linked_list(list); +} + +static void +test_double_linked_list_insert_multiple_next_adds_data_with_data(void **state) +{ + (void)state; + + char *data = (char *)malloc(sizeof(char) * 4); + strcpy(data, "foo"); + struct double_linked_list *list = make_double_linked_list(data); + char *afterAfterData = (char *)malloc(sizeof(char) * 4); + strcpy(afterAfterData, "bar"); + char *afterData = (char *)malloc(sizeof(char) * 4); + strcpy(afterData, "qux"); + + insert_double_linked_list_after(list, afterAfterData); + insert_double_linked_list_after(list, afterData); + + assert_string_equal(list->next->next->data, "bar"); + + free_double_linked_list(list); +} + +int +main() +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_double_linked_list_initialized_prev_null), + cmocka_unit_test(test_double_linked_list_initialized_next_null), + cmocka_unit_test(test_double_linked_list_initialized_with_data), + cmocka_unit_test(test_double_linked_list_insert_before_prev_not_null), + cmocka_unit_test(test_double_linked_list_insert_before_prev_is_inserted_data), + cmocka_unit_test(test_double_linked_list_insert_multiple_prev_adds_data), + cmocka_unit_test(test_double_linked_list_insert_multiple_prev_adds_data_with_data), + cmocka_unit_test(test_double_linked_list_insert_after_next_not_null), + cmocka_unit_test(test_double_linked_list_insert_after_next_is_inserted_data), + cmocka_unit_test(test_double_linked_list_insert_multiple_next_adds_data), + cmocka_unit_test(test_double_linked_list_insert_multiple_next_adds_data_with_data), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/1/HelloWorldJava/.gitignore b/1/HelloWorldJava/.gitignore new file mode 100644 index 0000000..6d0e1d5 --- /dev/null +++ b/1/HelloWorldJava/.gitignore @@ -0,0 +1,8 @@ +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +CTestTestfile.cmake +*.jar +Makefile +HelloWorld +Testing diff --git a/1/HelloWorldJava/CMakeLists.txt b/1/HelloWorldJava/CMakeLists.txt new file mode 100644 index 0000000..d03d617 --- /dev/null +++ b/1/HelloWorldJava/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8) + +find_package(Java REQUIRED) +include(UseJava) + +enable_testing() + +project(HelloWorldJava NONE) + +add_jar(HelloWorldJava HelloWorld/HelloWorldJava.java) + +get_target_property(_jarFile HelloWorldJava JAR_FILE) +get_target_property(_classDir HelloWorldJava CLASSDIR) + +message(STATUS "Jar file ${_jarFile}") +message(STATUS "Class compiled to ${_classDir}") + +add_test( + NAME TestHelloWorldJava + COMMAND ${Java_JAVA_EXECUTABLE} -cp ${_jarFile} HelloWorld/HelloWorldJava) diff --git a/1/assignments.org b/1/assignments.org new file mode 100644 index 0000000..ae40227 --- /dev/null +++ b/1/assignments.org @@ -0,0 +1,3 @@ +- There are at least six domain-specific languages used in the little system I cobbled together to write and publish this book. What are they? + + They are at the very least: Make, HTML, CSS, Sass, Markdown, Mustache, XML, Yaml, Dart(?)