-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated test to include filled shapes
- Loading branch information
Showing
2 changed files
with
114 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package space.earlygrey.shapedrawer.test; | ||
|
||
import java.text.DecimalFormat; | ||
|
||
public class TestUtils { | ||
|
||
public static class RollingAverage { | ||
|
||
private int size; | ||
private double total = 0d; | ||
private int index = 0; | ||
private double samples[]; | ||
private static final DecimalFormat format = new DecimalFormat("##.##"); | ||
|
||
public RollingAverage(int size) { | ||
this.size = size; | ||
samples = new double[size]; | ||
for (int i = 0; i < size; i++) samples[i] = 0d; | ||
} | ||
|
||
public void add(double x) { | ||
total -= samples[index]; | ||
samples[index] = x; | ||
total += x; | ||
if (++index == size) index = 0; // cheaper than modulus | ||
} | ||
|
||
public double getAverage() { | ||
return total / size; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return format.format(getAverage()); | ||
} | ||
} | ||
} |