From: Peter Murray-R. <pe...@us...> - 2006-06-27 17:07:37
|
Update of /cvsroot/cml/jumbo53/src/org/xmlcml/euclid/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv5151/src/org/xmlcml/euclid/test Modified Files: RealArrayTest.java RealRangeTest.java Log Message: main polymer and cml frag routines Index: RealRangeTest.java =================================================================== RCS file: /cvsroot/cml/jumbo53/src/org/xmlcml/euclid/test/RealRangeTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RealRangeTest.java 2 Jun 2006 15:48:08 -0000 1.1 --- RealRangeTest.java 27 Jun 2006 17:07:26 -0000 1.2 *************** *** 194,197 **** --- 194,213 ---- } + /** test getting a random variate. + * tests limits only + */ + @Test + public void testGetRandomVariate() { + RealRange range = new RealRange(10, 20); + double sum = 0.0; + for (int i = 0; i < 100; i++) { + double d = range.getRandomVariate(); + Assert.assertTrue("limit: ", d >= 10. && d <= 20.); + sum += d; + } + // System.out.println(sum); + // crude check + Assert.assertTrue("distribution", sum > 1400 && sum < 1600); + } /** * Test method for 'org.xmlcml.euclid.RealRange.RealRange(IntRange)' Index: RealArrayTest.java =================================================================== RCS file: /cvsroot/cml/jumbo53/src/org/xmlcml/euclid/test/RealArrayTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RealArrayTest.java 2 Jun 2006 15:48:08 -0000 1.1 --- RealArrayTest.java 27 Jun 2006 17:07:26 -0000 1.2 *************** *** 274,277 **** --- 274,361 ---- } + /** test getSymmetricalArray() + */ + @Test + public void testGetSymmetricalArray() { + RealArray realArray = RealArray.getSymmetricalArray(10., 11, 1.0); + Assert.assertEquals("range min", 9.0, realArray.getArray()[0], EPS); + Assert.assertEquals("range min+1", 9.2, realArray.getArray()[1], EPS); + Assert.assertEquals("range max", 11.0, realArray.getArray()[10], EPS); + Assert.assertEquals("range mid", 10.0, realArray.getArray()[5], EPS); + } + + /** test getNormalDistribution() + */ + @Test + public void testGetNormalDistribution() { + double mean = 10.; + double halfrange = 5.0; + int nsteps = 101; + double sigma = 1.0; + RealArray realArray = RealArray.getSymmetricalArray(mean, nsteps, halfrange); + RealArray normalDist = realArray.getNormalDistribution(sigma); + Assert.assertEquals("range min", 1.486e-06, normalDist.getArray()[0], 1E-06); + Assert.assertEquals("range mid", 0.398942, normalDist.getArray()[50], 1E-06); + Assert.assertEquals("range max", 1.486e-06, normalDist.getArray()[100], 1E-06); + RealArray cumulativeSum = normalDist.cumulativeSum(); + Assert.assertEquals("range min", 1.5e-06, cumulativeSum.getArray()[0], 1E-06); + Assert.assertEquals("range mid", 5.199469, cumulativeSum.getArray()[50], 1E-06); + Assert.assertEquals("range max", 9.999996, cumulativeSum.getArray()[100], 1E-06); + + for (int i = 0; i < 100; i++) { + double d = mean - halfrange + Math.random()*halfrange; + // System.out.println(d); + } + } + + /** test lineSearch. + */ + @Test + public void testLineSearch() { + RealArray x = new RealArray(11, 0., 1.0); + RealArray cumulative = new RealArray( + new double[]{0., 4., 5., 20., 23., 26., 33., 40., 41., 44., 50.}); + double d = -1.; + double probe = 22.; + d = x.lineSearch(probe, cumulative); + Assert.assertEquals("search ", 11./3., d, EPS); + probe = 2.; + d = x.lineSearch(probe, cumulative); + Assert.assertEquals("search ", 0.5, d, EPS); + probe = 1.; + d = x.lineSearch(probe, cumulative); + Assert.assertEquals("search ", 0.25, d, EPS); + probe = 4.5; + d = x.lineSearch(probe, cumulative); + Assert.assertEquals("search ", 1.5, d, EPS); + probe = 50; + d = x.lineSearch(probe, cumulative); + Assert.assertEquals("search ", 10., d, EPS); + probe = 0; + d = x.lineSearch(probe, cumulative); + Assert.assertEquals("search ", 0., d, EPS); + } + + /** test getRandomVariate. + * + */ + @Test + @SuppressWarnings("unused") + public void testGetRandomVariate() { + + RealArray x = new RealArray(11, 20., 1.); // gives 20, 21 ...30 + System.out.println(x); + RealArray freq = new RealArray( + new double[] { + 5., 10., 10., 1., 0., 2., 10., 15., 10., 3., 1. + }); + RealArray cumulativeSum = new RealArray(); + for (int i = 0; i < 50; i++) { + double random = x.getRandomVariate(freq, cumulativeSum); + // System.out.println(cumulativeSum); + // System.out.println(random); + } + } + /** * Test method for 'org.xmlcml.euclid.RealArray.elementAt(int)' *************** *** 488,492 **** } catch (ArrayIndexOutOfBoundsException e) { Assert.assertEquals("subArray ArrayIndexOutOfBoundsException", ! "java.lang.ArrayIndexOutOfBoundsException", "" + e); } } --- 572,576 ---- } catch (ArrayIndexOutOfBoundsException e) { Assert.assertEquals("subArray ArrayIndexOutOfBoundsException", ! "java.lang.ArrayIndexOutOfBoundsException: was 1 in 0-4", "" + e); } } |