Skip to content

Commit

Permalink
Merge pull request #22 from fungenomics/issue/11
Browse files Browse the repository at this point in the history
Create unit testing for sum_n_first_fibonacci_numbers.
  • Loading branch information
sjessa authored May 14, 2020
2 parents 37b8402 + 8bd5141 commit 56b5aa1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/sum_first_fibonacci_numbers.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#' sum_n_first_fibonacci_numbers(5)
#' sum_n_first_fibonacci_numbers(8)
sum_n_first_fibonacci_numbers <- function(n){
if(n < 0){
stop("Please use a positive number")
}
if(length(fibonacci) < n){
print(paste0("Fibonacci vector's length is ", length(fibonacci), ". Summing the ", length(fibonacci), " first numbers instead."))
return(sum(fibonacci))
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-sum_n_first_fibonacci_numbers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("sum_n_first_fibonacci_numbers works", {
expect_equal(sum_n_first_fibonacci_numbers(4), 7)
})

test_that("sum_n_first_fibonacci_numbers handles edge cases", {
expect_error(sum_n_first_fibonacci_numbers(-3), "Please use a positive number")
})

0 comments on commit 56b5aa1

Please sign in to comment.