From 2b6449f2a43c96efc7bb259467574cdc6c51fdc9 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:01:54 +0100 Subject: [PATCH] added setRoomPredecessor with test --- src/c/map.c | 18 +++++++++++++++--- src/c/map.h | 3 ++- test/c/test_map.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/c/map.c b/src/c/map.c index eb67707..5e0c8c4 100644 --- a/src/c/map.c +++ b/src/c/map.c @@ -1,4 +1,4 @@ -//headers +// headers #include "map.h" Room *getMap(char *gameMapFile) @@ -59,10 +59,22 @@ Room *getMap(char *gameMapFile) return fillMap; }; -int getRoomSuccessor(Room *room){ +int getRoomSuccessor(Room *room) +{ return room->successor; } -void setRoomSuccessor(Room *room, int successorSet){ +void setRoomSuccessor(Room *room, int successorSet) +{ room->successor = successorSet; } + +int getRoomPredecessor(Room *room) +{ + return room->predecessor; +} + +void setRoomPredecessor(Room *room, int predecessorSet) +{ + room->predecessor = predecessorSet; +} diff --git a/src/c/map.h b/src/c/map.h index e26284b..966a89c 100644 --- a/src/c/map.h +++ b/src/c/map.h @@ -30,6 +30,7 @@ Room *getMap(char *gameMapFile); int getRoomSuccessor(Room *room); void setRoomSuccessor(Room *room, int successorSet); - +int getRoomPredecessor(Room *room); +void setRoomPredecessor(Room *room, int predecessorSet); #endif // MAP_H \ No newline at end of file diff --git a/test/c/test_map.c b/test/c/test_map.c index 337a247..9cb774f 100644 --- a/test/c/test_map.c +++ b/test/c/test_map.c @@ -80,6 +80,40 @@ void test_setRoomSuccessor(void) TEST_ASSERT_EQUAL(successor, result); } +void test_getRoomPredecessor(void) +{ + // arrange + int predecessor = 1, result; + Room test; + test.predecessor = predecessor; + + /* act */ + // Die Funktion wird ausgeführt + result = getRoomPredecessor(&test); + + // output + printf("getRoomPredecessor | Successor should be: %d -> is: %d", predecessor, result); + + // assert + TEST_ASSERT_EQUAL(predecessor, result); +} + +void test_setRoomPredecessor(void) +{ + // arrange + int predecessor = 3, result; + + // act + Room test; + setRoomPredecessor(&test, predecessor); + result = test.predecessor; + + //output + printf("setRoomPredecessor | successor to set: %d -> is: %d", predecessor, result); + + // assert + TEST_ASSERT_EQUAL(predecessor, result); +} #endif // TEST