Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid output for ETL exercise #62

Open
ErikSchierboom opened this issue Mar 30, 2023 · 1 comment
Open

Invalid output for ETL exercise #62

ErikSchierboom opened this issue Mar 30, 2023 · 1 comment
Assignees

Comments

@ErikSchierboom
Copy link
Member

When submitting the following solution to the etl exercise:

use experimental qw( signatures switch );

sub transform ( $data ) {

    return reverse %$data;

    my %result;

    for my $key ( keys %$data ) {
        for my $value ( %$data{ $key } ) {
            $result->{ lc $value }++; # = [ $result{ lc $value }, lc $key ];
        }
    }

#    for my $key (keys %$data) {
#        %results->{ lc %$data->{$_} } = $_;
#    }

    return \%result;

}

use strict; use warnings;
use Exporter qw<import>; our @EXPORT_OK = qw<transform>

the test runner returns invalid JSON:

{
   "status" : "fail",
   "tests" : [
      {
         "name" : "Imported symbol: transform",
         "output" : null,
         "status" : "pass"
      },
      {
         "message" : "+-----------------------+----+-------+\n| GOT                   | OP | CHECK |\n+-----------------------+----+-------+\n| ARRAY(0x5654e8335858) | eq | 1     |\n+-----------------------+----+-------+single letter",
         "name" : {
            "a" : 1
         },
         "output" : null,
         "status" : "fail"
      },
      {
         "message" : "+-----------------------+----+-------+\n| GOT                   | OP | CHECK |\n+-----------------------+----+-------+\n| ARRAY(0x5654e7386458) | eq | 1     |\n+-----------------------+----+-------+single score with multiple letters",
         "name" : {
            "a" : 1,
            "e" : 1,
            "i" : 1,
            "o" : 1,
            "u" : 1
         },
         "output" : null,
         "status" : "fail"
      },
      {
         "message" : "+-----------------------+----+-------+\n| GOT                   | OP | CHECK |\n+-----------------------+----+-------+\n| ARRAY(0x5654e79cb540) | eq | 2     |\n+-----------------------+----+-------+1HASH(0x55f9ca8e2620)multiple scores with multiple letters",
         "name" : [
            "A",
            "E"
         ],
         "output" : null,
         "status" : "fail"
      },
      {
         "message" : "+-----------------------+----+-------+\n| GOT                   | OP | CHECK |\n+-----------------------+----+-------+\n| ARRAY(0x5654e7378b50) | eq | 8     |\n+-----------------------+----+-------+2ARRAY(0x55f9ca8e2350)5ARRAY(0x55f9ca8e2a88)1ARRAY(0x55f9caad4d38)4ARRAY(0x55f9caad4c90)10ARRAY(0x55f9caad4480)3HASH(0x55f9ca8e26b0)multiple scores with differing numbers of letters",
         "name" : [
            "D",
            "G"
         ],
         "output" : null,
         "status" : "fail"
      }
   ],
   "version" : 2
}

How how the name key is a string, object and array. We only accept strings for the name though, so the others likely indicate some issue with the test runner.

@m-dango
Copy link
Member

m-dango commented Jul 18, 2023

Using bin/run-in-docker.sh, I don't seem to get the same result:

{
  "status": "fail",
  "tests": [
    {
      "name": "Imported symbol: transform",
      "output": null,
      "status": "pass"
    },
    {
      "message": "+------------------------+--------+\n| GOT                    | CHECK  |\n+------------------------+--------+\n| )8e83993a7f55x0(YARRA1 | <HASH> |\n+------------------------+--------+",
      "name": "single letter",
      "output": null,
      "status": "fail"
    },
    {
      "message": "+------------------------+--------+\n| GOT                    | CHECK  |\n+------------------------+--------+\n| )0488d53a7f55x0(YARRA1 | <HASH> |\n+------------------------+--------+",
      "name": "single score with multiple letters",
      "output": null,
      "status": "fail"
    },
    {
      "message": "+----------------------------------------------+--------+\n| GOT                                          | CHECK  |\n+----------------------------------------------+--------+\n| )0447262a7f55x0(YARRA2)89b1a93a7f55x0(YARRA1 | <HASH> |\n+----------------------------------------------+--------+",
      "name": "multiple scores with multiple letters",
      "output": null,
      "status": "fail"
    },
    {
      "message": "+-----------------------------------------------------------------+--------+\n| GOT                                                             | CHECK  |\n+-----------------------------------------------------------------+--------+\n| )8877262a7f55x0(YARRA5)0757873a7f55x0(YARRA1)81e0562a7f55x0(YAR | <HASH> |\n| RA4)8c4a262a7f55x0(YARRA3)0d61262a7f55x0(YARRA2)0477262a7f55x0( |        |\n| YARRA8)8e47262a7f55x0(YARRA01                                   |        |\n+-----------------------------------------------------------------+--------+",
      "name": "multiple scores with differing numbers of letters",
      "output": null,
      "status": "fail"
    }
  ],
  "version": 2
}

