Sha256: fb83306fed5328dab59df8483141405f41d3c2188d7f349b5aa1c277e0cf66d3

Contents?: true

Size: 1.8 KB

Versions: 78

Compression:

Stored size: 1.8 KB

Contents

#!/usr/bin/env perl6
use v6;
use Test;
use JSON::Fast;
use lib $?FILE.IO.dirname;
use FlattenArray;
plan 6;

my Version:D $version = v2;

if FlattenArray.^ver !~~ $version {
  warn "\nExercise version mismatch. Further tests may fail!"
    ~ "\nFlattenArray is {FlattenArray.^ver.gist}. "
    ~ "Test is {$version.gist}.\n";
}

my $c-data = from-json $=pod.pop.contents;
is-deeply flatten-array(.<input><array>), |.<expected description> for @($c-data<cases>);

=head2 Canonical Data
=begin code
{
  "exercise": "flatten-array",
  "version": "1.2.0",
  "cases": [
    {
      "description": "no nesting",
      "property": "flatten",
      "input": {
        "array": [0, 1, 2]
      },
      "expected": [0, 1, 2]
    },
    {
      "description": "flattens array with just integers present",
      "property": "flatten",
      "input": {
        "array": [1, [2, 3, 4, 5, 6, 7], 8]
      },
      "expected": [1, 2, 3, 4, 5, 6, 7, 8]
    },
    {
      "description": "5 level nesting",
      "property": "flatten",
      "input": {
        "array": [0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2]
      },
      "expected": [0, 2, 2, 3, 8, 100, 4, 50, -2]
    },
    {
      "description": "6 level nesting",
      "property": "flatten",
      "input": {
        "array": [1, [2, [[3]], [4, [[5]]], 6, 7], 8]
      },
      "expected": [1, 2, 3, 4, 5, 6, 7, 8]
    },
    {
      "description": "6 level nest list with null values",
      "property": "flatten",
      "input": {
        "array": [0, 2, [[2, 3], 8, [[100]], null, [[null]]], -2]
      },
      "expected": [0, 2, 2, 3, 8, 100, -2]
    },
    {
      "description": "all values in nested list are null",
      "property": "flatten",
      "input": {
        "array": [null, [[[null]]], null, null, [[null, null], null], null]
      },
      "expected": []
    }
  ]
}
=end code

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.179 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.178 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.177 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.176 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.175 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.174 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.173 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.172 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.171 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.170 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.169 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.167 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.166 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.165 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.164 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.163 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.162 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.161 tracks/perl6/exercises/flatten-array/flatten-array.t
trackler-2.2.1.160 tracks/perl6/exercises/flatten-array/flatten-array.t