storj/cmd/tools/segment-verify/node_check_test.go
Ethan Adams 1c309a0318 cmd/tools/segment-verify: check for unvetted nodes
this also renames the command from `duplicates` to `node-check`

Change-Id: Idd303b17ec03f5b55fbbb1f4039a7761da37abe6
2022-12-19 09:59:13 +00:00

49 lines
1.1 KiB
Go

// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestBitSet(t *testing.T) {
b := newBitSet(4)
require.False(t, b.Include(0))
require.True(t, b.Include(0))
require.False(t, b.Include(3))
require.True(t, b.Include(3))
require.False(t, b.Include(2))
require.False(t, b.Include(1))
require.True(t, b.Include(1))
require.True(t, b.Include(2))
}
func TestBitSetRandom(t *testing.T) {
for width := 0; width < 66; width++ {
b := newBitSet(width)
checks := make([]int, 0, width*2)
for i := 0; i < width; i++ {
checks = append(checks, i, i)
}
rand.New(rand.NewSource(time.Now().UnixNano())).Shuffle(
len(checks), func(i, j int) { checks[i], checks[j] = checks[j], checks[i] })
for i := 0; i < 2; i++ {
correct := make(map[int]bool, width)
for _, check := range checks {
expected := correct[check]
correct[check] = true
require.Equal(t, expected, b.Include(check),
fmt.Sprintf("width: %d, check: %d", width, check))
}
b.Clear()
}
}
}