example
Class Counter

java.lang.Object
  extended by example.Counter

public class Counter
extends java.lang.Object

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.

Author:
vesal
Example:
 private Counter cnt;
 
 /.** *./
 \@Before public void doInit() {
   cnt = new Counter(3);
 } 
 
 /.** *./
 \@After public void doAfter() {
   System.out.println("After: " + cnt.getCount());
 }
 

Field Summary
private  int count
           
private  int max
           
private  int maxN
           
private  int min
           
private  int sum
           
 
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
 

Field Detail

count

private int count

max

private int max

min

private int min

sum

private int sum

maxN

private final int maxN
Constructor Detail

Counter

public Counter(int maxN)
Init counter with max N items

Parameters:
maxN -
Method Detail

add

public void add(int i)
Adds i to current counter if not allready too many added.

Parameters:
i - value to add
Example:
 #THROWS IndexOutOfBoundsException,Exception
 // Test by ordinary sentences 
 // Counter cnt = new Counter(3);
              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
       
 

getCount

public int getCount()
Returns:
count of items

getMax

public int getMax()
Returns:
max item

getMin

public int getMin()
Returns:
min item

getSum

public int getSum()
Returns:
Sum of items

getAvg

public double getAvg()
Returns:
Avg of items