Commit c042952

mo khan <mo.khan@gmail.com>
2020-08-02 02:27:28
Start to build a hash table
1 parent f1e4b32
src/02/04/hash.c
@@ -0,0 +1,7 @@
+#include "hash.h"
+#include <stdio.h>
+
+Hash *hash_init(int size)
+{
+  return NULL;
+}
src/02/04/hash.h
@@ -0,0 +1,4 @@
+typedef struct {
+} Hash;
+
+Hash *hash_init(int size);
src/02/04/hash_test.c
@@ -0,0 +1,26 @@
+#include "hash.h"
+#include <cgreen/cgreen.h>
+#include <string.h>
+
+Describe(HashTable);
+BeforeEach(HashTable) {}
+AfterEach(HashTable) {}
+
+Ensure(HashTable, when_initializing_a_hash) {
+  Hash *hash = hash_init(13);
+
+  assert_that(hash, is_not_equal_to(NULL));
+}
+
+TestSuite *hash_table_tests() {
+  TestSuite *suite = create_test_suite();
+
+  add_test_with_context(suite, HashTable, when_initializing_a_hash);
+  return suite;
+}
+
+int main(int argc, char **argv) {
+  TestSuite *suite = create_test_suite();
+  add_suite(suite, hash_table_tests());
+  return run_test_suite(suite, create_text_reporter());
+}
src/02/04/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+  return 0;
+}
src/02/04/Makefile
@@ -0,0 +1,38 @@
+#!/usr/bin/make -f
+SHELL=/bin/sh
+
+CC=clang
+CFLAGS=-std=c99
+TEST_LIBS = -lcgreen
+
+BUILDDIR := build
+OBJS := $(addprefix $(BUILDDIR)/,hash.o)
+TEST_OBJS := $(addprefix $(BUILDDIR)/,hash_test.o)
+
+$(BUILDDIR)/%.o : %.c
+	$(COMPILE.c) $(OUTPUT_OPTION) $<
+
+.PHONY: all
+all: $(OBJS) $(BUILDDIR)/main.o
+	$(CC) $(OBJS) $(BUILDDIR)/main.o -o $(BUILDDIR)/program
+
+.PHONY: test
+test: $(OBJS) $(TEST_OBJS)
+	$(CC) $(OBJS) $(TEST_OBJS) $(TEST_LIBS) -o $(BUILDDIR)/test
+
+$(OBJS): | $(BUILDDIR)
+
+$(TEST_OBJS): | $(BUILDDIR)
+
+$(BUILDDIR):
+	mkdir $(BUILDDIR)
+
+.PHONY: clean
+clean:
+	rm -fr build
+
+run : all
+	./build/program
+
+run_test : test
+	cgreen-runner -c -v $(BUILDDIR)/test