Skip to content

Instantly share code, notes, and snippets.

@shelajev
Created August 28, 2019 12:36
Show Gist options
  • Save shelajev/fb6a5fc1f4ee3df49a81ec0dce24c4d7 to your computer and use it in GitHub Desktop.
Save shelajev/fb6a5fc1f4ee3df49a81ec0dce24c4d7 to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws Exception {
int cnt = Integer.parseInt(args[0]);
long seed = Long.parseLong(args[1]);
int repeat = Integer.parseInt(args[2]);
Shape[] samples = generate(3, args, cnt, seed);
double expected = computeArea(samples);
long prev = System.currentTimeMillis();
for (int i = 0; i < repeat * 1000; i++) {
double sum = computeArea(samples);
if (sum  != expected) {
throw new IllegalStateException();
}
if (i % 1000 == 0) {
prev = System.currentTimeMillis();
}
}
System.err.println("last round " + (System.currentTimeMillis() - prev) + " ms.");
}
static Shape[] generate(int offset, String[] types, int count, long seed) {
java.util.Random r = new java.util.Random(seed);
Shape[] arr = new Shape[count];
for (int i = 0; i < arr.length; i++) {
String t = types[offset + i % (types.length - offset)];
Shape s;
switch (t) {
case "circle":
s = Shape.cicle(r.nextDouble());
break;
case "rectangle":
s = Shape.rectangle(r.nextDouble(), r.nextDouble());
break;
case "square":
s = Shape.square(r.nextDouble());
break;
case "triangle":
s = Shape.triangle(r.nextDouble(), r.nextDouble());
break;
default:
throw new IllegalStateException("" + t);
}
arr[i] = s;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment