142 lines
2.8 KiB
C++
142 lines
2.8 KiB
C++
#include "testlib.h"
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
const int MIN_N = 1;
|
|
const int MAX_N = 1e3;
|
|
const int MIN_NI = 1;
|
|
const int MAX_NI = 1e4;
|
|
|
|
const int rnd_test_n = 40;
|
|
|
|
template <typename T>
|
|
void append(vector<T> &dest, const vector<T> &orig)
|
|
{
|
|
dest.insert(dest.end(), orig.begin(), orig.end());
|
|
}
|
|
|
|
string output_tc(const vector<int> &nums)
|
|
{
|
|
ostringstream oss;
|
|
oss << nums.size() << endl;
|
|
for (int i = 0; i < nums.size(); i++)
|
|
{
|
|
if (i != 0)
|
|
oss << " ";
|
|
oss << nums[i];
|
|
}
|
|
oss << endl;
|
|
return oss.str();
|
|
}
|
|
|
|
vector<string> generate_sample_tests()
|
|
{
|
|
vector<string> tests;
|
|
tests.push_back(output_tc({1, 5, 8, 9, 10, 17, 17, 20}));
|
|
tests.push_back(output_tc({1, 2, 3, 5}));
|
|
tests.push_back(output_tc({3, 5, 8, 9, 10, 17, 17, 20}));
|
|
return tests;
|
|
}
|
|
|
|
vector<string> generate_manual_tests()
|
|
{
|
|
vector<string> tests;
|
|
tests.push_back(output_tc({MIN_NI, MIN_NI, MIN_NI, MIN_NI}));
|
|
return tests;
|
|
}
|
|
|
|
string rnd_test(int i)
|
|
{
|
|
int min_n = MIN_N;
|
|
int max_n = MAX_N;
|
|
|
|
if (i < rnd_test_n / 3)
|
|
{
|
|
max_n = MAX_N / 3;
|
|
}
|
|
else if (i < rnd_test_n / 2)
|
|
{
|
|
max_n = MAX_N / 2;
|
|
}
|
|
|
|
int n = rnd.next(min_n, max_n);
|
|
vector<int> nums(n);
|
|
|
|
nums[0] = 10;
|
|
for (int j = 1; j < n; j++)
|
|
{
|
|
int length = j + 1;
|
|
|
|
int choice = rnd.next(0, 100);
|
|
|
|
if (choice < 20) {
|
|
nums[j] = nums[j-1] + rnd.next(1, nums[0] - 1);
|
|
}
|
|
else if (choice < 80) {
|
|
int offset = rnd.next(-2, 3);
|
|
nums[j] = nums[j-1] + nums[0];
|
|
}
|
|
else {
|
|
nums[j] = nums[j-1] + nums[0] + rnd.next(5, 15);
|
|
}
|
|
|
|
nums[j] = min(nums[j], MAX_NI);
|
|
}
|
|
return (output_tc(nums));
|
|
}
|
|
|
|
vector<string> generate_random_tests()
|
|
{
|
|
vector<string> tests;
|
|
for (int i = 0; i < rnd_test_n; i++)
|
|
{
|
|
tests.push_back(rnd_test(i));
|
|
}
|
|
return tests;
|
|
}
|
|
|
|
string extreme_test_1()
|
|
{
|
|
vector<int> nums(MAX_N);
|
|
for (int i = 0; i < MAX_N; i++)
|
|
{
|
|
nums[i] = MIN_NI;
|
|
}
|
|
return (output_tc(nums));
|
|
}
|
|
|
|
string extreme_test_2()
|
|
{
|
|
vector<int> nums(MAX_N);
|
|
for (int i = 0; i < MAX_N; i++)
|
|
{
|
|
nums[i] = MAX_NI;
|
|
}
|
|
return (output_tc(nums));
|
|
}
|
|
|
|
vector<string> generate_extreme_tests()
|
|
{
|
|
vector<string> tests;
|
|
tests.push_back(extreme_test_1());
|
|
tests.push_back(extreme_test_2());
|
|
return tests;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
registerGen(argc, argv, 1);
|
|
vector<string> tests;
|
|
size_t test = 0;
|
|
append(tests, generate_sample_tests());
|
|
append(tests, generate_manual_tests());
|
|
append(tests, generate_random_tests());
|
|
append(tests, generate_extreme_tests());
|
|
for (const auto &t : tests)
|
|
{
|
|
startTest(++test);
|
|
cout << t;
|
|
}
|
|
return 0;
|
|
} |