tests/testthat/test-chem_FUN.R

test_that("format inchikeys", expect_identical(
    format_inchikey(c("BQJCRHHNABKAKU-KBQPJGBKSA-N", 
        "BQJCRHHNABKAKU-KBQPJGBKSA", 
        "BQJCRHHNABKAKU-KBQPJGBKSA-5", 
        "BQJCRHHNABKAKU-KBQPJGBKSA-n", 
        "BQJCRHHNABKAKU/KBQPJGBKSA/N", 
        "BQJCRHHNABKAKU-KBQPJGBKXA-N", 
        "BQJCRHHNABKAKU-KBQPJGBKSB-N")), 
    c("BQJCRHHNABKAKU-KBQPJGBKSA-N", NA, NA, NA, NA, NA, NA)))

test_that("check inchikeys", expect_identical(
    check_inchikey(c("BQJCRHHNABKAKU-KBQPJGBKSA-N", 
        "BQJCRHHNABKAKU-KBQPJGBKSA", 
        "BQJCRHHNABKAKU-KBQPJGBKSA-5", 
        "BQJCRHHNABKAKU-KBQPJGBKSA-n", 
        "BQJCRHHNABKAKU/KBQPJGBKSA/N", 
        "BQJCRHHNABKAKU-KBQPJGBKXA-N", 
        "BQJCRHHNABKAKU-KBQPJGBKSB-N")), 
    c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)))

test_that("check cas", expect_identical(
    check_cas(c("64-17-5", "64175", "4-17-5", 
        "64-177-6", "64-17-55", "64-17-6")), 
    c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)))

test_that("format formulas", expect_identical(
    format_formula(c("C12H18Br6", "C12[2]H18Br6", "C12H17DBr6", 
        "C12H18Gy2Br6", "C12 H18Br6", "Gy2", "")), 
    c("C12H18Br6", "C12[2]H18Br6", "C12H17D1Br6", 
        "C12H18Br6", NA, NA, NA)))
        
test_that("get basepeak m/z", expect_equal(
    get_basepeak_mass("C12H18Br6", 0),
    641.6447373))
    
test_that("convert m/z to mass", expect_equal(
    mzs_to_mass(443.1247895, c("M+H", "M+2H")), 
    matrix(c("443.1247895", "443.1247895", "M+H", "M+2H", 
        "444.1320655", "887.256855"), ncol = 3, 
        dimnames = list(c(), c("mz", "adduct", "mass")))))
    
test_that("get mass range", expect_equal(
    get_mass_range(c(443.1247985, 190.053578), ppm = 2, mda = 1), 
    matrix(c(443.1229123, 190.0521979, 443.1266847, 190.0549581), ncol = 2)))
shutinet/metabSeek documentation built on Sept. 5, 2020, 12:57 a.m.