Created
November 1, 2021 00:26
-
-
Save ytyubox/e10e400970e1b73a96222c01405494f9 to your computer and use it in GitHub Desktop.
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
final class FibTests: XCTestCase { | |
class DPO1 { | |
func fib(_ n: Int) -> Int { | |
var dp = [0,1] | |
if n < 2 {return dp[n]} | |
for i in 2...n { | |
dp[i&1] = dp[0] + dp[1] | |
} | |
return dp[n&1] | |
} | |
} | |
func test() throws { | |
let fibs = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 ,610] | |
for i in fibs.indices { | |
XCTAssertEqual(DPO1().fib(i), fibs[i]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment