Skip to content

list-ops: division operator is ambiguous #1467

Closed
@juhlig

Description

@juhlig

{
"description": "direction dependent function applied to non-empty list",
"property": "foldl",
"input": {
"list": [2, 5],
"initial": 5,
"function": "(x, y) -> x / y"
},
"expected": 0
}

{
"description": "direction dependent function applied to non-empty list",
"property": "foldr",
"input": {
"list": [2, 5],
"initial": 5,
"function": "(x, y) -> x / y"
},
"expected": 2
}

The two cases instruct the test implementation to apply the division operator / to the two arguments of the function used for folding.

This operator is ambiguous, depending on language and circumstances. There are languages which always do floating-point division with / and have a separate operator for integer division (eg div in Erlang), others do integer division if both operands are integers and float division only if at least one operand is a float, etc.

The current test cases in question assume integer division, but this is not obvious, only if you (as a human) read the test arguments and expected outcome carefully. For a test generator on the other hand, it is quite difficult.

As finding a language-agnostic way to explicitly specify integer division would pose rather difficult, I suggest to alter the test cases to use another direction-dependent but unambiguous operation instead, like -.

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