Additionally the test runner is being changed, so it would be worth checking after test_code is added:

{
  "message": null,
  "status": "fail",
  "tests": [
    {
      "message": "# Failed test 'single letter'\n# at /solution/etl.t line 19.\n# +------------------------+--------+--------+\n# | GOT                    | CHECK  | LNs    |\n# +------------------------+--------+--------+\n# | )865c8ea15e55x0(YARRA1 | <HASH> | 15, 18 |\n# +------------------------+--------+--------+\n",
      "name": "single letter",
      "status": "fail",
      "test_code": "is( \n    transform(\n        {\n            1 => [\"A\"]\n        }\n    ),\n    hash {\n        field a => 1;\n        end;\n    },\n    \"single letter\",\n);"
    },
    {
      "message": "# Failed test 'single score with multiple letters'\n# at /solution/etl.t line 36.\n# +------------------------+--------+--------+\n# | GOT                    | CHECK  | LNs    |\n# +------------------------+--------+--------+\n# | )814c8ea15e55x0(YARRA1 | <HASH> | 28, 35 |\n# +------------------------+--------+--------+\n",
      "name": "single score with multiple letters",
      "status": "fail",
      "test_code": "is( \n    transform(\n        {\n            1 => [ \"A\", \"E\", \"I\", \"O\", \"U\" ]\n        }\n    ),\n    hash {\n        field a => 1;\n        field e => 1;\n        field i => 1;\n        field o => 1;\n        field u => 1;\n        end;\n    },\n    \"single score with multiple letters\",\n);"
    },
    {
      "message": "# Failed test 'multiple scores with multiple letters'\n# at /solution/etl.t line 53.\n# +----------------------------------------------+--------+--------+\n# | GOT                                          | CHECK  | LNs    |\n# +----------------------------------------------+--------+--------+\n# | )8d4c8ea15e55x0(YARRA2)82c6e8b15e55x0(YARRA1 | <HASH> | 46, 52 |\n# +----------------------------------------------+--------+--------+\n",
      "name": "multiple scores with multiple letters",
      "status": "fail",
      "test_code": "is( \n    transform(\n        {\n            1 => [ \"A\", \"E\" ],\n            2 => [ \"D\", \"G\" ]\n        }\n    ),\n    hash {\n        field a => 1;\n        field d => 2;\n        field e => 1;\n        field g => 2;\n        end;\n    },\n    \"multiple scores with multiple letters\",\n);"
    },
    {
      "message": "# Failed test 'multiple scores with differing numbers of letters'\n# at /solution/etl.t line 97.\n# +------------------------------------------------------+--------+--------+\n# | GOT                                                  | CHECK  | LNs    |\n# +------------------------------------------------------+--------+--------+\n# | )897a6ea15e55x0(YARRA1)033f1ab15e55x0(YARRA3)8cdf1ab | <HASH> | 68, 96 |\n# | 15e55x0(YARRA8)822f1ab15e55x0(YARRA2)0e6b54b15e55x0( |        |        |\n# | YARRA5)0150d4b15e55x0(YARRA01)0af6e8b15e55x0(YARRA4  |        |        |\n# +------------------------------------------------------+--------+--------+\n# failed 4 of 4 tests\n",
      "name": "multiple scores with differing numbers of letters",
      "status": "fail",
      "test_code": "is( \n    transform(\n        {\n            1  => [ \"A\", \"E\", \"I\", \"O\", \"U\", \"L\", \"N\", \"R\", \"S\", \"T\" ],\n            10 => [ \"Q\", \"Z\" ],\n            2  => [ \"D\", \"G\" ],\n            3  => [ \"B\", \"C\", \"M\", \"P\" ],\n            4  => [ \"F\", \"H\", \"V\", \"W\", \"Y\" ],\n            5  => [\"K\"],\n            8  => [ \"J\", \"X\" ]\n        }\n    ),\n    hash {\n        field a => 1;\n        field b => 3;\n        field c => 3;\n        field d => 2;\n        field e => 1;\n        field f => 4;\n        field g => 2;\n        field h => 4;\n        field i => 1;\n        field j => 8;\n        field k => 5;\n        field l => 1;\n        field m => 3;\n        field n => 1;\n        field o => 1;\n        field p => 3;\n        field q => 10;\n        field r => 1;\n        field s => 1;\n        field t => 1;\n        field u => 1;\n        field v => 4;\n        field w => 4;\n        field x => 8;\n        field y => 4;\n        field z => 10;\n        end;\n    },\n    \"multiple scores with differing numbers of letters\",\n);"
    }
  ],
  "version": 2
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants