Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unit testing for sum_n_first_fibonacci_numbers. #22

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
})