tests/testthat/test_aac.R

test_that("test suite aaa", {


## Some random tests that check hypergeo::complex_gamma() against
## numerical results from sage 8.3

sage_session_cut_and_pasted <- '
sage: [gamma(n/2.3 + I*(5.5-n)/7) for n in range(0,20)]

[-0.246585750155252 - 0.788407925178669*I,
 0.542559294193820 - 0.767432004580555*I,
 0.819235116119572 - 0.294120086420150*I,
[snip]


sage: [log(gamma(n/2.3 + I*(5.5-n)/7)) for n in range(0,20)]

[-0.191075804494126 - 1.87392184418394*I,
 -0.0620324737856585 - 0.955400956657334*I,
 -0.138765022409830 - 0.344685902467053*I,

[snip]
'

##  Use emacs to massage the sage output into R idiom, results below:

sage_output_gamma_R_format <- c(
-0.246585750155252-0.788407925178669i,
 0.542559294193820-0.767432004580555i,
 0.819235116119572-0.294120086420150i,
 0.834755183900526-0.0417405920901170i,
 0.899406167732265+0.0469668262409705i,
 1.08409566482215+0.0410229805324838i,
 1.43521690425971-0.0775040106458880i,
 2.02236228878133-0.413390653488534i,
 2.93560947168107-1.21439179143865i,
 4.23482688752040-3.00609122808354i,
 5.76739908927908-6.84960530420096i,
 6.63025533662589-14.7735197662212i,
 3.74361928083599-30.3434731835514i,
-11.6304854429652-58.9008933757605i,
-61.7157426512415-105.508243912928i,
-198.078972505428-164.220688914079i,
-528.676625677938-180.647166193543i,
-1247.44255340476+57.6876659718305i,
-2603.20278421158+1204.08700523020i,
-4556.25723645914+4991.74774863458i
)

sage_output_lngamma_R_format <- c(
-0.191075804494126 -1.87392184418394i,
-0.0620324737856585-0.955400956657334i,
-0.138765022409830-0.344685902467053i,
-0.179368180688191-0.0499617809420536i,
-0.104658948009976+0.0521724291113619i,
+0.0814615994375794+0.0378226923195707i,
+0.362771955148006-0.0539492000104258i,
+0.724733286298095-0.201632125710389i,
+1.15589878343980-0.392240333063894i,
+1.64736893188028-0.617306057097316i,
+2.19213696055626-0.870962364182450i,
+2.78458653080112-1.14894642256732i,
+3.42013476961537-1.44804186919336i,
+4.09498074511363-1.76574700191682i,
+4.80592625283565-2.10006693124277i,
+5.55024592165772-2.44937765347333i,
+6.32559132493222-2.81233386576143i,
+7.12991892377862+3.09538082977844i,
+7.96143501192192+2.70835903122769i,
+8.81855300357745+2.31061545024411i
)


# now perform the actual comparison:
jj <- 0:19 # note off-by-one issue
z <-jj/2.3 + 1i*(5.5-jj)/7   # this is the vector of values used in
                             # the first line of
                             # "sage_session_cut_and_pasted"



## First, check hypergeo::complex_gamma():
error1 <- sage_output_gamma_R_format - complex_gamma(z)
expect_true(all(abs(error1)<1e-10))


## Second, check hypergeo::complex_gamma(log=TRUE):
## Need to account for sage's different cut lines:
sage_output_lngamma_R_format[18:20] %<>% "-"(pi*2i)

error2 <- sage_output_lngamma_R_format - complex_gamma(z,log=TRUE) 
expect_true(all(abs(error2)<1e-13))

} )
RobinHankin/hypergeo documentation built on Aug. 29, 2023, 4 p.m.