gen-array-with-opt.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * gen-array-with-opt -test-count <num>
  3. * -sum-n <num>
  4. * [-min-n <num>]
  5. * [-min-value <num>] [-max-value <num>]
  6. * [-value-bias <num>]
  7. *
  8. * Generate a test with `test-count` test cases, each test case is an
  9. * array. The sum of lengths of all arrays will equal `sum-n`.
  10. *
  11. * Arguments:
  12. * -test-count: specify the number of test cases. Required.
  13. * -sum-n: specify the sum of array lengths over all test cases. Required.
  14. * -min-n: specify the minimum array length for all test cases. Default: 1.
  15. * -min-value: specify the minimum value for the array element. Default: 1.
  16. * -max-value: specify the maximum value for the array element. Default: 10^9.
  17. * -value-bias: specify the bias for generating the value. The bigger the
  18. * _positive_ value-bias, the closer the element to max-value. The smaller the
  19. * _negative_ value-bias, the closer the element to min-value. See rnd.wnext()
  20. * function. Default: 0 (no bias).
  21. */
  22. #include "testlib.h"
  23. #include <vector>
  24. using namespace std;
  25. int main(int argc, char** argv) {
  26. registerGen(argc, argv, 1);
  27. int test_count = opt<int>("test-count");
  28. int sum_n = opt<int>("sum-n");
  29. int min_n = opt<int>("min-n", 1);
  30. int min_value = opt<int>("min-value", 1);
  31. int max_value = opt<int>("max-value", 1000 * 1000 * 1000);
  32. int value_bias = opt<int>("value-bias", 0);
  33. check_unused_opt();
  34. vector<int> n_list = rnd.partition(test_count, sum_n, min_n);
  35. println(test_count);
  36. for (int test_case = 0; test_case < test_count; ++test_case) {
  37. int n = n_list[test_case];
  38. vector<int> arr(n);
  39. for (int i = 0; i < n; ++i) {
  40. arr[i] = rnd.wnext(min_value, max_value, value_bias);
  41. }
  42. println(n);
  43. println(arr);
  44. }
  45. }