Unit tests not needing the assertion imports seems like a bad sign. Let's
actually turn these "tests" into tests. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2843 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@link CheapIntMap} class.
|
* Tests the {@link CheapIntMap} class.
|
||||||
@@ -31,34 +32,34 @@ public class CheapIntMapTest
|
|||||||
public void runTest ()
|
public void runTest ()
|
||||||
{
|
{
|
||||||
CheapIntMap map = new CheapIntMap(10);
|
CheapIntMap map = new CheapIntMap(10);
|
||||||
|
|
||||||
for (int ii = 0; ii < 100; ii += 20) {
|
for (int ii = 0; ii < 100; ii += 20) {
|
||||||
map.put(ii, ii);
|
map.put(ii, ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ii = 0; ii < 5; ii++) {
|
for (int ii = 0; ii < 5; ii++) {
|
||||||
map.put(ii, ii);
|
map.put(ii, ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ii = 0; ii < 100; ii++) {
|
for (int ii = 0; ii < 100; ii++) {
|
||||||
Object val = map.get(ii);
|
Object val = map.get(ii);
|
||||||
|
assertTrue(val == null || (ii < 5) || (ii%20 == 0));
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
System.out.println(ii + " => " + val);
|
assertEquals(ii, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ii = 0; ii < 100; ii += 20) {
|
for (int ii = 0; ii < 100; ii += 20) {
|
||||||
System.out.println("Removing " + map.remove(ii));
|
map.remove(ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ii = 10; ii > 0; ii--) {
|
for (int ii = 10; ii > 0; ii--) {
|
||||||
map.put(ii, ii);
|
map.put(ii, ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ii = 0; ii < 100; ii++) {
|
for (int ii = 0; ii < 100; ii++) {
|
||||||
Object val = map.get(ii);
|
Object val = map.get(ii);
|
||||||
|
assertTrue(((ii == 0 || ii > 10) && val == null) ||
|
||||||
|
((ii <= 10) && val != null));
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
System.out.println(ii + " => " + val);
|
assertEquals(ii, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,15 @@
|
|||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@link Config} class.
|
* Tests the {@link Config} class.
|
||||||
@@ -33,33 +38,45 @@ public class ConfigTest
|
|||||||
@Test
|
@Test
|
||||||
public void runTest ()
|
public void runTest ()
|
||||||
{
|
{
|
||||||
PrefsConfig config = new PrefsConfig("util/test");
|
// util/test.properties contains:
|
||||||
|
// prop1 = 25
|
||||||
|
// prop2 = twenty five
|
||||||
|
// prop3 = 9, 8, 7, 6
|
||||||
|
// prop4 = one, two, three,, and a half, four
|
||||||
|
// sub.sub1 = 5
|
||||||
|
// sub.sub2 = whee!
|
||||||
|
|
||||||
System.out.println("prop1: " + config.getValue("prop1", 1));
|
Config config = new Config("util/test");
|
||||||
System.out.println("prop2: " + config.getValue("prop2", "two"));
|
|
||||||
|
|
||||||
int[] ival = new int[] { 1, 2, 3 };
|
assertEquals(25, config.getValue("prop1", 1));
|
||||||
ival = config.getValue("prop3", ival);
|
assertEquals("twenty five", config.getValue("prop2", "two"));
|
||||||
System.out.println("prop3: " + StringUtil.toString(ival));
|
assertArrayEquals(new int[] { 9, 8, 7, 6 }, config.getValue("prop3", (int[])null));
|
||||||
|
assertArrayEquals(new String[] { "one", "two", "three, and a half", "four" },
|
||||||
String[] sval = new String[] { "one", "two", "three" };
|
config.getValue("prop4", (String[])null));
|
||||||
sval = config.getValue("prop4", sval);
|
assertEquals("undefined", config.getValue("prop5", "undefined"));
|
||||||
System.out.println("prop4: " + StringUtil.toString(sval));
|
|
||||||
|
|
||||||
System.out.println("prop5: " + config.getValue("prop5", "undefined"));
|
|
||||||
|
|
||||||
// now set some properties
|
// now set some properties
|
||||||
config.setValue("prop1", 15);
|
PrefsConfig pconfig = new PrefsConfig("util/test");
|
||||||
System.out.println("prop1: " + config.getValue("prop1", 1));
|
pconfig.setValue("prop1", 15);
|
||||||
config.setValue("prop2", "three");
|
assertEquals(15, pconfig.getValue("prop1", 1));
|
||||||
System.out.println("prop2: " + config.getValue("prop2", "two"));
|
pconfig.setValue("prop2", "three");
|
||||||
|
assertEquals("three", pconfig.getValue("prop2", "two"));
|
||||||
|
|
||||||
Iterator<String> iter = config.keys();
|
List<String> list = CollectionUtil.addAll(new ArrayList<String>(), pconfig.keys());
|
||||||
System.out.println("Keys: " + StringUtil.toString(iter));
|
Collections.sort(list);
|
||||||
|
assertEquals("(prop1, prop2, prop3, prop4, sub.sub1, sub.sub2, sub.sub3)",
|
||||||
|
StringUtil.toString(list));
|
||||||
|
|
||||||
config.setValue("sub.sub3", "three");
|
// fiddly with sub-properties
|
||||||
|
pconfig.setValue("sub.sub3", "three");
|
||||||
Properties subprops = config.getSubProperties("sub");
|
Properties subprops = pconfig.getSubProperties("sub");
|
||||||
System.out.println("Sub: " + StringUtil.toString(subprops.propertyNames()));
|
assertEquals("three", subprops.getProperty("sub3"));
|
||||||
|
// oh Java, you're so awesome
|
||||||
|
List<String> slist = new ArrayList<String>();
|
||||||
|
for (Enumeration<?> iter = subprops.propertyNames(); iter.hasMoreElements(); ) {
|
||||||
|
slist.add(iter.nextElement().toString());
|
||||||
|
}
|
||||||
|
Collections.sort(slist);
|
||||||
|
assertEquals("(sub1, sub2, sub3)", StringUtil.toString(slist));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class ConfigUtilTest
|
|||||||
public void runTest ()
|
public void runTest ()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
String path = "util/test.properties";
|
String path = "util/child.properties";
|
||||||
Properties props = ConfigUtil.loadInheritedProperties(path);
|
Properties props = ConfigUtil.loadInheritedProperties(path);
|
||||||
assertTrue("props valid", props.toString().equals(DUMP));
|
assertTrue("props valid", props.toString().equals(DUMP));
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test case for {@link Throttle}.
|
* A test case for {@link Throttle}.
|
||||||
@@ -48,35 +49,35 @@ public class ThrottleTest
|
|||||||
@Test
|
@Test
|
||||||
public void runTest ()
|
public void runTest ()
|
||||||
{
|
{
|
||||||
testUpdate(4);
|
testUpdate(4, "01234", "0012345678", "00123", "39101112", "0000039101112");
|
||||||
testUpdate(5);
|
testUpdate(5, "12345", "12345678910", "12345", "1112131415", "000001112131415");
|
||||||
testUpdate(6);
|
testUpdate(6, "23456", "3456789101112", "34567", "1415161718", "000001415161718");
|
||||||
testUpdate(7);
|
testUpdate(7, "34567", "567891011121314", "56789", "1718192021", "000001718192021");
|
||||||
testUpdate(8);
|
testUpdate(8, "45678", "78910111213141516", "7891011", "2021222324", "000002021222324");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void testUpdate (int opCount)
|
protected void testUpdate (int opCount, String... results)
|
||||||
{
|
{
|
||||||
// set up a throttle for 5 ops per millisecond
|
// set up a throttle for 5 ops per millisecond
|
||||||
TestThrottle throttle = new TestThrottle(5, 1);
|
TestThrottle throttle = new TestThrottle(5, 1);
|
||||||
System.out.println("Testing updates with " + opCount + " operations");
|
// System.out.println("Testing updates with " + opCount + " operations");
|
||||||
long time = 0;
|
long time = 0;
|
||||||
for (int ii = 0; ii < opCount; ++ii) {
|
for (int ii = 0; ii < opCount; ++ii) {
|
||||||
throttle.throttleOp(time += 1);
|
throttle.throttleOp(time += 1);
|
||||||
}
|
}
|
||||||
System.out.println(" " + throttle.opsToString());
|
assertEquals(results[0], throttle.opsToString());
|
||||||
throttle.reinit(10, 1);
|
throttle.reinit(10, 1);
|
||||||
for (int ii = 0; ii < opCount; ++ii) {
|
for (int ii = 0; ii < opCount; ++ii) {
|
||||||
throttle.throttleOp(time += 1);
|
throttle.throttleOp(time += 1);
|
||||||
}
|
}
|
||||||
System.out.println(" " + throttle.opsToString());
|
assertEquals(results[1], throttle.opsToString());
|
||||||
throttle.reinit(5, 1);
|
throttle.reinit(5, 1);
|
||||||
System.out.println(" " + throttle.opsToString());
|
assertEquals(results[2], throttle.opsToString());
|
||||||
for (int ii = 0; ii < opCount; ++ii) {
|
for (int ii = 0; ii < opCount; ++ii) {
|
||||||
throttle.throttleOp(time += 1);
|
throttle.throttleOp(time += 1);
|
||||||
}
|
}
|
||||||
System.out.println(" " + throttle.opsToString());
|
assertEquals(results[3], throttle.opsToString());
|
||||||
throttle.reinit(10, 1);
|
throttle.reinit(10, 1);
|
||||||
System.out.println(" " + throttle.opsToString());
|
assertEquals(results[4], throttle.opsToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# $Id: test.properties,v 1.3 2002/11/25 22:23:21 mdb Exp $
|
||||||
|
#
|
||||||
|
# A test properties file
|
||||||
|
|
||||||
|
_extends = util/parent.properties
|
||||||
|
|
||||||
|
prop1 = 25
|
||||||
|
prop2 = twenty five
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
#
|
#
|
||||||
# A test properties file
|
# A test properties file
|
||||||
|
|
||||||
_extends = util/parent.properties
|
sub.sub1 = 5
|
||||||
|
sub.sub2 = whee!
|
||||||
|
|
||||||
prop1 = 25
|
prop1 = 25
|
||||||
prop2 = twenty five
|
prop2 = twenty five
|
||||||
|
prop3 = 9, 8, 7, 6
|
||||||
|
prop4 = one, two, three,, and a half, four
|
||||||
|
|||||||
Reference in New Issue
Block a user