You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
1.9 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "schach.h"
  4. #include "string.h"
  5. void setUp(void)
  6. {
  7. }
  8. void tearDown(void)
  9. {
  10. }
  11. void test_print_Schachfeld(void){
  12. /* arrange */
  13. char expected = 'S';
  14. int x = 8;
  15. int y = 8;
  16. /* act */
  17. char** Spielfeld = create_Schachfeld(x, y);
  18. /* assert */
  19. TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[5][0]);
  20. TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[4][3]);
  21. }
  22. void test_print_Schachfeld_Turm_weiss(void){
  23. /* arrange */
  24. char expected = 'T';
  25. int x = 8;
  26. int y = 8;
  27. /* act */
  28. char** Spielfeld = create_Schachfeld(x, y);
  29. /* assert */
  30. TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[0][0]);
  31. TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[0][7]);
  32. }
  33. void test_print_Schachfeld_Bauern_weiss(void){
  34. /* arrange */
  35. char expected = 'B';
  36. int x = 8;
  37. int y = 8;
  38. /* act */
  39. char** Spielfeld = create_Schachfeld(x, y);
  40. /* assert */
  41. for(int l = 0;l<y;l++){
  42. TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[1][l]);
  43. }
  44. }
  45. void test_print_Schachfeld_dame_schwarz(void){
  46. /* arrange */
  47. char expected = 'd';
  48. int x = 8;
  49. int y = 8;
  50. /* act */
  51. char** Spielfeld = create_Schachfeld(x, y);
  52. /* assert */
  53. TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[7][3]);
  54. //TEST_ASSERT_EQUAL_CHAR(expected,Spielfeld[0][7]);
  55. }
  56. void test_read_input(void) {
  57. /* arrange */
  58. const char *input = "8\n";
  59. int result = 0;
  60. int expected = 7;
  61. FILE *original_stdin = freopen(NULL, "r", stdin);
  62. FILE *tempInput = fopen("temp_input.txt", "w");
  63. fputs(input, tempInput);
  64. fclose(tempInput);
  65. tempInput = freopen("temp_input.txt", "r", stdin);
  66. /* act */
  67. result = read_input();
  68. /* assert */
  69. TEST_ASSERT_EQUAL_INT(expected, result);
  70. /* Clean up */
  71. fclose(tempInput);
  72. freopen("/dev/tty", "r", stdin);
  73. freopen(NULL, "r", stdin);
  74. }
  75. #endif // TEST