Guest User

Untitled

a guest
Jul 15th, 2013
282
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <gtest/gtest.h>
  2. #include <vector>
  3.  
  4.  
  5.  
  6. void Function (std::vector <int>& v)
  7. {
  8.     for (auto x = v.begin (); x != v.end (); ++x) {
  9.         if ( (* x) == 42) {
  10.             v.erase (x);
  11.         }
  12.     }
  13. }
  14.  
  15.  
  16. class FunctionTest : public ::testing::Test
  17. {
  18.     protected:
  19.         virtual void SetUp    () {};
  20.         virtual void TearDown () {};
  21. };
  22.  
  23.  
  24.  
  25. TEST_F (FunctionTest, EmptyVectorProcessedSuccess)
  26. {
  27.     // Arrange.
  28.     std::vector <int> testVector   {};
  29.  
  30.     // Act.
  31.     Function (testVector);
  32.  
  33.     // Assert.
  34.     EXPECT_EQ (testVector.size (), 0);
  35. }
  36.  
  37.  
  38.  
  39. TEST_F (FunctionTest, NotEmptyVectorProcessedWithRemovingSuccess)
  40. {
  41.     // Arrange.
  42.     std::vector <int> etalonVector {1, 3};
  43.     std::vector <int> testVector   {1, 42, 3};
  44.  
  45.     // Act.
  46.     Function (testVector);
  47.  
  48.     // Assert.
  49.     ASSERT_EQ (etalonVector.size (), testVector.size () );
  50.     for (int i = 0; i < etalonVector.size (); ++i) {
  51.         EXPECT_EQ (etalonVector [i], testVector [i]);
  52.     }
  53. }
  54.  
  55.  
  56.  
  57. TEST_F (FunctionTest, NotEmptyVectorProcessedWithoutRemovingSuccess)
  58. {
  59.     // Arrange.
  60.     std::vector <int> etalonVector {1, 2, 3};
  61.     std::vector <int> testVector   {1, 2, 3};
  62.  
  63.     // Act.
  64.     Function (testVector);
  65.  
  66.     // Assert.
  67.     ASSERT_EQ (etalonVector.size (), testVector.size () );
  68.     for (int i = 0; i < etalonVector.size (); ++i) {
  69.         EXPECT_EQ (etalonVector [i], testVector [i]);
  70.     }
  71. }
RAW Paste Data