-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #634 from jimmywarting/feature/modernize-bitset
Feature/modernize bitset
- Loading branch information
Showing
2 changed files
with
121 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,69 @@ | ||
'use strict'; | ||
|
||
var claire = require('claire'); | ||
const claire = require('claire'); | ||
const {BitSet} = require('../lib/bitset'); | ||
|
||
var forAll = claire.forAll, | ||
arb = claire.data, | ||
label = claire.label, | ||
choice = claire.choice, | ||
transform = claire.transform; | ||
const { | ||
forAll, | ||
data: arb, | ||
label, | ||
choice, | ||
transform | ||
} = claire; | ||
|
||
var BitSet = require('../lib/bitset').BitSet; | ||
var PosInt = transform(Math.floor, arb.Positive); | ||
const PosInt = transform(Math.floor, arb.Positive); | ||
|
||
var EmptyBitSet = label('bitset', transform( | ||
function(size) { | ||
const EmptyBitSet = label('bitset', transform( | ||
size => { | ||
return new BitSet(size); | ||
}, | ||
choice(arb.Nothing, PosInt))); | ||
|
||
suite('BitSet', function() { | ||
suite('BitSet', () => { | ||
|
||
test('get bit', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { | ||
.satisfy((b, bit) => { | ||
b.set(bit); | ||
return b.get(bit); | ||
}).asTest()); | ||
|
||
test('clear bit', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { | ||
.satisfy((b, bit) => { | ||
b.set(bit); | ||
b.clear(bit); | ||
return !b.get(bit); | ||
}).asTest()); | ||
|
||
test('next set of empty', forAll(EmptyBitSet) | ||
.satisfy(function(b) { | ||
.satisfy(b => { | ||
return b.nextSetBit(0) === -1; | ||
}).asTest()); | ||
|
||
test('next set of one bit', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { | ||
.satisfy((b, bit) => { | ||
b.set(bit); | ||
return b.nextSetBit(0) === bit; | ||
}).asTest()); | ||
|
||
test('next set same bit', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { | ||
.satisfy((b, bit) => { | ||
b.set(bit); | ||
return b.nextSetBit(bit) === bit; | ||
}).asTest()); | ||
|
||
test('next set following bit', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { | ||
.satisfy((b, bit) => { | ||
b.set(bit); | ||
return b.nextSetBit(bit+1) === -1; | ||
}).asTest()); | ||
|
||
test('next clear of empty', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { return b.nextClearBit(bit) === bit; }) | ||
.satisfy((b, bit) => { return b.nextClearBit(bit) === bit; }) | ||
.asTest()); | ||
|
||
test('next clear of one set', forAll(EmptyBitSet, PosInt) | ||
.satisfy(function(b, bit) { | ||
.satisfy((b, bit) => { | ||
b.set(bit); | ||
return b.nextClearBit(bit) === bit + 1; | ||
}).asTest()); | ||
|
||
}); |