빠른 정렬 단위 테스트 생성

지정된 Python 함수의 단위 테스트를 생성합니다.

모델을 직접 쿼리하고 Cloud 콘솔에서 다른 매개변수 값을 사용하거나 Vertex AI API를 직접 호출하여 반환된 결과를 테스트할 수 있습니다.

자유 형식 프롬프트


Create unit tests for the following quick_sort function.

```python
def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    else:
        pivot = arr[0]
        left = [x for x in arr[1:] if x < pivot]
        right = [x for x in arr[1:] if x >= pivot]
        return quick_sort(left) + [pivot] + quick_sort(right)
```

                

응답


```python
import unittest

class QuickSortTest(unittest.TestCase):

def test_empty_array(self):
self.assertEqual(quick_sort([]), [])

def test_single_element_array(self):
self.assertEqual(quick_sort([1]), [1])

def test_sorted_array(self):
self.assertEqual(quick_sort([1, 2, 3, 4, 5]), [1, 2, 3, 4, 5])

def test_unsorted_array(self):
self.assertEqual(quick_sort([5, 2, 1, 3, 4]), [1, 2, 3, 4, 5])

def test_array_with_duplicates(self):
self.assertEqual(quick_sort([5, 2, 1, 3, 4, 5]), [1, 2, 3, 4, 5, 5])

def test_large_array(self):
arr = [i for i in range(1000)]
self.assertEqual(quick_sort(arr), arr)

```

              
모델: gemini-1.0-pro-001
강도: 0.2
최대 출력 토큰: 2048
최상위 K: 40
최상위 P: 0.95