[ create a new paste ] login | about

Link: http://codepad.org/tiRdtlFH    [ raw code | output | fork ]

xtofl - C++, pasted on Nov 4:
#include <vector>
#include <string>
#include <sstream>
#include <cassert>
#include <iostream>
#include <stdexcept>

std::vector<std::string> lines( std::istream& inFile ){
  char pop[20], mut[20];
  std::vector<std::string> ret;
  inFile.getline(pop,20);
  if(!inFile) throw std::runtime_error("reading pop from stream");
  ret.push_back(pop);
  inFile.getline(mut,20);
  if(!inFile) throw std::runtime_error("reading mut from stream");
  ret.push_back(mut);
  return ret;
}

void test(std::string s){
  std::cout << "\nrunning test with :\n" << s << std::endl;
  try {
    std::stringstream ss(s);
    std::vector<std::string> lines_(lines(ss));
    std::cout << ">> " << lines_[0] << std::endl;
    std::cout << ">> " << lines_[1] << std::endl;
    assert( lines_[0] == "a" );
    assert( lines_[1] == "b" );
  } catch (const std::runtime_error& e)
  {
    std::cout << "error: " << e.what();
  }
}

int main(){
  test("a");
  test("a\nb");
  test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbb");
  test("aa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

running test with :
a
error: reading mut from stream
running test with :
a
b
>> a
>> b

running test with :
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbb
error: reading pop from stream
running test with :
aa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
error: reading mut from stream


Create a new paste based on this one


Comments: