Skip to content

Reverse repair #22

@feixiangdejiahao

Description

@feixiangdejiahao

Sometime, program passes the example but also contains incorrect code branch. These incorrect branches aren't covered by examples. When doing reverse repair, it will introduce incorrect descriptions into requirement. Hidden tests will expose these incorrect branches.

original requirement

 def is_undulating(n: int) -> bool:
"""
Write a function to check whether the given number is undulating or not.
assert is_undulating(1212121) == True
"""

Repaired requirement

def is_undulating(n: int) -> bool:
    """
    Write a function to check whether the given number is undulating or not.
    An undulating number is defined as a number that strictly alternates between two distinct digits and must be at least 3 digits long.
    For example, 1212121 is an undulating number because it alternates between the digits 1 and 2.
    The function should return True if the number is undulating, otherwise False.

    Examples:
    >>> is_undulating(1212121)
    True
    >>> is_undulating(123123)
    False
    >>> is_undulating(112211)
    False
    >>> is_undulating(12)
    False
    """

Target program for reversing

def is_undulating(n: int) -> bool:
    s = str(n)
    if len(s) < 2:
        return False
    for i in range(1, len(s)):
        if i == 1:
            if s[i] == s[i - 1]:
                return False
        elif s[i] == s[i - 1] or (s[i] != s[i - 2] and i >= 2):
            return False
    return True

The repaired requirement adds the incorrect description strictly alternates between two distinct digits and must be at least 3 digits long.
Failed hidden tests:

[[input], [actual output], [Expected output]
[[82], [False], [True]],
[[40], [False], [True]], 
[[83], [False], [True]], 
[[39], [False], [True]], 
[[81], [False], [True]], 
[[41], [False], [True]], 
[[80], [False], [True]]

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