tests/testthat/test-pricesAsStrings.R

testthat::test_that("The function recognises numbers as strings", {

    # A data frame containing two prices wrongly read as strings
    df <- data.frame(
        product = c('SmartWatch', 'laptop', 'monitor'),
        price_USD = c('249', '517' ,319)
    )

    # Expected price for a USD discount of 25 %
    price_manual <- (249+319+517)*0.75

    testthat::expect_equal(
        object = total_price(df, currency = 'USD'),
        expected = price_manual
    )
})
svalvaro/terribleCode documentation built on Feb. 2, 2022, 5:18 p.m.