File: bits_test.go

package info (click to toggle)
golang-github-kentik-patricia 0.0~git20200128.c35d94c-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,368 kB
  • sloc: makefile: 38
file content (40 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package patricia

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestLeftMasks(t *testing.T) {
	// 32-bit
	assert.Equal(t, uint32(0), _leftMasks32[0])
	assert.Equal(t, uint32(0x80000000), _leftMasks32[1])
	assert.Equal(t, uint32(0xC0000000), _leftMasks32[2])
	assert.Equal(t, uint32(0xE0000000), _leftMasks32[3])
	assert.Equal(t, uint32(0xF0000000), _leftMasks32[4])
	assert.Equal(t, uint32(0xFFFFFFFE), _leftMasks32[31])
	assert.Equal(t, uint32(0xFFFFFFFF), _leftMasks32[32])

	// 64-bit
	assert.Equal(t, uint64(0), _leftMasks64[0])
	assert.Equal(t, uint64(0x8000000000000000), _leftMasks64[1])
	assert.Equal(t, uint64(0xC000000000000000), _leftMasks64[2])
	assert.Equal(t, uint64(0xE000000000000000), _leftMasks64[3])
	assert.Equal(t, uint64(0xF000000000000000), _leftMasks64[4])
	assert.Equal(t, uint64(0xFFFFFFFE00000000), _leftMasks64[31])
	assert.Equal(t, uint64(0xFFFFFFFF00000000), _leftMasks64[32])
	assert.Equal(t, uint64(0xFFFFFFFF80000000), _leftMasks64[33])
	assert.Equal(t, uint64(0xFFFFFFFFFFFFFFFE), _leftMasks64[63])
	assert.Equal(t, uint64(0xFFFFFFFFFFFFFFFF), _leftMasks64[64])
}

func TestMergePrefixes32(t *testing.T) {
	newPrefix, newLength := MergePrefixes32(uint32(0x88803000), uint(4), uint32(0x8FE30000), uint(4))
	assert.Equal(t, uint32(0x88000000), newPrefix)
	assert.Equal(t, uint(8), newLength)

	newPrefix, newLength = MergePrefixes32(uint32(0x80000000), 4, uint32(0xFFFFFFFF), 0)
	assert.Equal(t, uint32(0x80000000), newPrefix)
	assert.Equal(t, uint(4), newLength)
}