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.

49 lines
1.0 KiB

11 months ago
  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "SchereSteinPapier.h"
  4. #include <stdlib.h>
  5. void setUp(void)
  6. {
  7. }
  8. void tearDown(void)
  9. {
  10. }
  11. void test_Scheresteinpapier_generateRandom(void) {
  12. srand(42);
  13. for (int i = 0; i < 100; ++i) {
  14. int result = generateRandom();
  15. TEST_ASSERT_TRUE(result >= 0 && result <= 2);
  16. }
  17. }
  18. void test_Scheresteinpapier_determineWinner(void) {
  19. for (int spieler = 0; spieler <= 2; ++spieler) {
  20. for (int computer = 0; computer <= 2; ++computer) {
  21. int result = determineWinner(spieler, computer);
  22. if ((spieler == 0 && computer == 2) ||
  23. (spieler == 1 && computer == 0) ||
  24. (spieler == 2 && computer == 1)) {
  25. TEST_ASSERT_EQUAL(1, result); // Spieler gewinnt
  26. }
  27. else if (spieler == computer) {
  28. TEST_ASSERT_EQUAL(0, result); // Unentschieden
  29. }
  30. else {
  31. TEST_ASSERT_EQUAL(-1, result); // Computer gewinnt
  32. }
  33. }
  34. }
  35. }
  36. #endif // TEST