test/testthat/test_find_pattern.R

#!/usr/bin/Rscript
# -*- coding: utf-8 -*-

################################ Description ###################################
# Title: Unit test for the leading spaces checker
# Created the 2014-12-29 
# by Joris Muller <joris.muller@jom.link>
# Licence: This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# ( at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
################################################################################

library(testthat)

context("Find leading spaces")


test_that(desc = "Find leading spaces in character vectors",{
   expect_equal(find_leadspace(char_vector), c(2,4)) 
})

test_that(desc = "Must accept factors too",{
    factor_vector <- as.factor(char_vector)
    expect_equal(find_leadspace(factor_vector), c(2,4))
})

test_that(desc = "logical argument",{
    expect_is(find_leadspace(char_vector, return_logical = TRUE), "logical")
}) 

#############################
context("Find tailing spaces")


char_vector <- c("aa", "bb ", "jfj jk", " z z z ")

test_that(desc = "Find tailing spaces in character vectors",{
   expect_equal(find_tailspace(char_vector), c(2,4)) 
})

test_that(desc = "Must accept factors too",{
    factor_vector <- as.factor(char_vector)
    expect_equal(find_tailspace(factor_vector), c(2,4))
})

test_that(desc = "logical argument",{
    expect_is(find_tailspace(char_vector, return_logical = TRUE), "logical")
}) 

########################
contexte("Find double spaces")

char_vector <- c("aa", "bb ", "jfj    jk", " z  z z ")

test_that(desc = "Find tailing spaces in character vectors",{
   expect_equal(find_multiplespace(char_vector), c(3,4)) 
})
jomuller/dfcheck documentation built on May 19, 2019, 7:26 p.m.