extend("test")
extend("array")

nth = array:nth
tail = array:tail
reduce = array:reduce
append = array:append
range = array:range

describe("fibonacci calculation fuction", () => {
  it("should return the first 19 values of the sequence as an int_array", () => {

    fibonacci = compose(
      tail,
      reduce(
        (acc, i) => append(
          i > 1 ? nth(i, acc) + nth(i - 1, acc) : i,
          acc
        ),
        [0]
      ),
      range(0)
    )

    # Check the result
    result = fibonacci(19)
    expect_equal( type(result), "int_array" )
    expect_equal( result, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584] )
  })
})

