use v6.d;

use lib '.';
use lib './lib';

use Data::Translators;
use JSON::Fast;
use Test;

plan *;

#===========================================================
## 1
#===========================================================
my $data1 = [ 4 => 'a', 5 => 'b', 8 => 'c'];
is-deeply
        to-dataset($data1),
        $data1.map({ Hash.new( <Key Value> Z=> $_.kv ) }).Array;

#===========================================================
## 2
#===========================================================
my $data2 = { 4 => 'a', 5 => 'b', 8 => 'c'};
is-deeply
        to-dataset($data2),
        $data2.map({ Hash.new( <Key Value> Z=> $_.kv ) }).Array;

#===========================================================
## 3
#===========================================================
my $data3 = (${:id("304"), :passengerAge("60"), :passengerClass("1st"), :passengerSex("male"), :passengerSurvival("died")},
             ${:id("594"), :passengerAge("30"), :passengerClass("2nd"), :passengerSex("female"), :passengerSurvival("survived")},
             ${:id("1163"), :passengerAge("-1"), :passengerClass("3rd"), :passengerSex("male"), :passengerSurvival("survived")},
             ${:id("1038"), :passengerAge("-1"), :passengerClass("3rd"), :passengerSex("female"), :passengerSurvival("survived")});

is-deeply
        to-dataset($data3),
        $data3;

#===========================================================
## 4
#===========================================================
my $data4 = (${:id("304"), :passengerAge("60"), :passengerClass("1st"), :passengerSex("male"), :passengerSurvival("died")},
             ${:id("594"), :passengerClass("2nd"), :passengerSex("female"), :passengerSurvival("survived")},
             ${:id("1163"), :passengerAge("-1"),  :passengerSex("male"), :passengerSurvival("survived")},
             ${:id("1038"), :passengerAge("-1"), :passengerSex("female")});

my $res4 = $[{:id("304"), :passengerAge("60"), :passengerClass("1st"), :passengerSex("male"), :passengerSurvival("died")},
             {:id("594"), :passengerAge("NA"), :passengerClass("2nd"), :passengerSex("female"), :passengerSurvival("survived")},
             {:id("1163"), :passengerAge("-1"), :passengerClass("NA"), :passengerSex("male"), :passengerSurvival("survived")},
             {:id("1038"), :passengerAge("-1"), :passengerClass("NA"), :passengerSex("female"), :passengerSurvival("NA")}];

is-deeply
        to-dataset($data4, missing-value => 'NA'),
        $res4;


#===========================================================
## 5
#===========================================================
is-deeply
        to-dataset($data4[(0,3,2,1)]),
        to-dataset($data4[(0,3,2,1)].Array),
        'equivalence';

done-testing;