Created
August 21, 2014 15:01
-
-
Save 3100/6224f73ab8c11b19aa23 to your computer and use it in GitHub Desktop.
how to test a R script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Combine <- function(df1, df2, fmt) { | |
# 同じサイズの2つの行列を用いて、各セル値を合成します。 | |
# | |
# Args: | |
# df1: 行列1 | |
# df2: 行列2 | |
# fmt: 表示書式(sprintf) | |
# | |
# Returns: | |
# 合成した行列 | |
matrix(sprintf(df1, df2, fmt = fmt), nrow = nrow(df1), dimnames = dimnames(df1)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# library(testthat) | |
# source('<path of sample.R>') | |
# test_file('<path of this file'>) | |
test_that('Combine works', { | |
m1 <- cbind(c('hoge', 'huga', 'hige'), | |
c(1, 2, 3)) | |
m2 <- cbind(c('a', 'b', 'c'), | |
c(5, 6, 7)) | |
combined <- Combine(m1, m2, "%s %s") | |
expect_equal(combined[1,1], 'hoge a') | |
expect_equal(combined[3,2], '3 7') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment