From 8eeb87af2a66fad93026e18d51fe496d60b4b4e9 Mon Sep 17 00:00:00 2001 From: andrewk Date: Fri, 31 Jul 2009 00:09:35 +0000 Subject: [PATCH] Tests for downsampling related utilities in ListUtils class that didn't get checked in earlier git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1352 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/ListUtilsTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 java/test/org/broadinstitute/sting/utils/ListUtilsTest.java diff --git a/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java b/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java new file mode 100644 index 000000000..723a16476 --- /dev/null +++ b/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java @@ -0,0 +1,61 @@ +package org.broadinstitute.sting.utils; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.broadinstitute.sting.BaseTest; +import org.broadinstitute.sting.utils.MathUtils; + + +import java.io.File; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +/** + * Basic unit test for MathUtils + */ +public class ListUtilsTest extends BaseTest { + @BeforeClass + public static void init() { } + + /** + * Tests that the random index selection is working correctly + */ + @Test + public void testRandomIndicesWithReplacement() { + logger.warn("Executing testRandomIndicesWithReplacement"); + + // Check that the size of the list returned is correct + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(0, 5).size() == 0); + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(1, 5).size() == 1); + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(5, 5).size() == 5); + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(1000, 5).size() == 1000); + + // Check that the list contains only the k element range that as asked for - no more, no less + List Five = new ArrayList(); + Collections.addAll(Five, 0, 1, 2, 3, 4); + List BigFive = ListUtils.sampleIndicesWithReplacement(10000, 5); + Assert.assertTrue(BigFive.containsAll(Five)); + Assert.assertTrue(Five.containsAll(BigFive)); + } + + /** + * Tests that we get the right values from the multinomial distribution + */ + @Test + public void testSliceListByIndices() { + logger.warn("Executing testSliceListByIndices"); + + // Check that the list contains only the k element range that as asked for - no more, no less but now + // use the index list to pull elements from another list using sliceListByIndices + List Five = new ArrayList(); + Collections.addAll(Five, 0, 1, 2, 3, 4); + List FiveAlpha = new ArrayList(); + Collections.addAll(FiveAlpha, 'a', 'b', 'c', 'd', 'e'); + List BigFive = ListUtils.sampleIndicesWithReplacement(10000, 5); + List BigFiveAlpha = ListUtils.sliceListByIndices(BigFive, FiveAlpha); + Assert.assertTrue(BigFiveAlpha.containsAll(FiveAlpha)); + Assert.assertTrue(FiveAlpha.containsAll(BigFiveAlpha)); + } +} \ No newline at end of file