Debian Codegraph @

src/test/dr/inference/operators/RandomWalkOperatorTest.java

raw symbols SCIP
1 /*
2 * YuleLikelihoodTest.java
3 *
4 * Copyright (C) 2002-2009 Alexei Drummond and Andrew Rambaut
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package test.dr.inference.operators;
27
28 import dr.inference.model.Parameter;
29 import dr.inference.operators.AdaptationMode;
30 import dr.inference.operators.RandomWalkOperator;
31 import junit.framework.*;
32
33 /**
34 * RandomWalkOperatorTest.
35 *
36 * @author Andrew Rambaut
37 * @version 1.0
38 * @since <pre>08/26/2007</pre>
39 */
40 public class RandomWalkOperatorTest extends TestCase {
41
42 public RandomWalkOperatorTest(String name) {
43 super(name);
44 }
45
46 public void setUp() throws Exception {
47 super.setUp();
48 }
49
50 public void testRandomWalkOperator() {
51 Parameter parameter = new Parameter.Default("test", 0.5, 0.0, 1.0);
52 RandomWalkOperator rwo = new RandomWalkOperator(parameter, 1.0, RandomWalkOperator.BoundaryCondition.reflecting, 1.0, AdaptationMode.ADAPTATION_OFF);
53
54 double test1 = rwo.reflectValue(8.7654321, 3.14159265, Double.POSITIVE_INFINITY);
55 double test2 = rwo.reflectValue(8.7654321, Double.NEGATIVE_INFINITY, 3.14159265);
56 double test3 = rwo.reflectValue(1.2345678, 3.14159265, 2.0 * 3.14159265);
57 double test4 = rwo.reflectValue(12345678.987654321, 3.14159265, 2.0 * 3.14159265);
58
59 double test1b = rwo.reflectValueLoop(8.7654321, 3.14159265, Double.POSITIVE_INFINITY);
60 double test2b = rwo.reflectValueLoop(8.7654321, Double.NEGATIVE_INFINITY, 3.14159265);
61 double test3b = rwo.reflectValueLoop(1.2345678, 3.14159265, 2.0 * 3.14159265);
62 double test4b = rwo.reflectValueLoop(12345678.987654321, 3.14159265, 2.0 * 3.14159265);
63
64 assertEquals(test1, test1b);
65 assertEquals(test2, test2b);
66 assertEquals(test3, test3b);
67 assertTrue(Math.abs(test4 - test4b) < 0.001);
68
69 }
70
71 public static Test suite() {
72 return new TestSuite(RandomWalkOperatorTest.class);
73 }
74 }