extend("test")
extend("array")
describe("how ink povides an iterator that is compaible with array:map", () => {
it("should produce a simple range from 0..3 using array:map identity", () => {
result = array:map(x => x, ink(0, 3))
expect_equal(result, [0,1,2])
})
it("should handle an empty range => map yields empty array", () => {
out = array:map(x => x * 2, ink(5, 5))
expect_equal(out, [])
})
it("should apply x => x*x over ink(2,5) => squares of [2,3,4]", () => {
squares = array:map(x => x * x, ink(2,5))
expect_equal(squares, [4,9,16])
})
})
describe("how ink provides an iterator that is compaible with array:reduce", () => {
it("should sum up elements from 10..14 => 10+11+12+13=46", () => {
total = array:reduce(
(acc, x) => acc + x,
0,
ink(10,14)
)
expect_equal(total, 46)
})
it("should produce 0 if start >= end => no iteration", () => {
result = array:reduce(
(acc, x) => acc + x,
1000,
ink(5, 5)
)
expect_equal(result, 1000)
result2 = array:reduce(
(acc, x) => acc + x,
0,
ink(20, 10)
)
expect_equal(result2, 0)
})
it("should handle partial usage => function known, missing data", () => {
sumUntil = array:reduce((acc, x) => acc + x, 100)
out = sumUntil(ink(3,6)) # enumerates [3,4,5]
expect_equal(out, 3+4+5 + 100)
})
})