Skip to content

Commit

Permalink
concept exercise uses unity
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode committed Dec 31, 2024
1 parent dba3890 commit 546abd5
Show file tree
Hide file tree
Showing 5 changed files with 3,358 additions and 15 deletions.
7 changes: 5 additions & 2 deletions exercises/concept/basics/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ALL_ASFLAGS += $(ASFLAGS)

C_OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
AS_OBJS = $(patsubst %.asm,%.o,$(wildcard *.asm))
ALL_OBJS = $(filter-out exemplar.o,$(C_OBJS) $(AS_OBJS))
ALL_OBJS = $(filter-out exemplar.o,$(C_OBJS) $(AS_OBJS) vendor/unity.o)

CC_CMD = $(CC) $(ALL_CFLAGS) -c -o $@ $<

Expand All @@ -37,7 +37,10 @@ tests: $(ALL_OBJS)
%.o: %.c
@$(CC_CMD)

vendor/unity.o: vendor/unity.c vendor/unity.h vendor/unity_internals.h
@$(CC_CMD)

clean:
@rm -f *.o tests
@rm -f *.o vendor/*.o tests

.PHONY: all clean
63 changes: 50 additions & 13 deletions exercises/concept/basics/basics_test.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
#include <assert.h>
#include <inttypes.h>
#include "vendor/unity.h"

int64_t expected_minutes_in_oven(void);
int64_t remaining_minutes_in_oven(int64_t actual_minutes_in_oven);
int64_t preparation_time_in_minutes(int64_t number_of_layers);
int64_t elapsed_time_in_minutes(int64_t number_of_layers, int64_t actual_minutes_in_oven);
#include <stdint.h>

extern int64_t expected_minutes_in_oven(void);
extern int64_t remaining_minutes_in_oven(int64_t actual_minutes_in_oven);
extern int64_t preparation_time_in_minutes(int64_t number_of_layers);
extern int64_t elapsed_time_in_minutes(int64_t number_of_layers, int64_t actual_minutes_in_oven);

void setUp(void) {
}

void tearDown(void) {
}

void test_expected(void) {
TEST_ASSERT_EQUAL_INT64(40, expected_minutes_in_oven());
}

void test_remaining(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT64(15, remaining_minutes_in_oven(25));
}

void test_preparation_one(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT64(2, preparation_time_in_minutes(1));
}

void test_preparation_many(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT64(8, preparation_time_in_minutes(4));
}

void test_elapsed_one(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT64(32, elapsed_time_in_minutes(1, 30));
}

void test_elapsed_many(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL_INT64(16, elapsed_time_in_minutes(4, 8));
}

int main(void) {
assert(40 == expected_minutes_in_oven());
assert(15 == remaining_minutes_in_oven(25));
assert(2 == preparation_time_in_minutes(1));
assert(8 == preparation_time_in_minutes(4));
assert(32 == elapsed_time_in_minutes(1, 30));
assert(16 == elapsed_time_in_minutes(4, 8));
return 0;
UNITY_BEGIN();
RUN_TEST(test_expected);
RUN_TEST(test_remaining);
RUN_TEST(test_preparation_one);
RUN_TEST(test_preparation_many);
RUN_TEST(test_elapsed_one);
RUN_TEST(test_elapsed_many);
return UNITY_END();
}
Loading

0 comments on commit 546abd5

Please sign in to comment.