DefinitelyTyped/types/weighted/weighted-tests.ts
Piotr Błażejewicz (Peter Blazejewicz) 7b855576c6
update(weighted): DT definition changes (#45939)
This adds changes discussed in merged PR:
`#45633

- CommonJS module shape
- proper alias for select
- TS config and TSLint config updated to just follow DT defaults
- tests amended with modern syntax - but still using existing tests

Thanks!
2020-07-10 08:43:13 -07:00

38 lines
1.1 KiB
TypeScript

/// <reference lib="dom" />
import weighted = require('weighted');
import { select } from 'weighted';
function testSet() {
const options = ['Wake Up', 'Snooze Alarm'];
const weights = [0.25, 0.75];
console.log('Decision:', weighted(options, weights));
console.log('Decision:', weighted.select(options, weights));
console.log('Decision:', select(options, weights));
}
function testObj() {
const options = {
'Wake Up': 0.25,
'Snooze Alarm': 0.75,
};
console.log('Decision:', weighted(options));
console.log('Decision:', weighted.select(options));
console.log('Decision:', select(options));
}
function testOverrideRand() {
const options = ['Wake Up', 'Snooze Alarm'];
const weights = [0.25, 0.75];
function rand() {
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
console.log('Decision:', weighted(options, weights, rand));
console.log('Decision:', weighted.select(options, weights, rand));
console.log('Decision:', select(options, weights, rand));
}