mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Added C and check library version
This commit is contained in:
parent
e916fdd8ac
commit
96d9751300
90
c-check/GildedRose.c
Normal file
90
c-check/GildedRose.c
Normal file
@ -0,0 +1,90 @@
|
||||
#include <string.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
c-check/GildedRose.h
Normal file
9
c-check/GildedRose.h
Normal file
@ -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);
|
||||
BIN
c-check/GildedRose.o
Normal file
BIN
c-check/GildedRose.o
Normal file
Binary file not shown.
43
c-check/GildedRoseTextTests.c
Normal file
43
c-check/GildedRoseTextTests.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
||||
BIN
c-check/GildedRoseTextTests.o
Normal file
BIN
c-check/GildedRoseTextTests.o
Normal file
Binary file not shown.
46
c-check/Makefile
Normal file
46
c-check/Makefile
Normal file
@ -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}
|
||||
5
c-check/README
Normal file
5
c-check/README
Normal file
@ -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
|
||||
BIN
c-check/golden_rose
Executable file
BIN
c-check/golden_rose
Executable file
Binary file not shown.
2
c-check/run-once.sh
Executable file
2
c-check/run-once.sh
Executable file
@ -0,0 +1,2 @@
|
||||
make
|
||||
./GildedRoseTextTests
|
||||
Loading…
Reference in New Issue
Block a user