Skip to content

Commit 40586f4

Browse files
authored
style: simplify fib_iterative (#188)
* tests: add missing test case for `fib_iterative` * style: remove redundant brach in `fib_iterative`
1 parent 4da6bc6 commit 40586f4

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

src/math/fibonacci.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ function fib_iterative(n::Int)
9898
throw(DomainError("n is negative"))
9999
elseif n == 1
100100
return [0]
101-
elseif n == 2
102-
return [0, 1]
103101
else
104102
result = [0, 1]
105103
a, b = 0, 1

test/math.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ using TheAlgorithms.Math
239239
@test fib_recursive_memo(6) == [0, 1, 1, 2, 3, 5]
240240
@test_throws DomainError fib_recursive_memo(-1)
241241
@test fib_iterative(1) == [0]
242+
@test fib_iterative(2) == [0, 1]
242243
@test fib_iterative(6) == [0, 1, 1, 2, 3, 5]
243244
@test_throws DomainError fib_iterative(-1)
244245
end

0 commit comments

Comments
 (0)