gen-array-with-opt.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. vector<int> n_list = rnd.partition(test_count, sum_n, min_n);
  34. println(test_count);
  35. for (int test_case = 0; test_case < test_count; ++test_case) {
  36. int n = n_list[test_case];
  37. vector<int> arr(n);
  38. for (int i = 0; i < n; ++i) {
  39. arr[i] = rnd.wnext(min_value, max_value, value_bias);
  40. }
  41. println(n);
  42. println(arr);
  43. }
  44. }