waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

AccumulatorTest.cpp (1386B)


      1 #include "gtest/gtest.h"
      2 #include "Accumulator.h"
      3 #include <string>
      4 #include <vector>
      5 #include <fstream>
      6 
      7 using namespace std;
      8 
      9 class AccumulatorTest : public testing::Test
     10 {
     11  protected:
     12     virtual void SetUp();
     13     virtual void TearDown();
     14 
     15     Accumulator * m_accumulator;
     16 
     17 };
     18 
     19 void AccumulatorTest::SetUp()
     20 {
     21   m_accumulator = new Accumulator;
     22 }
     23 
     24 void AccumulatorTest::TearDown()
     25 {
     26   delete m_accumulator;
     27 }
     28 
     29 static void readlines(const char * filename, vector<string> & lines)
     30 {
     31   string datafile("input");
     32   datafile += "/";
     33   datafile += filename;
     34   ifstream infile;
     35   infile.open(datafile.c_str());
     36   if (infile.is_open())
     37   {
     38     char buffer[BUFSIZ];
     39     while (!infile.eof())
     40     {
     41       infile.getline(buffer, BUFSIZ);
     42       lines.push_back(buffer);
     43     }
     44   }
     45 }
     46 
     47 TEST_F(AccumulatorTest, test0)
     48 {
     49   vector<string> lines;
     50   readlines("test0.txt", lines);
     51   size_t expected(2);
     52   ASSERT_EQ(expected, lines.size());
     53   m_accumulator->accumulate(lines[0].c_str());
     54   ASSERT_EQ(10, m_accumulator->total());
     55 
     56 }
     57 
     58 TEST_F(AccumulatorTest, test1)
     59 {
     60   vector<string> lines;
     61   readlines("test1.txt", lines);
     62   size_t expected(6);
     63   ASSERT_EQ(expected, lines.size());
     64   for (vector<string>::const_iterator it(lines.begin());
     65       it != lines.end(); ++it)
     66   {
     67     const string & line(*it);
     68     m_accumulator->accumulate(line.c_str());
     69   }
     70   ASSERT_EQ(1+2+3+4+5, m_accumulator->total());
     71 
     72 }