Space Walk board game
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.
 
 

69 lines
1.7 KiB

  1. #include <cassert>
  2. #include <iostream>
  3. #include <ncurses.h>
  4. #include "board.h"
  5. #include "inputoutput.h"
  6. #include "maingame.h"
  7. #include "player.h"
  8. #include "spaceship.h"
  9. #include "test.h"
  10. Test::Test() {
  11. // IO::print("Unit test\n");
  12. refresh();
  13. // Board tests
  14. Board *board = new Board;
  15. char arrayShip[3] = { SpaceShip::SMALL, SpaceShip::MEDIUM, SpaceShip::BIG };
  16. SpaceShip *ship = new SpaceShip(1, arrayShip[0]);
  17. SpaceShip *ship2 = new SpaceShip(1, arrayShip[1]);
  18. SpaceShip *ship3 = new SpaceShip(1, arrayShip[2]);
  19. board->setShip(0, ship);
  20. board->setShip(0, ship);
  21. board->setShip(1, ship);
  22. board->setShip(1, ship2);
  23. board->setShip(2, ship3);
  24. for (int i = 0; i < 3; i++) {
  25. auto ships = board->getShips(i);
  26. // printf("%lu\n", ships->size());
  27. for (int j = 0; j < (int)ships->size(); j++) {
  28. // printf("%d\n", ships->at(j)->getSize());
  29. assert(ships->at(j)->getSize() == arrayShip[i]);
  30. }
  31. assert(ships->size() == 1);
  32. }
  33. board->moveShip(3, ship3);
  34. assert(board->getShip(3, 0)->getSize() == arrayShip[2]);
  35. // char array[SHIP_SIZE] = {
  36. // SpaceShip::SMALL, SpaceShip::SMALL, SpaceShip::SMALL,
  37. // SpaceShip::MEDIUM, SpaceShip::MEDIUM, SpaceShip::MEDIUM,
  38. // SpaceShip::BIG, SpaceShip::BIG, SpaceShip::BIG,
  39. // SpaceShip::SMALL, SpaceShip::SMALL, SpaceShip::SMALL,
  40. // SpaceShip::MEDIUM, SpaceShip::MEDIUM, SpaceShip::MEDIUM,
  41. // SpaceShip::BIG, SpaceShip::BIG, SpaceShip::BIG,
  42. // };
  43. // for (unsigned char i = 0; i < SHIP_SIZE; i++) {
  44. // // printf("%d\n", board.ships[i]->getSize());
  45. // // printf("%d\n", array[i]);
  46. // assert(board.ships[i]->getSize() == array[i]);
  47. // }
  48. // IO::print("Passed board checks..");
  49. refresh();
  50. getch();
  51. // Cleanup resources
  52. delete board;
  53. delete ship;
  54. delete ship2;
  55. delete ship3;
  56. IO::setQuit();
  57. }