2005-03-23 Comwiz

* Phase 1 of the unit test bounty completed. (The router build script was modified not to build the router
 tests because of a broken dependancy on the core tests. This should be fixed in
 phase 3 of the unit test bounty.)
This commit is contained in:
comwiz
2005-06-23 02:11:04 +00:00
committed by zzz
parent adeb09576a
commit 440cf2c983
81 changed files with 3306 additions and 1429 deletions

View File

@@ -0,0 +1,33 @@
package net.i2p.stat;
import java.util.Properties;
import junit.framework.TestCase;
public class RateStatTest extends TestCase {
public void testRateStat() throws Exception{
RateStat rs = new RateStat("moo", "moo moo moo", "cow trueisms", new long[] { 60 * 1000, 60 * 60 * 1000,
24 * 60 * 60 * 1000});
for (int i = 0; i < 50; i++) {
Thread.sleep(20);
rs.addData(i * 100, 20);
}
rs.coalesceStats();
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(2048);
rs.store(baos, "rateStat.test");
byte data[] = baos.toByteArray();
Properties props = new Properties();
props.load(new java.io.ByteArrayInputStream(data));
RateStat loadedRs = new RateStat("moo", "moo moo moo", "cow trueisms", new long[] { 60 * 1000,
60 * 60 * 1000,
24 * 60 * 60 * 1000});
loadedRs.load(props, "rateStat.test", true);
assertEquals(rs, loadedRs);
}
}

View File

@@ -0,0 +1,28 @@
package net.i2p.stat;
import java.util.Properties;
import junit.framework.TestCase;
public class RateTest extends TestCase {
public void testRate() throws Exception{
Rate rate = new Rate(1000);
for (int i = 0; i < 50; i++) {
Thread.sleep(20);
rate.addData(i * 100, 20);
}
rate.coalesce();
StringBuffer buf = new StringBuffer(1024);
rate.store("rate.test", buf);
byte data[] = buf.toString().getBytes();
Properties props = new Properties();
props.load(new java.io.ByteArrayInputStream(data));
Rate r = new Rate(props, "rate.test", true);
assertEquals(r, rate);
}
}

View File

@@ -0,0 +1,27 @@
package net.i2p.stat;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* @author Comwiz
*/
public class StatTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite("net.i2p.stat.StatTestSuite");
suite.addTestSuite(RateStatTest.class);
suite.addTestSuite(RateTest.class);
return suite;
}
}