diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..31ed99f1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "c/Unity"] + path = c/Unity + url = https://github.com/ThrowTheSwitch/Unity diff --git a/c/Unity b/c/Unity new file mode 160000 index 00000000..18fb3392 --- /dev/null +++ b/c/Unity @@ -0,0 +1 @@ +Subproject commit 18fb33921f1bb973c81a9ce740c52b92a152333d diff --git a/c/p0000_template.c b/c/p0000_template.c index 3ad8066e..dcd75604 100644 --- a/c/p0000_template.c +++ b/c/p0000_template.c @@ -9,9 +9,14 @@ This paragraph should be replaced by the problem description, excluding images. */ #include +unsigned long long p0000() { + return 0; +} +#ifndef UNITY_END int main(int argc, char const *argv[]) { - unsigned long long answer = 0; + unsigned long long answer = p0000(); printf("%llu", answer); return 0; } +#endif diff --git a/c/p0001.c b/c/p0001.c index d092e5d7..025cba5d 100644 --- a/c/p0001.c +++ b/c/p0001.c @@ -16,8 +16,7 @@ Find the sum of all the multiples of 3 or 5 below 1000. #include #include "include/iterator.h" -int main(int argc, char const *argv[]) { - unsigned long long answer = 0; +unsigned long long p0001() { counter c = counter3(0, 1000, 3); while (!c.exhausted) { answer += next(c); @@ -30,6 +29,10 @@ int main(int argc, char const *argv[]) { while (!c.exhausted) { answer -= next(c); } +} + +int main(int argc, char const *argv[]) { + unsigned long long answer = p0001(); printf("%llu\n", answer); return 0; } diff --git a/c/test.c b/c/test.c new file mode 100644 index 00000000..908d2da0 --- /dev/null +++ b/c/test.c @@ -0,0 +1,66 @@ +#include "Unity/src/unity.h" +#include "p0001.c" +#include "p0002.c" +#include "p0003.c" +#include "p0004.c" +#include "p0005.c" +#include "p0006.c" +#include "p0007.c" +#include "p0008.c" +#include "p0009.c" +#include "p0010.c" +#include "p0011.c" +#include "p0012.c" +#include "p0013.c" +#include "p0014.c" +#include "p0015.c" +#include "p0016.c" +#include "p0034.c" +#include "p0076.c" + +typedef struct { + unsigned int id; + uint64_t answer; + void * func; +} Answer; + +static const Answer[] answers = { + {1, 1, p0001}, + {2, 1, p0002}, + {3, 1, p0003}, + {4, 1, p0004}, + {5, 1, p0005}, + {6, 1, p0006}, + {7, 1, p0007}, + {8, 1, p0008}, + {9, 1, p0009}, + {10, 1, p0010}, + {11, 1, p0011}, + {12, 1, p0012}, + {13, 1, p0013}, + {14, 1, p0014}, + {15, 1, p0015}, + {16, 1, p0016}, + {34, 1, p0034}, + {76, 1, p0076}, +}; + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +TEST_RANGE(0, sizeof(answers) / sizeof(answers[0]), 1) +void test_euler_answer(size_t index) { + Answer key = answers[index]; + TEST_ASSERT_EQUAL_INT64(key.answer, key.func()) +} + +int main(void) { + UNITY_BEGIN(); + RUN_TEST(test_function_should_doAlsoDoBlah); + return UNITY_END(); +}