1 import java
.io
.FileNotFoundException
;
2 import java
.io
.IOException
;
3 import java
.io
.PrintWriter
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Arrays
;
7 import java
.util
.Random
;
10 static final int MAX_N
= 10000;
11 static final int MAX_M
= 10;
12 static final int MAX_W
= 80;
13 static final int MIN_CH
= 32;
14 static final int MAX_CH
= 126;
15 static final Random random
= new Random(7509843543298434535L);
17 static PrintWriter out
;
21 final String description
;
22 List
<List
<String
>> values
= new ArrayList
<List
<String
>>();
24 public doall(String description
) {
25 this.description
= description
;
31 System
.out
.println("Writing test " + test
+ " (" + description
+ ")");
32 out
.format("%02d %s\n", test
, description
);
33 assert 0 <= values
.size() && values
.size() <= MAX_N
;
35 int m
= values
.get(0).size();
36 for (List
<String
> row
: values
) {
37 assert row
.size() == m
;
38 for (String value
: row
) {
39 assert value
.indexOf(',') == -1;
40 for (char ch
: value
.toCharArray()) {
41 assert MIN_CH
<= ch
&& ch
<= MAX_CH
;
47 PrintWriter out
= new PrintWriter(String
.format("%02d", test
));
48 out
.println(values
.size() + " " + m
);
49 for (List
<String
> row
: values
) {
51 for (String value
: row
) {
62 } catch (IOException e
){
67 private doall
hand(String
... lines
) {
68 for (String line
: lines
) {
69 values
.add(Arrays
.asList(line
.split(",")));
74 private int random(int max
) {
75 return random
.nextInt(max
);
78 private int random(int min
, int max
) {
79 return min
+ random(max
- min
);
82 private int random(int min
, int max
, int except
) {
83 int value
= random(min
, max
);
84 return value
== except ?
random(min
, max
, except
) : value
;
87 private char randomChar(int min
, int max
) {
88 return (char) random(min
, max
, ',');
91 private String
randomValue(int w
) {
92 return randomValue(w
, MAX_CH
);
95 private String
randomValue(int w
, int maxChar
) {
96 StringBuilder sb
= new StringBuilder();
97 sb
.append(randomChar(MIN_CH
+ 1, maxChar
+ 1));
98 for (int i
= 0; i
< w
- 2; i
++) {
99 sb
.append(randomChar(MIN_CH
, maxChar
+ 1));
102 sb
.append(randomChar(MIN_CH
+ 1, maxChar
+ 1));
104 return sb
.toString();
107 private String
randomValue(String prefix
, int w
) {
110 return randomValue(w
);
112 return prefix
.substring(0, w
- tail
) + randomValue(tail
);
115 private List
<String
> randomLine(int m
, int width
, int maxChar
) {
116 int[] widths
= new int[m
];
117 for (int i
= 0; i
< width
- 2 * m
+ 1; i
++) {
120 List
<String
> result
= new ArrayList
<String
>();
121 for (int w
: widths
) {
122 result
.add(randomValue(w
+ 1, maxChar
));
127 private List
<String
> randomLine(String prefix
, int m
, int width
) {
128 int[] widths
= new int[m
];
129 for (int i
= 0; i
< width
- 2 * m
+ 1; i
++) {
132 List
<String
> result
= new ArrayList
<String
>();
133 for (int w
: widths
) {
134 result
.add(randomValue(prefix
, w
+ 1));
139 private doall
randomLines(int n
, int m
, int width
, int deltaWidth
, int maxChar
) {
140 for (int i
= 0; i
< n
; i
++) {
141 values
.add(randomLine(m
, width
- random(deltaWidth
+ 1), maxChar
));
146 private doall
randomLines(int n
, int m
, int width
, int deltaWidth
) {
147 return randomLines(n
, m
, width
, deltaWidth
, MAX_CH
);
150 private doall
randomLines(int n
, int m
, int width
) {
151 return randomLines(n
, m
, width
, 0);
154 private doall
randomLinesPrefix(int n
, int m
, int width
, int deltaWidth
) {
155 String prefix
= randomValue(width
);
156 for (int i
= 0; i
< n
; i
++) {
157 values
.add(randomLine(prefix
, m
, width
- random(deltaWidth
+ 1)));
162 private doall
randomLinesPrefix(int n
, int m
, int width
) {
163 return randomLinesPrefix(n
, m
, width
, 0);
166 private void makeEqual(int r1
, int r2
, int c
) {
167 List
<String
> row1
= values
.get(r1
);
168 List
<String
> row2
= values
.get(r2
);
169 String value1
= row1
.get(c
);
170 String value2
= row2
.get(c
);
171 if (value1
.length() < value2
.length()) {
178 private doall
hack() {
179 int r1
= random(values
.size());
180 int r2
= random(0, values
.size(), r1
);
181 int c1
= random(values
.get(0).size());
182 int c2
= random(0, values
.get(0).size(), c1
);
183 makeEqual(r1
, r2
, c1
);
184 makeEqual(r1
, r2
, c2
);
188 private doall
hack(int n
) {
189 for (int i
= 0; i
< n
; i
++) {
195 public static void main(String
[] args
) throws FileNotFoundException
{
196 out
= new PrintWriter("tests.lst");
198 new doall("Example test 1").hand(
199 "How to compete in ACM ICPC,Peter,peter@neerc.ifmo.ru",
200 "How to win ACM ICPC,Michael,michael@neerc.ifmo.ru",
201 "Notes from ACM ICPC champion,Michael,michael@neerc.ifmo.ru"
203 new doall("Example test 2").hand(
204 "1,Peter,peter@neerc.ifmo.ru",
205 "2,Michael,michael@neerc.ifmo.ru"
207 new doall("Manual test for concatenation without comma").hand(
211 new doall("3 rows, 5 columns").randomLines(3, 5, 10).write();
212 new doall("5 rows, 3 columns, NO").randomLines(5, 3, 10).hack().write();
213 new doall("Random test for concatenation without comma").randomLines(10, 3, 10, 3, 2 + MIN_CH
).write();
214 new doall("1 row, 1 column").randomLines(1, 1, 1).write();
215 new doall("1 row, 2 columns").randomLines(1, 2, 10, 3).write();
216 new doall("2 rows, 1 column").randomLines(2, 1, 10, 3).write();
217 new doall("2 rows, 2 columns, YES").randomLines(2, 2, 10, 3).write();
218 new doall("2 rows, 2 columns, NO").randomLines(2, 2, 10, 3).hack().write();
220 new doall("10 rows, 2 columns, NO").randomLines(3, 5, 10).hack().write();
221 new doall("10 rows, 9 columns, NO").randomLines(3, 5, 10).hack().write();
223 new doall("47 rows, 9 columns, NO").randomLines(1000, 9, MAX_W
).hack().write();
224 new doall("100 rows, 9 columns, NO").randomLines(1000, 9, MAX_W
).hack().write();
225 new doall("637 rows, 8 columns, NO").randomLines(1000, 8, MAX_W
).hack().write();
226 new doall("1024 rows, 10 columns, YES").randomLines(1000, 10, MAX_W
).hack().write();
227 new doall("5073 rows, 10 columns, NO").randomLines(1000, 10, MAX_W
).hack().write();
229 new doall("max all, common prefix, NO").randomLinesPrefix(MAX_N
, MAX_M
, MAX_W
).hack().write();
230 new doall("max all, common prefix, YES").randomLinesPrefix(MAX_N
, MAX_M
, MAX_W
).write();
232 new doall("almost max rows, almost max columns, almost max width, common prefix, massive NO").randomLinesPrefix(MAX_N
- 3, MAX_M
- 1, MAX_W
, 10).hack(MAX_N
* MAX_M
).write();
233 new doall("almost max rows, almost max columns, almost max width, common prefix, NO").randomLinesPrefix(MAX_N
- 3, MAX_M
- 1, MAX_W
, 10).hack().write();
234 new doall("almost max rows, max columns, almost max width, common prefix, YES").randomLinesPrefix(MAX_N
- 5, MAX_M
, MAX_W
, 10).write();
236 random
.setSeed(75098435432984345L);
237 new doall("Large test for concatenation without comma").randomLines(MAX_N
, MAX_M
, MAX_W
, 3, 6 + MIN_CH
).write();
239 new doall("max all, NO").randomLines(MAX_N
, MAX_M
, MAX_W
).hack().write();
240 random
.setSeed(7509843543298434435L);
241 new doall("max all, YES").randomLines(MAX_N
, MAX_M
, MAX_W
).write();
242 new doall("max all, common prefix, NO").randomLinesPrefix(MAX_N
, MAX_M
, MAX_W
).hack().write();
243 new doall("max all, common prefix, YES").randomLinesPrefix(MAX_N
, MAX_M
, MAX_W
).write();