File: utils_test.go

package info (click to toggle)
fq 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 106,624 kB
  • sloc: xml: 2,835; makefile: 250; sh: 241; exp: 57; ansic: 21
file content (88 lines) | stat: -rw-r--r-- 1,939 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package common_test

import (
	"testing"

	"github.com/wader/fq/format/postgres/common"
)

func TestTypeAlign(t *testing.T) {
	expected0 := common.TypeAlign(8192, 8192+0)
	if expected0 != 8192 {
		t.Errorf("must be 8192\n")
	}

	expected1 := common.TypeAlign(8192, 8192+100)
	if expected1 != 8192*2 {
		t.Errorf("must be 8192*2\n")
	}

	expected2 := common.TypeAlign(8192, 0)
	if expected2 != 0 {
		t.Errorf("must be 0\n")
	}

	expected3 := common.TypeAlign(8192, 700)
	if expected3 != 8192 {
		t.Errorf("must be 8192\n")
	}

	expected4 := common.TypeAlign(8192, 8192*2+5000)
	if expected4 != 8192*3 {
		t.Errorf("must be 8192*3\n")
	}

	expected5 := common.TypeAlign(8192, 114720)
	if expected5 != 122880 {
		t.Errorf("must be 8192*3\n")
	}
}

func TestTypeAlign8(t *testing.T) {
	expected39 := common.TypeAlign8(39)
	if expected39 != 40 {
		t.Errorf("must be 40\n")
	}
	expected41 := common.TypeAlign8(41)
	if expected41 != 48 {
		t.Errorf("must be 40\n")
	}
}

func TestRoundDown(t *testing.T) {
	const pageSize1 = 8192
	expected1 := common.RoundDown(pageSize1, 7*pageSize1+35)
	if expected1 != 7*pageSize1 {
		t.Errorf("must be %d\n", 7*pageSize1)
	}
	expected2 := common.RoundDown(pageSize1, 7*pageSize1-1)
	if expected2 != 6*pageSize1 {
		t.Errorf("must be %d\n", 6*pageSize1)
	}

	const pageSize2 = 7744
	expected3 := common.RoundDown(pageSize2, 15*pageSize2+61)
	if expected3 != 15*pageSize2 {
		t.Errorf("must be %d\n", 15*pageSize2)
	}
	expected4 := common.RoundDown(pageSize2, 3*pageSize2-15)
	if expected4 != 2*pageSize2 {
		t.Errorf("must be %d\n", 2*pageSize2)
	}

	expected5 := common.RoundDown(pageSize1, 5*pageSize1)
	if expected5 != 5*pageSize1 {
		t.Errorf("must be %d\n", 5*pageSize1)
	}
}

func TestIsMaskSet(t *testing.T) {
	m1 := common.IsMaskSet(0xff+0x1221000, 0xf0)
	if m1 != 1 {
		t.Errorf("mask must be set\n")
	}
	m2 := common.IsMaskSet(0xff+0x1221000, 0xf00)
	if m2 != 0 {
		t.Errorf("mask must be 0\n")
	}
}