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

Item tests #3

Merged
merged 6 commits into from
May 1, 2019
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
1 change: 1 addition & 0 deletions test/craft_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void AddAllTests() {
TestTest_AddTests();
AuthTest_AddTests();
MatrixTest_AddTests();
ItemTest_AddTests();
}

int main(int argc, char** argv) {
Expand Down
111 changes: 111 additions & 0 deletions test/item_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <math.h>

#include "../src/item.h"

#include <CUnit/CUnit.h>
#include "item_test.h"

static void handleValidTransparent(){
CU_ASSERT(is_transparent(0));
CU_ASSERT(is_transparent(10));
CU_ASSERT(is_transparent(15));

}

static void handleInvalidTransparent(){
for (int i = 1; i<64; i++){
if(i!=10 && i!=15 && i!=17 && i!=18 && i!=19 && i!=20 && i!=21 && i!=22 && i!=23 ) //apparently plants are transparent
CU_ASSERT_FALSE(is_transparent(i));

}

}

static void handleValidObstacle(){
for (int i = 1; i<64; i++){
if( i<16 || i>23 ) //apparently plants are transparent
CU_ASSERT(is_obstacle(i));
}
}

static void handleInvalidObstacle(){
for (int i = 16; i<24; i++){
CU_ASSERT_FALSE(is_obstacle(i));
}

}

static void handleValidDestructable(){
for (int i = 1; i<64; i++){
if(i != 16)
CU_ASSERT(is_destructable(i));
}

}

static void handleInvalidDestructable(){
CU_ASSERT_FALSE(is_destructable(0));
CU_ASSERT_FALSE(is_destructable(16));

}

static void handleValidPlant(){
for (int i = 17; i<24; i++){
CU_ASSERT(is_plant(i));
}

}

static void handleInvalidPlant(){
for (int i = 0; i<64; i++){
if(i<17 || i>23)
CU_ASSERT_FALSE(is_plant(i));
}
}


static CU_TestInfo transparency_tests[] = {
{"Properly handles valid transparent items", handleValidTransparent},
{"Properly handles invalid transparent items", handleInvalidTransparent},
CU_TEST_INFO_NULL
};

static CU_TestInfo destructable_tests[] = {
{"Properly handles valid destructable items", handleValidDestructable},
{"Properly handles invalid destructable items", handleInvalidDestructable},
CU_TEST_INFO_NULL
};

static CU_TestInfo obstacle_tests[] = {
{"Properly handles valid obstacle items", handleValidObstacle},
{"Properly handles invalid obstacle items", handleInvalidObstacle},
CU_TEST_INFO_NULL
};

static CU_TestInfo plant_tests[] = {
{"Properly handles valid plant items", handleValidPlant},
{"Properly handles invalid plant items", handleInvalidPlant},
CU_TEST_INFO_NULL

};

static CU_SuiteInfo suites[] = {
{"transparency suite", NULL, NULL, NULL, NULL, transparency_tests},
{"obstacle suite", NULL, NULL, NULL, NULL, obstacle_tests},
{"destructable suite", NULL, NULL, NULL, NULL, destructable_tests},
{"plant suite", NULL, NULL, NULL, NULL, plant_tests},
CU_SUITE_INFO_NULL
};

void ItemTest_AddTests() {
assert(NULL != CU_get_registry());
assert(!CU_is_test_running());

if(CU_register_suites(suites) != CUE_SUCCESS) {
fprintf(stderr, "suite registration failed - %s\n", CU_get_error_msg());
exit(EXIT_FAILURE);
}
}
7 changes: 7 additions & 0 deletions test/item_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __ITEM_TEST_H__
#define __ITEM_TEST_H__

void ItemTest_AddTests();


#endif /* __MATRIX_TEST_H__ */