Skip to content

Commit

Permalink
Begin conversion to Unity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jun 23, 2024
1 parent 9a7862f commit 97b0bee
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "c/Unity"]
path = c/Unity
url = https://github.com/ThrowTheSwitch/Unity
1 change: 1 addition & 0 deletions c/Unity
Submodule Unity added at 18fb33
7 changes: 6 additions & 1 deletion c/p0000_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ This paragraph should be replaced by the problem description, excluding images.
*/
#include <stdio.h>

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
7 changes: 5 additions & 2 deletions c/p0001.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Find the sum of all the multiples of 3 or 5 below 1000.
#include <stdio.h>
#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);
Expand All @@ -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;
}
66 changes: 66 additions & 0 deletions c/test.c
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 97b0bee

Please sign in to comment.