diff --git a/c-check/GildedRose.c b/c-check/GildedRose.c new file mode 100644 index 00000000..afb97bbe --- /dev/null +++ b/c-check/GildedRose.c @@ -0,0 +1,90 @@ +#include +#include "GildedRose.h" + +Item* +init_item(Item* item, const char *name, int sellIn, int quality) +{ + item->sellIn = sellIn; + item->quality = quality; + item->name = strdup(name); + + return item; +} + +void update_quality(Item items[], int size) +{ + int i; + + for (i = 0; i < size; i++) + { + if (strcmp(items[i].name, "Aged Brie") && strcmp(items[i].name, "Backstage passes to a TAFKAL80ETC concert")) + { + if (items[i].quality > 0) + { + if (strcmp(items[i].name, "Sulfuras, Hand of Ragnaros")) + { + items[i].quality = items[i].quality - 1; + } + } + } + else + { + if (items[i].quality < 50) + { + items[i].quality = items[i].quality + 1; + + if (!strcmp(items[i].name, "Backstage passes to a TAFKAL80ETC concert")) + { + if (items[i].sellIn < 11) + { + if (items[i].quality < 50) + { + items[i].quality = items[i].quality + 1; + } + } + + if (items[i].sellIn < 6) + { + if (items[i].quality < 50) + { + items[i].quality = items[i].quality + 1; + } + } + } + } + } + + if (strcmp(items[i].name, "Sulfuras, Hand of Ragnaros")) + { + items[i].sellIn = items[i].sellIn - 1; + } + + if (items[i].sellIn < 0) + { + if (strcmp(items[i].name, "Aged Brie")) + { + if (strcmp(items[i].name, "Backstage passes to a TAFKAL80ETC concert")) + { + if (items[i].quality > 0) + { + if (strcmp(items[i].name, "Sulfuras, Hand of Ragnaros")) + { + items[i].quality = items[i].quality - 1; + } + } + } + else + { + items[i].quality = items[i].quality - items[i].quality; + } + } + else + { + if (items[i].quality < 50) + { + items[i].quality = items[i].quality + 1; + } + } + } + } +} diff --git a/c-check/GildedRose.h b/c-check/GildedRose.h new file mode 100644 index 00000000..78d54a08 --- /dev/null +++ b/c-check/GildedRose.h @@ -0,0 +1,9 @@ +typedef struct +{ + char *name; + int sellIn; + int quality; +} Item; + +extern Item* init_item(Item* item, const char *name, int sellIn, int quality); +extern void update_quality(Item items[], int size); diff --git a/c-check/GildedRose.o b/c-check/GildedRose.o new file mode 100644 index 00000000..37283c3a Binary files /dev/null and b/c-check/GildedRose.o differ diff --git a/c-check/GildedRoseTextTests.c b/c-check/GildedRoseTextTests.c new file mode 100644 index 00000000..d200ca0c --- /dev/null +++ b/c-check/GildedRoseTextTests.c @@ -0,0 +1,43 @@ +#include +#include "GildedRose.h" + +int +print_item(Item *item) +{ + return printf("%s, %d, %d\n", item->name, item->sellIn, item->quality); +} + +int main() +{ + Item items[9]; + int last = 0; + int day; + int index; + + init_item(items + last++, "+5 Dexterity Vest", 10, 20); + init_item(items + last++, "Aged Brie", 2, 0); + init_item(items + last++, "Elixir of the Mongoose", 5, 7); + init_item(items + last++, "Sulfuras, Hand of Ragnaros", 0, 80); + init_item(items + last++, "Sulfuras, Hand of Ragnaros", -1, 80); + init_item(items + last++, "Backstage passes to a TAFKAL80ETC concert", 15, 20); + init_item(items + last++, "Backstage passes to a TAFKAL80ETC concert", 10, 49); + init_item(items + last++, "Backstage passes to a TAFKAL80ETC concert", 5, 49); + // this Conjured item doesn't yet work properly + init_item(items + last++, "Conjured Mana Cake", 3, 6); + + puts("OMGHAI!"); + + for (day = 0; day <= 30; day++) + { + printf("-------- day %d --------\n", day); + printf("name, sellIn, quality\n"); + for(index = 0; index < last; index++) { + print_item(items + index); + } + + printf("\n"); + + update_quality(items, last); + } + return 0; +} diff --git a/c-check/GildedRoseTextTests.o b/c-check/GildedRoseTextTests.o new file mode 100644 index 00000000..e1981da6 Binary files /dev/null and b/c-check/GildedRoseTextTests.o differ diff --git a/c-check/Makefile b/c-check/Makefile new file mode 100644 index 00000000..6e077a88 --- /dev/null +++ b/c-check/Makefile @@ -0,0 +1,46 @@ +# Makefile for building the kata file with the Google Testing Framework +# +# SYNOPSIS: +# +# make [all] - makes everything, runs tests +# make TARGET - makes the given target. +# make clean - removes all files generated by make. +# make memtest - run memory leak analysis + +# The _POSIX_C_SOURCE definition prevents the compiler from throwing warnings +CFLAGS = `pkg-config --cflags check` -g --std=c99 -D_POSIX_C_SOURCE=200809L +LIBS = `pkg-config --libs check` + +# All files that should be part of your test should start with 'test' +TEST_SRC = `ls test*.[c\|h]` +TEST_BASE = $(basename ${TEST_SRC}) +TEST_OBJECTS = $(addsuffix .o, ${TEST_BASE}) + +# If you add more implementation classes, add them to this variable +OBJECT_UNDER_TEST = GildedRose.o + +# This is the test application. You can run this program to see your test output +TEST_APP = test_gildedrose + + +# This will generate output for several products over a course of several days. +# You can run this application to build golden rule tests +GOLDEN_APP = golden_rose + +all: ${TEST_APP} ${GOLDEN_APP} + ./${TEST_APP} + +${TEST_APP}: ${TEST_OBJECTS} ${OBJECT_UNDER_TEST} + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + +${GOLDEN_APP}: GildedRoseTextTests.o ${OBJECT_UNDER_TEST} + $(CC) $(CFLAGS) -o $@ $^ + +# If you're not on a mac, you should run memtest (in fact, consider adding it to the 'all' target). +# If you're on a mac, complain to apple for breaking an important development tool. +memtest: ${TEST_APP} + valgrind --leak-check=full --error-exitcode=1 ./${TEST_APP} --nofork + +clean: + rm -f *.o + rm -f ${TEST_APP} diff --git a/c-check/README b/c-check/README new file mode 100644 index 00000000..2bc1f69b --- /dev/null +++ b/c-check/README @@ -0,0 +1,5 @@ +run-once.sh runs your tests once + +Assumptions: + - make and a C++ compiler (like gcc) is installed on your system and is in the PATH + - The CppUTest framework is in the directory CppUTest diff --git a/c-check/golden_rose b/c-check/golden_rose new file mode 100755 index 00000000..a7b256d9 Binary files /dev/null and b/c-check/golden_rose differ diff --git a/c-check/run-once.sh b/c-check/run-once.sh new file mode 100755 index 00000000..4f6b2303 --- /dev/null +++ b/c-check/run-once.sh @@ -0,0 +1,2 @@ +make +./GildedRoseTextTests