Advertisement
rkynaa

testGameView.c (with extras)

Jan 20th, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.90 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // COMP2521 18x1 ... the Fury of Dracula
  3. // testGameView.c: test the GameView ADT
  4. //
  5. // As supplied, these are very simple tests.  You should write more!
  6. // Don't forget to be rigorous and thorough while writing tests.
  7. //
  8. // 2014-07-01   v1.0    Team Dracula <cs2521@cse.unsw.edu.au>
  9. // 2017-12-01   v1.1    Team Dracula <cs2521@cse.unsw.edu.au>
  10.  
  11. #include <assert.h>
  12. #include <stdbool.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "GameView.h"
  18.  
  19. int
  20. main (int argc, char *argv[])
  21. {
  22.     do {////////////////////////////////////////////////////////////////
  23.         puts ("Test basic empty initialisation");
  24.  
  25.         char *trail = "";
  26.         PlayerMessage messages[] = {};
  27.         GameView gv = newGameView (trail, messages);
  28.  
  29.         assert (getCurrentPlayer (gv) == PLAYER_LORD_GODALMING);
  30.         assert (getRound (gv) == 0);
  31.         assert (getHealth (gv, PLAYER_DR_SEWARD) ==
  32.                 GAME_START_HUNTER_LIFE_POINTS);
  33.         assert (getHealth (gv, PLAYER_DRACULA) ==
  34.                 GAME_START_BLOOD_POINTS);
  35.         assert (getScore (gv) == GAME_START_SCORE);
  36.         assert (getLocation (gv, PLAYER_LORD_GODALMING) ==
  37.                 UNKNOWN_LOCATION);
  38.  
  39.         puts ("passed");
  40.         disposeGameView (gv);
  41.     } while (0);
  42.  
  43.  
  44.     do {////////////////////////////////////////////////////////////////
  45.         puts ("Test for Dracula trail and basic functions");
  46.  
  47.         char *trail =
  48.             "GST.... SAO.... HZU.... MBB.... DC?....";
  49.         PlayerMessage messages[] = {
  50.             "Hello", "Rubbish", "Stuff", "", "Mwahahah"};
  51.         GameView gv = newGameView (trail, messages);
  52.  
  53.         assert (getCurrentPlayer (gv) == PLAYER_LORD_GODALMING);
  54.         assert (getRound (gv) == 1);
  55.         assert (getLocation (gv, PLAYER_LORD_GODALMING) == STRASBOURG);
  56.         assert (getLocation (gv, PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
  57.         assert (getLocation (gv, PLAYER_VAN_HELSING) == ZURICH);
  58.         assert (getLocation (gv, PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
  59.         assert (getLocation (gv, PLAYER_DRACULA) == CITY_UNKNOWN);
  60.         assert (getHealth (gv, PLAYER_DRACULA) ==
  61.                 GAME_START_BLOOD_POINTS);
  62.  
  63.         puts ("passed");
  64.         disposeGameView (gv);
  65.     } while (0);
  66.  
  67.  
  68.     do {////////////////////////////////////////////////////////////////
  69.         puts ("Test for encountering Dracula and hunter history");
  70.  
  71.         char *trail =
  72.             "GST.... SAO.... HCD.... MAO.... DGE.... "
  73.             "GGED...";
  74.         PlayerMessage messages[] = {
  75.             "Hello", "Rubbish",  "Stuff", "", "Mwahahah",
  76.             "Aha!"};
  77.         GameView gv = newGameView (trail, messages);
  78.  
  79.         assert (getLocation (gv, PLAYER_DRACULA) == GENEVA);
  80.         assert (getHealth (gv, PLAYER_LORD_GODALMING) == 5);
  81.         assert (getHealth (gv, PLAYER_DRACULA) == 30);
  82.         assert (getLocation (gv, PLAYER_LORD_GODALMING) == GENEVA);
  83.  
  84.         LocationID history[TRAIL_SIZE];
  85.         getHistory (gv, PLAYER_DRACULA, history);
  86.         assert (history[0] == GENEVA);
  87.         assert (history[1] == UNKNOWN_LOCATION);
  88.  
  89.         getHistory (gv, PLAYER_LORD_GODALMING, history);
  90.         assert (history[0] == GENEVA);
  91.         assert (history[1] == STRASBOURG);
  92.         assert (history[2] == UNKNOWN_LOCATION);
  93.  
  94.         getHistory (gv, PLAYER_DR_SEWARD, history);
  95.         assert (history[0] == ATLANTIC_OCEAN);
  96.         assert (history[1] == UNKNOWN_LOCATION);
  97.  
  98.         puts ("passed");
  99.         disposeGameView (gv);
  100.     } while (0);
  101.  
  102.  
  103.     do {////////////////////////////////////////////////////////////////
  104.         puts ("Test for Dracula doubling back at sea, "
  105.               "and losing blood points (Hunter View)");
  106.  
  107.         char *trail =
  108.             "GGE.... SGE.... HGE.... MGE.... DS?.... "
  109.             "GST.... SST.... HST.... MST.... DD1....";
  110.         PlayerMessage messages[] = {
  111.             "Hello", "Rubbish", "Stuff", "", "Mwahahah",
  112.             "Aha!", "", "", "", "Back I go"};
  113.         GameView gv = newGameView (trail, messages);
  114.  
  115.         assert (getCurrentPlayer (gv) == 0);
  116.         assert (getHealth (gv, PLAYER_DRACULA) ==
  117.                 GAME_START_BLOOD_POINTS - 4);
  118.         assert (getLocation (gv, PLAYER_DRACULA) == DOUBLE_BACK_1);
  119.  
  120.         LocationID history[TRAIL_SIZE];
  121.         getHistory (gv, PLAYER_DRACULA, history);
  122.         assert (history[0] == DOUBLE_BACK_1);
  123.         assert (history[1] == SEA_UNKNOWN);
  124.  
  125.         puts ("passed");
  126.         disposeGameView (gv);
  127.     } while (0);
  128.  
  129.  
  130.     do {////////////////////////////////////////////////////////////////
  131.         puts ("Test for Dracula doubling back at sea, "
  132.               "and losing blood points (Drac View)");
  133.  
  134.         char *trail =
  135.             "GGE.... SGE.... HGE.... MGE.... DEC.... "
  136.             "GST.... SST.... HST.... MST.... DD1....";
  137.         PlayerMessage messages[] = {
  138.             "Hello", "Rubbish", "Stuff", "", "Mwahahah",
  139.             "Aha!", "", "", "", "Back I go"};
  140.         GameView gv = newGameView (trail, messages);
  141.  
  142.         assert (getCurrentPlayer (gv) == 0);
  143.         assert (getHealth (gv, PLAYER_DRACULA) ==
  144.                 GAME_START_BLOOD_POINTS - 4);
  145.         assert (getLocation (gv, PLAYER_DRACULA) == DOUBLE_BACK_1);
  146.  
  147.         LocationID history[TRAIL_SIZE];
  148.         getHistory (gv, PLAYER_DRACULA, history);
  149.         assert (history[0] == DOUBLE_BACK_1);
  150.         assert (history[1] == ENGLISH_CHANNEL);
  151.  
  152.         puts ("passed");
  153.         disposeGameView (gv);
  154.     } while (0);
  155.  
  156.  
  157.     do {////////////////////////////////////////////////////////////////
  158.         puts ("Test for connections");
  159.         char *trail = "";
  160.         PlayerMessage messages[] = {};
  161.         GameView gv = newGameView (trail, messages);
  162.  
  163.         do {
  164.             puts ("Checking Galatz road connections");
  165.             int size, *edges = connectedLocations (gv, &size,
  166.                 GALATZ, PLAYER_LORD_GODALMING, 0, true, false, false);
  167.  
  168.             bool seen[NUM_MAP_LOCATIONS] = {false};
  169.             for (int i = 0; i < size; i++)
  170.                 seen[edges[i]] = true;
  171.  
  172.             assert (size == 5);
  173.             assert (seen[GALATZ]);
  174.             assert (seen[CONSTANTA]);
  175.             assert (seen[BUCHAREST]);
  176.             assert (seen[KLAUSENBURG]);
  177.             assert (seen[CASTLE_DRACULA]);
  178.  
  179.             free (edges);
  180.         } while (0);
  181.  
  182.         do {
  183.             puts ("Checking Ionian Sea sea connections");
  184.             int size, *edges = connectedLocations (gv, &size,
  185.                 IONIAN_SEA, PLAYER_LORD_GODALMING, 0,
  186.                 false, false, true);
  187.  
  188.             bool seen[NUM_MAP_LOCATIONS] = {false};
  189.             for (int i = 0; i < size; i++)
  190.                 seen[edges[i]] = true;
  191.  
  192.             assert (size == 7);
  193.             assert (seen[IONIAN_SEA]);
  194.             assert (seen[BLACK_SEA]);
  195.             assert (seen[ADRIATIC_SEA]);
  196.             assert (seen[TYRRHENIAN_SEA]);
  197.             assert (seen[ATHENS]);
  198.             assert (seen[VALONA]);
  199.             assert (seen[SALONICA]);
  200.  
  201.             free (edges);
  202.         } while (0);
  203.  
  204.         do {
  205.             puts ("Checking Athens rail connections (none)");
  206.             int size, *edges = connectedLocations (gv, &size,
  207.                 ATHENS, PLAYER_LORD_GODALMING, 0,
  208.                 false, true, false);
  209.  
  210.             assert (size == 1);
  211.             assert (edges[0] == ATHENS);
  212.  
  213.             free (edges);
  214.         } while (0);
  215.  
  216.         puts ("passed");
  217.         disposeGameView (gv);
  218.     } while (0);
  219.  
  220.     // Extra tests:
  221.     do {////////////////////////////////////////////////////////////////
  222.         puts ("Test for encountering Dracula at the sea and hunter history (EXTRA TEST #1)");
  223.  
  224.         char *trail =
  225.             "GST.... SAM.... HBA.... MAM.... DEC.V.. "
  226.             "GAO.... SMI.... HMS.... MECVD..";
  227.         PlayerMessage messages[] = {
  228.             "Hello", "Rubbish",  "Stuff", "", "Mwahahah",
  229.             "Hmmm?", "Perhaps", "", "Gotcha"};
  230.         GameView gv = newGameView (trail, messages);
  231.  
  232.         assert (getLocation (gv, PLAYER_DRACULA) == ENGLISH_CHANNEL);
  233.         assert (getHealth (gv, PLAYER_MINA_HARKER) == 5);
  234.         assert (getHealth (gv, PLAYER_DRACULA) == 28);
  235.         assert (getLocation (gv, PLAYER_MINA_HARKER) == ENGLISH_CHANNEL);
  236.  
  237.         LocationID history[TRAIL_SIZE];
  238.         getHistory (gv, PLAYER_DRACULA, history);
  239.         assert (history[0] == ENGLISH_CHANNEL);
  240.         assert (history[1] == UNKNOWN_LOCATION);
  241.  
  242.         getHistory (gv, PLAYER_LORD_GODALMING, history);
  243.         assert (history[0] == ATLANTIC_OCEAN);
  244.         assert (history[1] == STRASBOURG);
  245.         assert (history[2] == UNKNOWN_LOCATION);
  246.  
  247.         getHistory (gv, PLAYER_DR_SEWARD, history);
  248.         assert (history[0] == MILAN);
  249.         assert (history[1] == AMSTERDAM);
  250.         assert (history[2] == UNKNOWN_LOCATION);
  251.  
  252.         getHistory (gv, PLAYER_VAN_HELSING, history);
  253.         assert (history[0] == MEDITERRANEAN_SEA);
  254.         assert (history[1] == BARCELONA);
  255.         assert (history[2] == UNKNOWN_LOCATION);
  256.  
  257.         getHistory (gv, PLAYER_MINA_HARKER, history);
  258.         assert (history[0] == ENGLISH_CHANNEL);
  259.         assert (history[1] == AMSTERDAM);
  260.         assert (history[2] == UNKNOWN_LOCATION);
  261.  
  262.         puts ("passed");
  263.         disposeGameView (gv);
  264.     } while (0);
  265.  
  266.     do {////////////////////////////////////////////////////////////////
  267.         puts ("Test for dracula regain blood at the castle after lost few blood (EXTRA TEST #2)");
  268.  
  269.         char *trail =
  270.             "GEC.... SBU.... HBA.... MBU.... DTS.V.. "
  271.             "GBU.... SME.... HEC.... MST.... DCD....";
  272.         PlayerMessage messages[] = {
  273.             "Hello", "Rubbish",  "Perhaps?", "", "Mwahahah?"
  274.             "Wait!", "Really?", "", "Gotcha?", "Mwahahah"};
  275.         GameView gv = newGameView (trail, messages);
  276.  
  277.         assert (getCurrentPlayer (gv) == 0);
  278.         assert (getHealth (gv, PLAYER_DRACULA) ==
  279.                 GAME_START_BLOOD_POINTS);
  280.         assert (getLocation (gv, PLAYER_DRACULA) == CASTLE_DRACULA);
  281.  
  282.         LocationID history[TRAIL_SIZE];
  283.         getHistory (gv, PLAYER_DRACULA, history);
  284.         assert (history[0] == CASTLE_DRACULA);
  285.         assert (history[1] == TYRRHENIAN_SEA);
  286.         assert (history[2] == UNKNOWN_LOCATION);
  287.  
  288.         puts ("passed");
  289.         disposeGameView (gv);
  290.     } while (0);
  291.  
  292.     do {////////////////////////////////////////////////////////////////
  293.         puts ("Test for kill the dracula (EXTRA TEST #3)");
  294.  
  295.         char *trail =
  296.             "GST.... SMU.... HGE.... MMR.... DZU.... "
  297.             "GZUD... SZUD... HZUD... MZUD... DGE.... "
  298.             "GGED... SGED... HZU.... MZU.... DMR.... "
  299.             "GGE.... SGE.... HMRD... MMRD... DMS.... "
  300.             "GMR.... SMR.... HMR.... MMR.... DBA.... "
  301.             "GTO.... STO.... HTO.... MTO.... DSR.... "
  302.             "GTO.... STO.... HSRD... MSRD...";
  303.         PlayerMessage messages[] = {
  304.             "Hello", "Rubbish",  "Stuff", "", "Mwahahah",
  305.             "Hmmm?", "Perhaps", "", "Gotcha", "Mwahahah",
  306.             "Aha!", "", "", "", "Mwahahah",
  307.             "", "There!", "", "", "Mwahahah",
  308.             "", "", "Here!", "Aha!", "Mwahahah",
  309.             "Guys!", "Here!", "Come!", "Yeah!", "No!",
  310.             "", "", "Die!", "Yeah!"};
  311.         GameView gv = newGameView (trail, messages);
  312.  
  313.         assert (getLocation (gv, PLAYER_DRACULA) == BELGRADE);
  314.         assert (getHealth (gv, PLAYER_MINA_HARKER) == 3);
  315.         assert (getHealth (gv, PLAYER_LORD_GODALMING) == 3);
  316.         assert (getHealth (gv, PLAYER_DR_SEWARD) == 3);
  317.         assert (getHealth (gv, PLAYER_VAN_HELSING) == 3);
  318.         assert (getHealth (gv, PLAYER_DRACULA) == 0);
  319.         assert (getLocation (gv, PLAYER_MINA_HARKER) == BRUSSELS);
  320.         assert (getLocation (gv, PLAYER_LORD_GODALMING) == BELGRADE);
  321.         assert (getLocation (gv, PLAYER_DR_SEWARD) == BRUSSELS);
  322.         assert (getLocation (gv, PLAYER_VAN_HELSING) == BRUSSELS);
  323.  
  324.         LocationID history[TRAIL_SIZE];
  325.         getHistory (gv, PLAYER_DRACULA, history);
  326.         assert (history[0] == SARAGOSSA);
  327.         assert (history[1] == BARCELONA);
  328.         assert (history[2] == MEDITERRANEAN_SEA);
  329.         assert (history[3] == MARSEILLES);
  330.         assert (history[4] == GENEVA);
  331.         assert (history[5] == ZURICH);
  332.         assert (history[6] == UNKNOWN_LOCATION);
  333.  
  334.         getHistory (gv, PLAYER_LORD_GODALMING, history);
  335.         assert (history[0] == TOULOUSE);
  336.         assert (history[1] == TOULOUSE);
  337.         assert (history[2] == MARSEILLES);
  338.         assert (history[3] == GENEVA);
  339.         assert (history[4] == GENEVA);
  340.         assert (history[5] == ZURICH);
  341.         assert (history[6] == STRASBOURG);
  342.         assert (history[7] == UNKNOWN_LOCATION);
  343.  
  344.         getHistory (gv, PLAYER_DR_SEWARD, history);
  345.         assert (history[0] == TOULOUSE);
  346.         assert (history[1] == TOULOUSE);
  347.         assert (history[2] == MARSEILLES);
  348.         assert (history[3] == GENEVA);
  349.         assert (history[4] == GENEVA);
  350.         assert (history[5] == ZURICH);
  351.         assert (history[6] == STRASBOURG);
  352.         assert (history[7] == UNKNOWN_LOCATION);
  353.  
  354.         getHistory (gv, PLAYER_VAN_HELSING, history);
  355.         assert (history[0] == SARAGOSSA);
  356.         assert (history[1] == TOULOUSE);
  357.         assert (history[2] == MARSEILLES);
  358.         assert (history[3] == MARSEILLES);
  359.         assert (history[4] == ZURICH);
  360.         assert (history[5] == ZURICH);
  361.         assert (history[6] == GENEVA);
  362.         assert (history[7] == UNKNOWN_LOCATION);
  363.  
  364.         getHistory (gv, PLAYER_MINA_HARKER, history);
  365.         assert (history[0] == SARAGOSSA);
  366.         assert (history[1] == TOULOUSE);
  367.         assert (history[2] == MARSEILLES);
  368.         assert (history[3] == MARSEILLES);
  369.         assert (history[4] == ZURICH);
  370.         assert (history[5] == ZURICH);
  371.         assert (history[6] == GENEVA);
  372.         assert (history[7] == UNKNOWN_LOCATION);
  373.         puts ("passed");
  374.         disposeGameView (gv);
  375.     } while (0);
  376.  
  377.     do {////////////////////////////////////////////////////////////////
  378.         puts ("Test for connections (EXTRAS)");
  379.         char *trail = "";
  380.         PlayerMessage messages[] = {};
  381.         GameView gv = newGameView (trail, messages);
  382.  
  383.         do {
  384.             puts ("Checking Cologne rail connections");
  385.             int size, *edges = connectedLocations (gv, &size,
  386.                 COLOGNE, PLAYER_LORD_GODALMING, 0, false, true, false);
  387.  
  388.             bool seen[NUM_MAP_LOCATIONS] = {false};
  389.             for (int i = 0; i < size; i++)
  390.                 seen[edges[i]] = true;
  391.  
  392.             assert (size == 3);
  393.             assert (seen[COLOGNE]);
  394.             assert (seen[BRUSSELS]);
  395.             assert (seen[FRANKFURT]);
  396.  
  397.             free (edges);
  398.         } while (0);
  399.  
  400.         do {
  401.             puts ("Checking Ionian Sea rail connections");
  402.             int size, *edges = connectedLocations (gv, &size,
  403.                 IONIAN_SEA, PLAYER_LORD_GODALMING, 0,
  404.                 false, true, false);
  405.  
  406.             assert (size == 1);
  407.             assert (edges[0] == IONIAN_SEA);
  408.  
  409.             free (edges);
  410.         } while (0);
  411.  
  412.         do {
  413.             puts ("Checking Madrid sea connections");
  414.             int size, *edges = connectedLocations (gv, &size,
  415.                 MADRID, PLAYER_LORD_GODALMING, 0,
  416.                 false, false, true);
  417.  
  418.             assert (size == 1);
  419.             assert (edges[0] == MADRID);
  420.  
  421.             free (edges);
  422.         } while (0);
  423.  
  424.         do {
  425.             puts ("Checking Cagliari sea connections");
  426.             int size, *edges = connectedLocations (gv, &size,
  427.                 CAGLIARI, PLAYER_LORD_GODALMING, 0,
  428.                 false, false, true);
  429.  
  430.             assert (size == 1);
  431.             assert (edges[0] == CAGLIARI);
  432.  
  433.             free (edges);
  434.         } while (0);
  435.  
  436.         puts ("passed");
  437.         disposeGameView (gv);
  438.     } while (0);
  439.  
  440.     return EXIT_SUCCESS;
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement