import os

os.environ["CODEFLASH_API_KEY"] = "cf-test-key"
from codeflash_python.testing._testgen import merge_unit_tests


def test_merge_unit_tests_pytest():
    unit_tests = """
import time
import gc
from code_to_optimize.tsp import tsp
import pytest
import math
import sys
import itertools

def distance_between(city1: tuple, city2: tuple) -> float:
    return math.hypot(city1[0] - city2[0], city1[1] - city2[1])

def test_tsp_decimal_coordinates():
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp([(0.5, 0.5), (1.5, 1.5), (2.5, 2.5)])
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_decimal_coordinates_0')

def test_tsp_large_coordinate_values():
    cities = [(1000000, 1000000), (2000000, 2000000), (3000000, 3000000)]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_large_coordinate_values_1')
    """

    inspired_test = """
import pytest
import math
import sys
import itertools

def distance_between(city1: tuple, city2: tuple) -> float:
    return math.hypot(city1[0] - city2[0], city1[1] - city2[1])

def tsp(cities: list[list[int]]):
    permutations = itertools.permutations(cities)
    min_distance = sys.maxsize
    optimal_route = []
    for permutation in permutations:
        distance = 0
        for i in range(len(permutation) - 1):
            distance += distance_between(permutation[i], permutation[i + 1])
        distance += distance_between(permutation[-1], permutation[0])
        if distance < min_distance:
            min_distance = distance
            optimal_route = permutation
    return (optimal_route, min_distance)

def test_tsp_more_cities():
    cities = [[1, 2], [3, 4], [5, 6], [-3, 4], [0, 0]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_more_cities__inspired_1')

def test_tsp_three_cities():
    cities = [[1, 2], [3, 4], [5, 6]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_three_cities__inspired_1')

def test_tsp_single_city():
    cities = [[1, 2]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_single_city__inspired_1')

def test_tsp_empty_cities():
    cities = []
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_empty_cities__inspired_1')

def test_tsp_duplicate_cities():
    cities = [[1, 2], [3, 4], [1, 2], [3, 4]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_duplicate_cities__inspired_1')

def test_tsp_negative_coordinates():
    cities = [[-1, -2], [-3, -4], [-5, -6]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_negative_coordinates__inspired_1')
    """
    expected = """import pytest
import math
import sys
import itertools
import time
import gc
from code_to_optimize.tsp import tsp
import pytest
import math
import sys
import itertools

def distance_between(city1: tuple, city2: tuple) -> float:
    return math.hypot(city1[0] - city2[0], city1[1] - city2[1])

def test_tsp_decimal_coordinates():
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp([(0.5, 0.5), (1.5, 1.5), (2.5, 2.5)])
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_decimal_coordinates_0')

def test_tsp_large_coordinate_values():
    cities = [(1000000, 1000000), (2000000, 2000000), (3000000, 3000000)]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_large_coordinate_values_1')

def distance_between(city1: tuple, city2: tuple) -> float:
    return math.hypot(city1[0] - city2[0], city1[1] - city2[1])

def tsp(cities: list[list[int]]):
    permutations = itertools.permutations(cities)
    min_distance = sys.maxsize
    optimal_route = []
    for permutation in permutations:
        distance = 0
        for i in range(len(permutation) - 1):
            distance += distance_between(permutation[i], permutation[i + 1])
        distance += distance_between(permutation[-1], permutation[0])
        if distance < min_distance:
            min_distance = distance
            optimal_route = permutation
    return (optimal_route, min_distance)

def test_tsp_more_cities__inspired():
    cities = [[1, 2], [3, 4], [5, 6], [-3, 4], [0, 0]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_more_cities__inspired_1')

def test_tsp_three_cities__inspired():
    cities = [[1, 2], [3, 4], [5, 6]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_three_cities__inspired_1')

def test_tsp_single_city__inspired():
    cities = [[1, 2]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_single_city__inspired_1')

def test_tsp_empty_cities__inspired():
    cities = []
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_empty_cities__inspired_1')

def test_tsp_duplicate_cities__inspired():
    cities = [[1, 2], [3, 4], [1, 2], [3, 4]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_duplicate_cities__inspired_1')

def test_tsp_negative_coordinates__inspired():
    cities = [[-1, -2], [-3, -4], [-5, -6]]
    gc.disable()
    counter = time.perf_counter_ns()
    return_value = tsp(cities)
    duration = time.perf_counter_ns() - counter
    gc.enable()
    _log__test__values(return_value, duration, 'tsp_test_tsp_negative_coordinates__inspired_1')"""
    modified_file = merge_unit_tests(unit_tests, inspired_test)
    assert modified_file == expected
