tests/testthat/test_HI_and_MHI.R

# TESTING HI AND MHI ------------------------------------------------------

N = 20

time_grid = seq( 0, 1, length.out = N * 1e2 )

Data = matrix( 0, nrow = N, ncol = length( time_grid ) )

for( iObs in 1 : N )
{
  Data[ iObs, ] =  as.numeric( time_grid >= ( iObs - 1 ) / N & time_grid < iObs / N )
}

Data[ N, length( time_grid ) ] = 1

test_that( "Correctness of HI",
           expect_equal( HI( Data ), rep( 1 / N, N ) ) )

test_that( "Correctness of MHI",
           expect_equal( MHI( Data ), rep( ( N + ( N - 1 )^2 ) / N^2 , N ) ) )


# TEST BY JAMES LONG (TAMU) -------------------------------------------------------------------

yints = c( 1.27, .927, 1/2, .217, 0)
slopes = c( -1, -1, 0, 1, 1 )
time_grid = ( 0 : 100 ) / 100

Data = matrix( 0, nrow = length( yints ),
               ncol = length( time_grid ) )

for( i in 1 : length( yints ) )

  Data[ i, ] = yints[ i ] + time_grid * slopes[ i ]

test_that( "Correctness of HI - James Long test",
           expect_equal( HI( Data ), c( 0.4, 0.2, 0.2, 0.4, 0.2 ) ) )

Try the roahd package in your browser

Any scripts or data that you put into this service are public.

roahd documentation built on May 30, 2017, 6:09 a.m.