Sha256: d5ef155f9564665723de52aebdc8e0d9fb15737e2fac11bc40e0f9f6e9a918e1

Contents?: true

Size: 952 Bytes

Versions: 66

Compression:

Stored size: 952 Bytes

Contents

local flatten = require 'flatten-array'

describe('flatten-array', function()
  it('should flatten arrays with a single level of nesting', function()
    assert.are.same(
      { 1, 2, 3, 4, 5, 6, 7, 8 },
      flatten({ 1, { 2, 3, 4, 5, 6, 7 }, 8 })
    )
  end)

  it('should flatten deeply nested arrays', function()
    assert.are.same(
      { 0, 2, 2, 3, 8, 100, 4, 50, -2 },
      flatten({ 0, 2, { { 2, 3 }, 8, 100, 4, { { { 50 } } } }, -2 })
    )

    assert.are.same(
      { 1,2,3,4,5,6,7,8 },
      flatten({ 1, { 2, { { 3 } }, { 4, { { 5 } } }, 6, 7 }, 8 })
    )
  end)

  it('should flatten arrays containing empty arrays', function()
    assert.are.same(
      { 0, 2, 2, 3, 8, 100, -2 },
      flatten({ 0, 2, { { 2, 3 }, 8, { { 100 } }, { {} } }, -2 })
    )
  end)

  it('should flatten arrays with no elements to an empty array', function()
    assert.are.same(
      {},
      flatten({ { { {  } } }, { { } } })
    )
  end)
end)

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
trackler-2.0.6.10 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.9 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.8 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.7 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.6 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.5 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.4 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.3 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.2 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.1 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.6.0 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.18 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.17 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.16 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.15 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.14 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.13 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.12 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.11 tracks/lua/exercises/flatten-array/flatten-array_spec.lua
trackler-2.0.5.10 tracks/lua/exercises/flatten-array/flatten-array_spec.lua