Advertisement
zynamo

Untitled

Jan 20th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.90 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // COMP2521 18x1 ... the Fury of Dracula
  3. // testHunterView.c: test the HunterView 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-02   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 "HunterView.h"
  18.  
  19. int
  20. main (int argc, char *argv[])
  21. {
  22.     do {////////////////////////////////////////////////////////////////
  23.         puts ("Test basic empty initialisation");
  24.         char *trail = "";
  25.         PlayerMessage messages[] = {};
  26.         HunterView hv = newHunterView (trail, messages);
  27.  
  28.         assert (whoAmI (hv) == PLAYER_LORD_GODALMING);
  29.         assert (giveMeTheRound (hv) == 0);
  30.         assert (howHealthyIs (hv, PLAYER_DR_SEWARD) ==
  31.                 GAME_START_HUNTER_LIFE_POINTS);
  32.         assert (howHealthyIs (hv, PLAYER_DRACULA) ==
  33.                 GAME_START_BLOOD_POINTS);
  34.         assert (giveMeTheScore (hv) == GAME_START_SCORE);
  35.         assert (whereIs (hv, PLAYER_LORD_GODALMING) ==
  36.                 UNKNOWN_LOCATION);
  37.  
  38.         puts ("passed");
  39.         disposeHunterView (hv);
  40.     } while (0);
  41.  
  42.  
  43.     do {////////////////////////////////////////////////////////////////
  44.         puts ("Test for Dracula trail and basic functions");
  45.  
  46.         char *trail =
  47.             "GST.... SAO.... HZU.... MBB.... DC?....";
  48.         PlayerMessage messages[] = {
  49.             "Hello", "Rubbish", "Stuff", "", "Mwahahah" };
  50.         HunterView hv = newHunterView (trail, messages);
  51.  
  52.         assert (whoAmI (hv) == PLAYER_LORD_GODALMING);
  53.         assert (giveMeTheRound (hv) == 1);
  54.         assert (whereIs (hv, PLAYER_LORD_GODALMING) == STRASBOURG);
  55.         assert (whereIs (hv, PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
  56.         assert (whereIs (hv, PLAYER_VAN_HELSING) == ZURICH);
  57.         assert (whereIs (hv, PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
  58.         assert (whereIs (hv, PLAYER_DRACULA) == CITY_UNKNOWN);
  59.         assert (howHealthyIs (hv, PLAYER_DRACULA) ==
  60.                 GAME_START_BLOOD_POINTS);
  61.  
  62.         puts ("passed");
  63.         disposeHunterView (hv);
  64.     } while (0);
  65.  
  66.  
  67.     do {////////////////////////////////////////////////////////////////
  68.         puts ("Test for encountering Dracula and hunter history");
  69.         char *trail =
  70.             "GST.... SAO.... HCD.... MAO.... DGE.... "
  71.             "GGED...";
  72.         PlayerMessage messages[] = {
  73.             "Hello", "Rubbish", "Stuff", "", "Mwahahah",
  74.             "Aha!" };
  75.         HunterView hv = newHunterView (trail, messages);
  76.  
  77.         assert (whereIs (hv, PLAYER_DRACULA) == GENEVA);
  78.         assert (howHealthyIs (hv, PLAYER_LORD_GODALMING) == 5);
  79.         assert (howHealthyIs (hv, PLAYER_DRACULA) == 30);
  80.         assert (whereIs (hv, PLAYER_LORD_GODALMING) == GENEVA);
  81.  
  82.         LocationID history[TRAIL_SIZE];
  83.         giveMeTheTrail (hv, PLAYER_DRACULA, history);
  84.         /*assert (history[0] == GENEVA);
  85.         assert (history[1] == UNKNOWN_LOCATION);
  86.  
  87.         giveMeTheTrail (hv, PLAYER_LORD_GODALMING, history);
  88.         assert (history[0] == GENEVA);
  89.         assert (history[1] == STRASBOURG);
  90.         assert (history[2] == UNKNOWN_LOCATION);
  91.  
  92.         giveMeTheTrail (hv, PLAYER_DR_SEWARD, history);
  93.         assert (history[0] == ATLANTIC_OCEAN);
  94.         assert (history[1] == UNKNOWN_LOCATION);*/
  95.  
  96.         puts ("passed");
  97.         disposeHunterView (hv);
  98.     } while (0);
  99.  
  100.  
  101.     do {////////////////////////////////////////////////////////////////
  102.         puts ("Test for Dracula doubling back at sea, "
  103.               "and losing blood points (Hunter View)");
  104.         char *trail =
  105.             "GGE.... SGE.... HGE.... MGE.... DS?.... "
  106.             "GST.... SST.... HST.... MST.... DD1....";
  107.         PlayerMessage messages[] = {
  108.             "Hello", "Rubbish", "Stuff", "", "Mwahahah",
  109.             "Aha!", "", "", "", "Back I go" };
  110.         HunterView hv = newHunterView (trail, messages);
  111.  
  112.         assert (whoAmI (hv) == 0);
  113.         assert (whereIs (hv, PLAYER_DRACULA) == DOUBLE_BACK_1);
  114.         assert (howHealthyIs (hv, PLAYER_DRACULA) ==
  115.                 GAME_START_BLOOD_POINTS - 4);
  116.  
  117.         LocationID history[TRAIL_SIZE];
  118.         giveMeTheTrail (hv, PLAYER_DRACULA, history);
  119.         /*assert (history[0] == DOUBLE_BACK_1);
  120.         assert (history[1] == SEA_UNKNOWN);*/
  121.  
  122.         puts ("passed");
  123.         disposeHunterView (hv);
  124.     } while (0);
  125.  
  126.  
  127.     do {////////////////////////////////////////////////////////////////
  128.         puts ("Checking Galatz road connections");
  129.         char *trail = "GGA....";
  130.         PlayerMessage messages[] = {"Gone to Galatz"};
  131.         HunterView hv = newHunterView (trail, messages);
  132.  
  133.         int size, *edges = whereCanTheyGo (
  134.             hv, &size, PLAYER_LORD_GODALMING, true, false, false);
  135.         bool seen[NUM_MAP_LOCATIONS] = {false};
  136.         for (int i = 0; i < size; i++)
  137.             seen[edges[i]] = true;
  138.         printf("%d is size\n", size);
  139.         assert (size == 5);
  140.         assert (seen[GALATZ]);
  141.         assert (seen[CONSTANTA]);
  142.         assert (seen[BUCHAREST]);
  143.         assert (seen[KLAUSENBURG]);
  144.         assert (seen[CASTLE_DRACULA]);
  145.  
  146.         puts ("passed");
  147.         free (edges);
  148.         disposeHunterView (hv);
  149.     } while (0);
  150.  
  151.  
  152.     do {////////////////////////////////////////////////////////////////
  153.         puts ("Checking Ionian Sea sea connections");
  154.         char *trail = "GIO....";
  155.         PlayerMessage messages[] = {"Sailing the Ionian"};
  156.         HunterView hv = newHunterView (trail, messages);
  157.  
  158.         int size, *edges = whereCanTheyGo (
  159.             hv, &size, PLAYER_LORD_GODALMING, false, false, true);
  160.         bool seen[NUM_MAP_LOCATIONS] = {false};
  161.         for (int i = 0; i < size; i++)
  162.             seen[edges[i]] = true;
  163.  
  164.         assert (size == 7);
  165.         assert (seen[IONIAN_SEA]);
  166.         assert (seen[BLACK_SEA]);
  167.         assert (seen[ADRIATIC_SEA]);
  168.         assert (seen[TYRRHENIAN_SEA]);
  169.         assert (seen[ATHENS]);
  170.         assert (seen[VALONA]);
  171.         assert (seen[SALONICA]);
  172.  
  173.         puts ("passed");
  174.         free (edges);
  175.         disposeHunterView (hv);
  176.     } while (0);
  177.  
  178.  
  179.     do {////////////////////////////////////////////////////////////////
  180.         puts ("Checking Athens rail connections (none)");
  181.  
  182.         char *trail = "GAT....";
  183.         PlayerMessage messages[] = {"Leaving Athens by train"};
  184.         HunterView hv = newHunterView (trail, messages);
  185.  
  186.         int size, *edges = whereCanTheyGo (
  187.             hv, &size, PLAYER_LORD_GODALMING, false, true, false);
  188.  
  189.         assert (size == 1);
  190.         assert (edges[0] == ATHENS);
  191.  
  192.         puts ("passed");
  193.         free (edges);
  194.         disposeHunterView (hv);
  195.     } while (0);
  196.  
  197.     return EXIT_SUCCESS;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement