UNPKG

fast-check

Version:

Property based testing framework for JavaScript (like QuickCheck)

30 lines (29 loc) 847 B
import { safeAdd, safePush, Set } from '../../../utils/globals.js'; const safeNumberIsNaN = Number.isNaN; export class StrictlyEqualSet { constructor(selector) { this.selector = selector; this.selectedItemsExceptNaN = new Set(); this.data = []; } tryAdd(value) { const selected = this.selector(value); if (safeNumberIsNaN(selected)) { safePush(this.data, value); return true; } const sizeBefore = this.selectedItemsExceptNaN.size; safeAdd(this.selectedItemsExceptNaN, selected); if (sizeBefore !== this.selectedItemsExceptNaN.size) { safePush(this.data, value); return true; } return false; } size() { return this.data.length; } getData() { return this.data; } }