Added selectRandomSubset() which selects a random subset of elements (with

equal probability) from a collection.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@701 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert@gmail.com
2002-04-11 04:11:23 +00:00
parent 8daf88066b
commit 6caf731ff9
2 changed files with 102 additions and 1 deletions
@@ -0,0 +1,46 @@
//
// $Id: CollectionUtilTest.java,v 1.1 2002/04/11 04:11:23 mdb Exp $
package com.samskivert.util;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Tests the {@link CollectionUtil} class.
*/
public class CollectionUtilTest extends TestCase
{
public CollectionUtilTest ()
{
super(CollectionUtil.class.getName());
}
public void runTest ()
{
ArrayList list = new ArrayList();
for (int i = 0; i < 100; i++) {
list.add(new Integer(i));
}
for (int i = 0; i < 10; i++) {
List subset = CollectionUtil.selectRandomSubset(list, 10);
// System.out.println(StringUtil.toString(subset));
assertTrue("length == 10", subset.size() == 10);
}
}
public static Test suite ()
{
return new CollectionUtilTest();
}
public static void main (String[] args)
{
CollectionUtilTest test = new CollectionUtilTest();
test.runTest();
}
}