Skip to content

Inconsistent test cases in the Hamming exercise #1666

Closed
@HenryRLee

Description

@HenryRLee

In #1450, two tests cases are added to the Hamming exercise. If one of the argument is empty, it throws an exception with message "[left|right] strand must not be empty":

    {
      "description": "disallow left empty strand",
      "property": "distance",
      "input": {
        "strand1": "",
        "strand2": "G"
      },
      "expected": {"error": "left strand must not be empty"}
    },
    {
      "description": "disallow right empty strand",
      "property": "distance",
      "input": {
        "strand1": "G",
        "strand2": ""
      },
      "expected": {"error": "right strand must not be empty"}
    }

This message apparently contradicts with the first test case, where both arguments are empty, it runs without any exceptions:

    {
      "description": "empty strands",
      "property": "distance",
      "input": {
        "strand1": "",
        "strand2": ""
      },
      "expected": 0
    }

In my opinion, the error messages in these two cases, should be identical to the other different length exceptions, i.e. "left and right strands must be of equal length":

    {
      "description": "disallow first strand longer",
      "property": "distance",
      "input": {
        "strand1": "AATG",
        "strand2": "AAA"
      },
      "expected": {"error": "left and right strands must be of equal length"}
    }

A significant issue from the current test case is the exercise from the Java track, in order to pass all the test cases, I have to do:

// Only throw this if left strand is empty and right strand is not
if (leftStrand.isEmpty() && !rightStrand.isEmpty())
    throw new IllegalArgumentException("left strand must not be empty.");

// Only throw this if right strand is empty and left strand is not
if (rightStrand.isEmpty() && !leftStrand.isEmpty())
    throw new IllegalArgumentException("right strand must not be empty.");

if (leftStrand.length() != rightStrand.length())
    throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length.");

where the condition and the message is not very consistent..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions