Skip to content

Latest commit

 

History

History
357 lines (353 loc) · 9.05 KB

File metadata and controls

357 lines (353 loc) · 9.05 KB

Results of GPT-3.5 on HumanEval/137

Date: 18 July, 2023
Model: gpt-3.5-turbo
Temperature: 0.2
Passing runs: 0
Total runs: 10
Success rate: 0%

Prompt

Tokens: 167

def compare_one(a, b):
    """
    Create a function that takes integers, floats, or strings representing
    real numbers, and returns the larger variable in its given variable type.
    Return None if the values are equal.
    Note: If a real number is represented as a string, the floating point might be . or ,

    compare_one(1, 2.5) ➞ 2.5
    compare_one(1, "2,3") ➞ "2,3"
    compare_one("5,1", "6") ➞ "6"
    compare_one("1", 1) ➞ None
    """

The above is an incomplete Python code fragment. Return the complete and correct code with no additional text.

Correct solution

def compare_one(a, b):
    """
    Create a function that takes integers, floats, or strings representing
    real numbers, and returns the larger variable in its given variable type.
    Return None if the values are equal.
    Note: If a real number is represented as a string, the floating point might be . or ,

    compare_one(1, 2.5) ➞ 2.5
    compare_one(1, "2,3") ➞ "2,3"
    compare_one("5,1", "6") ➞ "6"
    compare_one("1", 1) ➞ None
    """temp_a, temp_b = a, b
    if isinstance(temp_a, str): temp_a = temp_a.replace(',','.')
    if isinstance(temp_b, str): temp_b = temp_b.replace(',','.')
    if float(temp_a) == float(temp_b): return None
    return a if float(temp_a) > float(temp_b) else b

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate(1, 2) == 2
    assert candidate(1, 2.5) == 2.5
    assert candidate(2, 3) == 3
    assert candidate(5, 6) == 6
    assert candidate(1, "2,3") == "2,3"
    assert candidate("5,1", "6") == "6"
    assert candidate("1", "2") == "2"
    assert candidate("1", 1) == None

    # Check some edge cases that are easy to work out by hand.
    assert True

Runs

❌ Run 1

Start time: 2023-07-18 17:05:42
Duration: 6.93s
Completion tokens: 188
Result: Fail

def compare_one(a, b):
    if isinstance(a, str) and isinstance(b, str):
        a = a.replace(",", ".")
        b = b.replace(",", ".")
        if float(a) > float(b):
            return a
        elif float(a) < float(b):
            return b
        else:
            return None
    elif isinstance(a, str):
        a = a.replace(",", ".")
        if float(a) > b:
            return a
        elif float(a) < b:
            return b
        else:
            return None
    elif isinstance(b, str):
        b = b.replace(",", ".")
        if a > float(b):
            return a
        elif a < float(b):
            return b
        else:
            return None
    else:
        if a > b:
            return a
        elif a < b:
            return b
        else:
            return None

❌ Run 2

Start time: 2023-07-18 17:05:38
Duration: 4.24s
Completion tokens: 120
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if type(a) == int or type(a) == float:
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif type(a) == str:
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 3

Start time: 2023-07-18 17:05:33
Duration: 4.7s
Completion tokens: 118
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if isinstance(a, int) or isinstance(a, float):
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif isinstance(a, str):
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 4

Start time: 2023-07-18 17:05:26
Duration: 6.94s
Completion tokens: 188
Result: Fail

def compare_one(a, b):
    if isinstance(a, str) and isinstance(b, str):
        a = a.replace(",", ".")
        b = b.replace(",", ".")
        if float(a) > float(b):
            return a
        elif float(a) < float(b):
            return b
        else:
            return None
    elif isinstance(a, str):
        a = a.replace(",", ".")
        if float(a) > b:
            return a
        elif float(a) < b:
            return b
        else:
            return None
    elif isinstance(b, str):
        b = b.replace(",", ".")
        if a > float(b):
            return a
        elif a < float(b):
            return b
        else:
            return None
    else:
        if a > b:
            return a
        elif a < b:
            return b
        else:
            return None

❌ Run 5

Start time: 2023-07-18 17:04:50
Duration: 36.05s
Completion tokens: 120
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if type(a) == int or type(a) == float:
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif type(a) == str:
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 6

Start time: 2023-07-18 17:04:45
Duration: 5.08s
Completion tokens: 118
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if isinstance(a, int) or isinstance(a, float):
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif isinstance(a, str):
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 7

Start time: 2023-07-18 17:04:40
Duration: 4.59s
Completion tokens: 118
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if isinstance(a, int) or isinstance(a, float):
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif isinstance(a, str):
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 8

Start time: 2023-07-18 17:04:35
Duration: 5.24s
Completion tokens: 120
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if type(a) == int or type(a) == float:
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif type(a) == str:
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 9

Start time: 2023-07-18 17:04:30
Duration: 4.93s
Completion tokens: 118
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if isinstance(a, int) or isinstance(a, float):
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif isinstance(a, str):
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None

❌ Run 10

Start time: 2023-07-18 17:04:25
Duration: 4.96s
Completion tokens: 118
Result: Fail

def compare_one(a, b):
    if type(a) == type(b):
        if isinstance(a, int) or isinstance(a, float):
            if a > b:
                return a
            elif a < b:
                return b
            else:
                return None
        elif isinstance(a, str):
            a = a.replace(",", ".")
            b = b.replace(",", ".")
            if float(a) > float(b):
                return a
            elif float(a) < float(b):
                return b
            else:
                return None
    else:
        return None