Skip to content

Commit

Permalink
Introduce property tests using fast-check
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Jun 12, 2019
1 parent df4cbf6 commit 5d308d5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@typescript-eslint/eslint-plugin": "^1.10.2",
"@typescript-eslint/parser": "^1.10.2",
"eslint": "^5.16.0",
"fast-check": "^1.15.1",
"jest": "^24.8.0",
"prettier": "^1.18.2",
"ts-jest": "^24.0.2",
Expand All @@ -43,4 +44,4 @@
"js"
]
}
}
}
25 changes: 25 additions & 0 deletions src/List.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fc from 'fast-check';
import List from './List';

test('List.empty isEmpty', () => {
Expand Down Expand Up @@ -62,3 +63,27 @@ test('List.drop works', () => {
expect(simple.drop(3).equals(empty)).toBe(true);
expect(simple.drop(1).equals(List.of(2, 3))).toBe(true);
});

test('List.prepend properties', () => {
fc.assert(
fc.property(fc.array(fc.integer()), data => {
const list = List.of(...data);
const value = 1;
const extra = list.prepend(value);
expect(extra.tail().equals(list)).toBe(true);
expect(extra.head()).toBe(value);
})
);
});

test('List.take properties', () => {
const gen = fc.tuple(fc.array(fc.integer()), fc.nat());
fc.assert(
fc.property(gen, ([items, amount]) => {
const list = List.of(items);
const arr = Array.from(list.take(amount));
arr.push(...list.drop(amount));
expect(List.of(...arr).equals(list)).toBe(true);
})
);
});

0 comments on commit 5d308d5

Please sign in to comment.