001package models;
002
003import static org.junit.Assert.*;
004
005import org.apache.commons.math3.complex.Complex;
006import org.junit.Test;
007
008
009/**
010 * Unit tests for the {@link SinhTools} class.
011 *
012 */
013public class SinhToolsTest {
014
015        
016        /**
017         * Comparison of the function sinhIntegral to some values computed externally
018         * with Maple to higher floating point precision (tolerance 1e-20).
019         */
020        @Test
021        public void testSinhIntegral() {
022                
023                double prec = 1e-12;
024                
025                assertEquals(1.03157901353779514476969801058,
026                                SinhTools.sinhIntegral(1.0, 1.0), prec);
027
028                assertEquals(1.10201983196157370929728224428,
029                                SinhTools.sinhIntegral(2.0, 1.0), prec);
030
031                assertEquals(1.07836648136920973176139239832,
032                                SinhTools.sinhIntegral(2.0, 0.5), prec);
033
034                assertEquals(1.19672220495232805797153069762,
035                                SinhTools.sinhIntegral(10.0, 0.5), prec);
036
037        }
038
039        /** 
040         * Comparison of {@link models.SinhTools#sinhIntegral} for large values of theta
041         * with its limit computed in {@link models.SinhTools#sinhIntegralLimit}.
042         */
043        @Test
044        public void testSinhIntegralLimit() {
045                double finiteInt = SinhTools.sinhIntegral(50, 1.0);
046                double limitInt =  SinhTools.sinhIntegralLimit(1.0);
047                String msg = "Testing limit of sinh Integral";
048                                
049                assertEquals(msg, finiteInt, limitInt, 1e-10);                          
050        }
051
052        /** 
053         * Comparison of {@link models.SinhTools#sinhIntegralCCPair} for large values of theta
054         * with its limit computed in {@link models.SinhTools#sinhIntegralCCPairLimit}.
055         */
056        @Test
057        public void testSinhIntegralCCLimit() {
058                Complex c = new Complex(1.0, 0.5);
059                double finiteInt = SinhTools.sinhIntegralCCPair(50, c);
060                double limitInt =  SinhTools.sinhIntegralCCPairLimit(c);
061                String msg = "Testing limit of sinh Integral with complex coupling";
062                                
063                assertEquals(msg, finiteInt, limitInt, 1e-10);                          
064        }
065
066        /**
067         * Comparison of the function {@link models.SinhTools#sinhIntegralCCPair} to some values computed externally
068         * with Maple at higher floating point precision (tolerance 1e-20).
069         */
070        @Test
071        public void testSinhIntegralCCPair() {
072                double prec = 1e-12;
073
074                assertEquals(1.11148959840450668619683620201,
075                                SinhTools.sinhIntegralCCPair(1.0, new Complex(1,1)), prec);
076
077                assertEquals(1.26449797806599613970533667556,
078                                SinhTools.sinhIntegralCCPair(2.0, new Complex(1,0.5)), prec);
079                
080
081        }
082
083        private void testCCPairOneRealValue(double t, double b) {
084                double singleInt = SinhTools.sinhIntegral(t, b);
085                double doubleInt = SinhTools.sinhIntegralCCPair(t, new Complex(b,0));
086                String msg = "Testing t="+t+", b="+b;
087                                
088                assertEquals(msg, singleInt*singleInt, doubleInt, 1e-10);                               
089        }       
090
091        /**
092         * Comparison of the output of {@link models.SinhTools#sinhIntegralCCPair} to {@link models.SinhTools#sinhIntegral}
093         * in the case where the imaginary part of the coupling is zero.
094         */
095        @Test
096        public void testSinhIntegralCCPairReal() {
097                for (double t = 0.0; t <= 10.0; t += 1.0) {
098                        for (double b = 0.1; b <= 1.9; b += 0.1) {
099                                testCCPairOneRealValue(t, b);
100                        }
101                }
102        }
103
104}