1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.util;
23
24 import org.hipparchus.exception.MathIllegalStateException;
25 import org.junit.Assert;
26 import org.junit.Test;
27
28
29
30
31 public class ContinuedFractionTest {
32
33 @Test
34 public void testGoldenRatio() throws Exception {
35 ContinuedFraction cf = new ContinuedFraction() {
36
37 @Override
38 public double getA(int n, double x) {
39 return 1.0;
40 }
41
42 @Override
43 public double getB(int n, double x) {
44 return 1.0;
45 }
46 };
47
48 double gr = cf.evaluate(0.0, 10e-9);
49 Assert.assertEquals(1.61803399, gr, 10e-9);
50 }
51
52 @Test(expected = MathIllegalStateException.class)
53 public void testNonConvergentContinuedFraction() {
54 ContinuedFraction cf = new ContinuedFraction() {
55
56 @Override
57 public double getA(int n, double x) {
58 return 1.0;
59 }
60
61 @Override
62 public double getB(int n, double x) {
63 return 1.0;
64 }
65
66 };
67
68 cf.evaluate(0.0, 10e-9, 10);
69 }
70
71 @Test(expected = MathIllegalStateException.class)
72 public void testInfinityDivergence() {
73 ContinuedFraction cf = new ContinuedFraction() {
74
75 @Override
76 public double getA(int n, double x) {
77 return 1. / n;
78 }
79
80 @Override
81 public double getB(int n, double x) {
82 return 1.0;
83 }
84
85 };
86
87 cf.evaluate(1);
88 }
89 }