PBT 2021 の到来 - 20 日目
5076 ワード
Advent of PBT 2021 — Learn how to use property based testing and fast-check through examples
今日のアルゴリズムは drawTree です.
次のドキュメントとプロトタイプが付属しています.
/**
* Draw a tree with:
* - a trunc made of '^',
* - leaves on the left made of '('
* - and the ones on the right made of ')'
*
* @param size - Size of the tree >=1
*/
declare function drawTree(size: number): string;
すでにいくつかの例に基づいたテストを書いています:
it("should be able to draw a tree of size 1", () => {
// prettier-ignore
expect(drawTree(1)).toEqual(
"^\n" +
"^\n" +
"^"
);
});
it("should be able to draw a tree of size 2", () => {
// prettier-ignore
expect(drawTree(2)).toEqual(
" ^\n" +
"(^)\n" +
" ^\n" +
" ^"
);
});
it("should be able to draw a tree of size 5", () => {
// prettier-ignore
expect(drawTree(5)).toEqual(
" ^\n" +
" (^)\n" +
" ((^))\n" +
" (((^)))\n" +
"((((^))))\n" +
" ^\n" +
" ^"
);
});
プロパティベースのテストでどのようにカバーしますか?
作業を容易にするために、既にセットアップされた CodeSandbox を提供します.例に基づいたテストが既に作成されており、アルゴリズムの実装が可能です: https://codesandbox.io/s/advent-of-pbt-day-20-61ylb?file=/src/index.spec.ts&previewwindow=tests
解決策を見たいですか?今日のアルゴリズムをカバーするために私が持ってきたプロパティのセットは次のとおりです.
他の日に取り上げられたトピックとその解決策を確認するには.
このシリーズの詳細については、ハッシュタグ .
Reference
この問題について(PBT 2021 の到来 - 20 日目), 我々は、より多くの情報をここで見つけました https://dev.to/dubzzz/advent-of-pbt-2021-day-20-31a3テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol