PBT 2021의 도래 - Day 9

Advent of PBT 2021 — Learn how to use property based testing and fast-check through examples



오늘날 우리의 알고리즘은 다음과 같습니다.
다음 문서 및 프로토타입과 함께 제공됩니다.

/**
 * Build a sorted version of the passed array by relying
 * on "<" comparison.
 *
 * @param tab - Original array to be sorted
 *
 * @returns
 * Sorted copy of the original array.
 */
declare function sorted<T>(tab: T[]): T[];


우리는 이미 이에 대한 몇 가지 예제 기반 테스트를 작성했습니다.

it("should keep sorted array sorted", () => {
  expect(sorted([1, 2, 3])).toEqual([1, 2, 3]);
});

it("should sort reverse-sorted array", () => {
  expect(sorted([3, 2, 1])).toEqual([1, 2, 3]);
});

it("should sort any array", () => {
  expect(sorted([5, 2, 3, 1, 8])).toEqual([1, 2, 3, 5, 8]);
});


속성 기반 테스트로 그것을 어떻게 다루겠습니까?

작업을 쉽게 하기 위해 이미 작성된 예제 기반 테스트와 알고리즘 구현이 포함된 이미 설정된 CodeSandbox를 제공합니다. https://codesandbox.io/s/advent-of-pbt-day-9-mxzok?file=/src/index.spec.ts&previewwindow=tests

해결책을 보고 싶습니까? 다음은 오늘의 알고리즘을 다루기 위해 가져온 속성 집합입니다.


다른 날에 다룬 주제와 솔루션을 확인합니다.

이 시리즈에 대한 자세한 내용은 해시태그 .

좋은 웹페이지 즐겨찾기