tests/testthat/test_calc_entropy.R

testthat::test_that("calc_entropy() returns correct vector with attr", {
    #   Validated input matrix
    ra_mat <- matrix(c(-1, -1, -1, -1,  1,
                       -1,  0,  0, -1,  0,
                       -1,  0, -1,  0,  0, 
                        0,  0, -1,  0, -1), nrow = 4L, byrow = TRUE)
    
    #   Define the goal vector
    entropy_goal <- c(0.00000000, 0.47712125, 0.00000000, 0.30103000, 0.41269725)
    
    #   Calculate entropy and set attributes to NULL for testing purposes ONLY    
    entropy <- calc_entropy(ra_mat)
    attributes(entropy) <- NULL
    
    testthat::expect_equal(entropy, entropy_goal)
})

Try the obfuscatoR package in your browser

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

obfuscatoR documentation built on Sept. 8, 2023, 5:48 p.m.