homelab/services/parts-inventory/api/node_modules/sparse-bitfield/test.js
Dan V deb6c38d7b chore: commit homelab setup — deployment, services, orchestration, skill
- Add .gitignore: exclude compiled binaries, build artifacts, and Helm
  values files containing real secrets (authentik, prometheus)
- Add all Kubernetes deployment manifests (deployment/)
- Add services source code: ha-sync, device-inventory, games-console,
  paperclip, parts-inventory
- Add Ansible orchestration: playbooks, roles, inventory, cloud-init
- Add hardware specs, execution plans, scripts, HOMELAB.md
- Add skills/homelab/SKILL.md + skills/install.sh to preserve Copilot skill
- Remove previously-tracked inventory-cli binary from git index

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-09 08:10:32 +02:00

79 lines
1.9 KiB
JavaScript

var alloc = require('buffer-alloc')
var tape = require('tape')
var bitfield = require('./')
tape('set and get', function (t) {
var bits = bitfield()
t.same(bits.get(0), false, 'first bit is false')
bits.set(0, true)
t.same(bits.get(0), true, 'first bit is true')
t.same(bits.get(1), false, 'second bit is false')
bits.set(0, false)
t.same(bits.get(0), false, 'first bit is reset')
t.end()
})
tape('set large and get', function (t) {
var bits = bitfield()
t.same(bits.get(9999999999999), false, 'large bit is false')
bits.set(9999999999999, true)
t.same(bits.get(9999999999999), true, 'large bit is true')
t.same(bits.get(9999999999999 + 1), false, 'large bit + 1 is false')
bits.set(9999999999999, false)
t.same(bits.get(9999999999999), false, 'large bit is reset')
t.end()
})
tape('get and set buffer', function (t) {
var bits = bitfield({trackUpdates: true})
t.same(bits.pages.get(0, true), undefined)
t.same(bits.pages.get(Math.floor(9999999999999 / 8 / 1024), true), undefined)
bits.set(9999999999999, true)
var bits2 = bitfield()
var upd = bits.pages.lastUpdate()
bits2.pages.set(Math.floor(upd.offset / 1024), upd.buffer)
t.same(bits2.get(9999999999999), true, 'bit is set')
t.end()
})
tape('toBuffer', function (t) {
var bits = bitfield()
t.same(bits.toBuffer(), alloc(0))
bits.set(0, true)
t.same(bits.toBuffer(), bits.pages.get(0).buffer)
bits.set(9000, true)
t.same(bits.toBuffer(), Buffer.concat([bits.pages.get(0).buffer, bits.pages.get(1).buffer]))
t.end()
})
tape('pass in buffer', function (t) {
var bits = bitfield()
bits.set(0, true)
bits.set(9000, true)
var clone = bitfield(bits.toBuffer())
t.same(clone.get(0), true)
t.same(clone.get(9000), true)
t.end()
})
tape('set small buffer', function (t) {
var buf = alloc(1)
buf[0] = 255
var bits = bitfield(buf)
t.same(bits.get(0), true)
t.same(bits.pages.get(0).buffer.length, bits.pageSize)
t.end()
})