File: counts_test.go

package info (click to toggle)
git-sizer 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 300 kB
  • sloc: sh: 98; makefile: 80
file content (53 lines) | stat: -rw-r--r-- 1,711 bytes parent folder | download | duplicates (2)
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
package counts_test

import (
	"testing"

	"github.com/github/git-sizer/counts"

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

func TestCount32(t *testing.T) {
	assert := assert.New(t)

	var value uint64
	var overflow bool

	c := counts.NewCount32(0)
	value, overflow = c.ToUint64()
	assert.Equalf(uint64(0), value, "NewCount32(0).ToUint64() should be 0")
	assert.False(overflow, "NewCount32(0).ToUint64() does not overflow")

	c.Increment(counts.Count32(0xf0000000))
	value, overflow = c.ToUint64()
	assert.Equalf(uint64(0xf0000000), value, "Count32(0xf0000000).ToUint64() value")
	assert.False(overflow, "NewCount32(0xf0000000).ToUint64() does not overflow")

	c.Increment(counts.Count32(0xf0000000))
	value, overflow = c.ToUint64()
	assert.Equalf(uint64(0xffffffff), value, "Count32(0xffffffff).ToUint64() value")
	assert.True(overflow, "NewCount32(0xffffffff).ToUint64() overflows")
}

func TestCount64(t *testing.T) {
	assert := assert.New(t)

	var value uint64
	var overflow bool

	c := counts.NewCount64(0)
	value, overflow = c.ToUint64()
	assert.Equalf(uint64(0), value, "NewCount64(0).ToUint64() should be 0")
	assert.False(overflow, "NewCount64(0).ToUint64() does not overflow")

	c.Increment(counts.Count64(0xf000000000000000))
	value, overflow = c.ToUint64()
	assert.Equalf(uint64(0xf000000000000000), value, "Count64(0xf000000000000000).ToUint64() value")
	assert.False(overflow, "NewCount64(0xf000000000000000).ToUint64() does not overflow")

	c.Increment(counts.Count64(0xf000000000000000))
	value, overflow = c.ToUint64()
	assert.Equalf(uint64(0xffffffffffffffff), value, "Count64(0xffffffffffffffff).ToUint64() value")
	assert.True(overflow, "NewCount64(0xffffffffffffffff).ToUint64() overflows")
}