Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concept exercise uses unity #255

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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