@Garniturek żebyś nie musiał błądzić w ciemności, przygotowałem dla Ciebie drobne środowisko uruchomieniowe dla twoich programów;
Tutaj przykład z moim:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <cstdlib>
#include <string>
#include <initializer_list>
using namespace std;
namespace program{
void main(istream &cin, ostream &cout){
vector<int> vec;
copy(istream_iterator<int>(cin),
istream_iterator<int>(),
back_inserter(vec));
for(auto it = rbegin(vec); it != rend(vec); ++it){
cout << (*it) << " ";
}
}
}
template<typename T>
void test_program_with(const T &sequence){
using input_el_t = typename T::value_type;
stringstream input, output;
auto convert_to_input = [](auto &cont){
ostringstream result;
copy(begin(cont), end(cont), ostream_iterator<input_el_t>(result, " "));
return result.str();
};
auto run_program = [&]{
program::main(input, output);
};
auto pass_test = [](){
cout << "Passed." << endl;
};
auto fail_test_wrong_value = [](auto x, auto y){
cout << "Failed with x != y, where x=" << x << ", y=" << y << endl;
exit(-1);
};
auto fail_test_different_sizes = [](auto expected, auto result){
cout << "Failed with different sizes; expected size=" << expected << ", result size=" << result << endl;
exit(-2);
};
auto dump_container = [](const auto &container){
cout << "{ "; for(auto x : container) cout << x << " "; cout << "}\n";
};
input << convert_to_input(sequence);
run_program();
vector<string> expected;
transform(begin(sequence), end(sequence), back_inserter(expected), [](auto val){ return to_string(val); });
reverse(begin(expected), end(expected));
vector<string> result{istream_iterator<string>(output), istream_iterator<string>()};
dump_container(expected);
dump_container(result);
if(expected.size() != result.size())
fail_test_different_sizes(result.size(), result.size());
for(size_t i = 0; i < result.size(); ++i){
if(expected[i] != result[i])
fail_test_wrong_value(expected[i], result[i]);
}
pass_test();
}
int main() {
using seq = vector<int>;
test_program_with(seq{1, 2, 3});
test_program_with(seq{-13, -23, 33});
test_program_with(seq{});
}
stdout
{ 3 2 1 }
{ 3 2 1 }
Passed.
{ 33 -23 -13 }
{ 33 -23 -13 }
Passed.
{ }
{ }
Passed.
Link: http://melpon.org/wandbox/permlink/5x9nyThT7GOh6ilR
Jedyne co musisz zrobić, to wrzucić flaki swojego programu do program::main
Powodzenia.
{ 3 2 1 }
{ 3 2 1 }
Passed.
{ 33 -23 -13 }
{ 33 32- 31- }
Failed with x != y, where x=-23, y=32-
Natomiast twój drugi przechodzi ;) Zarówno mój test, jak i na spoju. Jednakże jest to bardzo brzydkie rozwiązanie.