|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Objectexample.Counter
public class Counter
Simple example class to show how to use ComTest. Counter is a class that counts sum, min and max of the items added. Only maxN item is taken acount.
private Counter gCnt;
/.** *./
\@Before public void doInit() {
gCnt = new Counter(3);
}
/.** *./
\@After public void doAfter() {
System.out.println("After: " + gCnt.getCount());
}
| Constructor Summary | |
|---|---|
Counter(int maxN)
Init counter with max N items |
|
| Method Summary | |
|---|---|
void |
add(int i)
Adds i to current counter if not allready too many added. |
double |
getAvg()
|
int |
getCount()
|
int |
getMax()
|
int |
getMin()
|
int |
getSum()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Counter(int maxN)
maxN - how many items to count in max| Method Detail |
|---|
public void add(int i)
i - value to add
#THROWS IndexOutOfBoundsException,Exception
// Test by ordinary sentences
// Counter cnt = new Counter(3);
Counter cnt = gCnt;
cnt.getCount() === 0; cnt.getSum() === 0;
cnt.add(1); cnt.getCount() === 1; cnt.getSum() === 1;
cnt.add(2); cnt.getCount() === 2; cnt.getSum() === 3;
,
// test by table
Counter cnt = new Counter(3);
cnt.add($add); cnt.getCount() === $count; cnt.getSum() === $sum;
cnt.getMax() === $max; cnt.getMin() === $min;
----------------------------------------------
$add | $count | $sum | $max | $min
----------------------------------------------
--- | 0 | 0 | 0 | 0 // after creation
1 | 1 | 1 | 1 | 1
2 | 2 | 1+2 | 2 | 1
3 | 3 | 1+2+3 | 3 | 1
4 | 3 | 6 | 3 | 1 // MaxN exceeded
==============================================
5 | 1 | 5 | 5 | 5
2 | 2 | 5+2 | 5 | 2
3 | 3 | 5+2+3 | 5 | 2
==============================================
-1 | 1 | -1 | -1 | -1
2 | 2 | -1+2 | 2 | -1
9 | 3 | -1+2+9 | 9 | -1
public int getCount()
public int getMax()
public int getMin()
public int getSum()
public double getAvg()
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||