Пример #1
0
  static void opsTest(){
    Hand h = Hand();
    ostringstream oss;

    int num;
    try {
      h += (num = 3);
      h += (num = 4);
      h += (num = 5);
      h += (num = 6);
      h += (num = 7);
      h += (num = 1);
    }catch(std::logic_error & e){
      oss << e.what();	
    }
    assert(oss.str() == "Shouldn't draw more than five cards!\n");
    oss.str("");
    oss.clear();
    
    assert(h.getSize() == 5);

    Hand h2 = Hand();
    h2 += 3;
    h2 += 4;
    vector<int> list = {1,2,3,4};

    try {
      h2 += list;
    }
    catch(std::logic_error & e){
      oss << e.what();
    }
    assert(oss.str() == "Shouldn't draw more than five cards!\n");
  }
Пример #2
0
  static void moveTest(){
    //declare new empty Hand and a Draw pile
    Hand h = Hand();
    Draw d = Draw();
    ostringstream oss;

    //try drawing more than 5 cards to Hand
    //exception should be caught before assert(false)
    try {
      d.move(h,6);
      assert(false);
    }
    catch(std::invalid_argument & e){
      oss << e.what();
    }

    //assert exception is caught and clear buffer
    assert(oss.str() == "Shouldn't draw more than five cards!\n");
    oss.str("");
    oss.clear();

    //move 5 cards from Draw pile to Hand
    d.move(h,5);
    
    //assert Hand now has 5 cards
    assert(h.getSize() == 5);
    
    //since we are taking from the topmost, unshuffled draw pile, the
    //five cards taken should be wild Skip-Bo Cards
    vector<int>::const_iterator it;
    for(it = (h.cards).begin(); it < (h.cards).end(); it++){
      assert(*it == 0);
    }

    //assert that the size of the Draw pile is decreased by 5
    assert(d.getSize() == 162 - 5);

    //assert that the rest of the draw pile is of the values expected
    int i;
    for(it = (d.cards).begin(), i=0; it < (d.cards).begin() + 144; it++, i++){
      assert(*it == i % 12 + 1);
    }
    for(it = (d.cards).begin() + 144; it < (d.cards).end(); it++){
      assert(*it == 0);
    }
    

    //try drawing more cards to the full Hand
    try {
      d.move(h,1);
      assert(false);
    }
    catch (std::logic_error & e){
      oss << e.what();
    }

    //assert exception is caught
    assert(oss.str() == "Shouldn't draw more than five cards!\n");
  }
Пример #3
0
  static void moveTest(){
    //initialize all variables
    ostringstream oss;
    Discard discard = Discard();
    Build build = Build();
    Hand hand = Hand();
    vector<int> value = {5, 0, 3, 2, 4};
    int index;

    //add the values to hand
    hand += value;
    
    //assert that hand successfully moves cards to build correctly
    hand.move(build, index = 1);
    assert(hand.getSize() == 4);
    assert(build.getSize() == 1);
    assert(build.getTop() == 0);
    
    //try moving cards from hand to discard
    try {
      //assert that the cards are moved correctly
      hand.move(discard, index = 3);
      assert(hand.getSize() == 3);
      assert(discard.getSize() == 1);

      //assert that an exception is thrown, so that assert(false) will
      //not be executed
      hand.move(discard, index = 6);
      assert(false);
    }
    //should catch invalid_argument, not logic_error
    catch(std::invalid_argument & e){
      oss << "Failed after trying to take a card of index " << index << "!"; 
    }
    catch(std::logic_error & e){
      oss << "I shouldn't be thrown!";
    }

    //assert that the code inside the catch block is executed
    assert(oss.str() == "Failed after trying to take a card of index 6!");
  }
Пример #4
0
 static void constructorTest(){
   Hand h = Hand();
   assert(h.getSize() == 0);
 }