com.greenpepper.Statistics Maven / Gradle / Ivy
/*
* Copyright (c) 2006 Pyxis Technologies inc.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA,
* or see the FSF site: http://www.fsf.org.
*/
package com.greenpepper;
import java.io.Serializable;
/**
* Statistics class.
*
* @author oaouattara
* @version $Id: $Id
*/
public final class Statistics implements Serializable
{
private static final long serialVersionUID = -1L;
private int rightCount;
private int wrongCount;
private int exceptionCount;
private int ignoredCount;
/**
* Constructor for Statistics.
*/
public Statistics()
{
this( 0, 0, 0, 0 );
}
/**
* Constructor for Statistics.
*
* @param right a int.
* @param wrong a int.
* @param exception a int.
* @param ignored a int.
*/
public Statistics( int right, int wrong, int exception, int ignored )
{
this.rightCount = right;
this.wrongCount = wrong;
this.exceptionCount = exception;
this.ignoredCount = ignored;
}
/**
* exceptionCount.
*
* @return a int.
*/
public int exceptionCount()
{
return exceptionCount;
}
/**
* wrongCount.
*
* @return a int.
*/
public int wrongCount()
{
return wrongCount;
}
/**
* ignoredCount.
*
* @return a int.
*/
public int ignoredCount()
{
return ignoredCount;
}
/**
* rightCount.
*
* @return a int.
*/
public int rightCount()
{
return rightCount;
}
/**
* tally.
*
* @param other a {@link com.greenpepper.Statistics} object.
*/
public void tally( Statistics other )
{
rightCount += other.rightCount();
wrongCount += other.wrongCount();
ignoredCount += other.ignoredCount();
exceptionCount += other.exceptionCount();
}
/**
* indicatesFailure.
*
* @return a boolean.
*/
public boolean indicatesFailure()
{
return wrongCount > 0 || exceptionCount > 0;
}
/**
* totalCount.
*
* @return a int.
*/
public int totalCount()
{
return rightCount() + wrongCount() + exceptionCount() + ignoredCount();
}
/**
* toString.
*
* @return a {@link java.lang.String} object.
*/
public String toString()
{
return String.format( "%d tests: %d right, %d wrong, %d ignored, %d exception(s)",
totalCount(), rightCount(), wrongCount(), ignoredCount(), exceptionCount() );
}
/**
* right.
*/
public void right()
{
rightCount++;
}
/**
* wrong.
*/
public void wrong()
{
wrongCount++;
}
/**
* exception.
*/
public void exception()
{
exceptionCount++;
}
/**
* ignored.
*/
public void ignored()
{
ignoredCount++;
}
/**
* hasFailed.
*
* @return a boolean.
*/
public boolean hasFailed()
{
return wrongCount() > 0 || exceptionCount() > 0;
}
/** {@inheritDoc} */
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (!(o instanceof Statistics)) return false;
Statistics that = (Statistics) o;
return exceptionCount == that.exceptionCount
&& ignoredCount == that.ignoredCount
&& rightCount == that.rightCount
&& wrongCount == that.wrongCount;
}
/** {@inheritDoc} */
@Override
public int hashCode()
{
int result;
result = rightCount;
result = 31 * result + wrongCount;
result = 31 * result + exceptionCount;
result = 31 * result + ignoredCount;
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy