Skip to content

Commit 35e58f9

Browse files
committed
Add some tests of the counts package
Vendor in `stretchr/testify` to make this easier. This also necessitates some changes to the Makefile.
1 parent 55b9fa0 commit 35e58f9

File tree

25 files changed

+5519
-13
lines changed

25 files changed

+5519
-13
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/.gopath
22
/bin
3-
/vendor

Gopkg.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
#
33
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
44
# for detailed Gopkg.toml documentation.
5+
6+
[prune]
7+
unused-packages = true
8+
go-tests = true
9+
non-go = true

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ all: bin/git-sizer
2121
.PHONY: bin/git-sizer
2222
bin/git-sizer:
2323
mkdir -p bin
24-
$(GO) build $(GOFLAGS) -o $@ $(PACKAGE)
24+
cd $(GOPATH)/src/$(PACKAGE) && $(GO) build $(GOFLAGS) -o $(ROOTDIR)/$@ $(PACKAGE)
2525

2626
# Cross-compile for a bunch of common platforms. Note that this
2727
# doesn't work with USE_ISATTY:
@@ -43,7 +43,7 @@ define PLATFORM_template =
4343
.PHONY: bin/git-sizer-$(1)-$(2)$(3)
4444
bin/git-sizer-$(1)-$(2)$(3):
4545
mkdir -p bin
46-
GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -o $$@ $$(PACKAGE)
46+
cd $$(GOPATH)/src/$$(PACKAGE) && GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -o $$(ROOTDIR)/$$@ $$(PACKAGE)
4747
endef
4848

4949
$(eval $(call PLATFORM_template,linux,amd64))
@@ -60,7 +60,7 @@ test: bin/git-sizer gotest
6060

6161
.PHONY: gotest
6262
gotest:
63-
$(GO) test -timeout 60s $(GOFLAGS) ./...
63+
cd $(GOPATH)/src/$(PACKAGE) && $(GO) test -timeout 60s $(GOFLAGS) ./...
6464

6565
.PHONY: gofmt
6666
gofmt:

counts/counts.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func (n1 *Count32) Increment(n2 Count32) {
3333
*n1 = n1.Plus(n2)
3434
}
3535

36-
// Adjust `*n1` to be `max(*n1, n2)` and return true iff n2 was
37-
// bigger. Favor `*n1` if they are equal.
36+
// AdjustMaxIfNecessary adjusts `*n1` to be `max(*n1, n2)`. Return
37+
// true iff `n2` was greater than `*n1`.
3838
func (n1 *Count32) AdjustMaxIfNecessary(n2 Count32) bool {
3939
if n2 > *n1 {
4040
*n1 = n2
@@ -44,8 +44,8 @@ func (n1 *Count32) AdjustMaxIfNecessary(n2 Count32) bool {
4444
}
4545
}
4646

47-
// Adjust `*n1` to be `max(*n1, n2)` and return true iff n2 was
48-
// bigger. Favor `n2` if they are equal.
47+
// AdjustMaxIfPossible adjusts `*n1` to be `max(*n1, n2)`. Return true
48+
// iff `n2` was greater than or equal to `*n1`.
4949
func (n1 *Count32) AdjustMaxIfPossible(n2 Count32) bool {
5050
if n2 >= *n1 {
5151
*n1 = n2
@@ -81,8 +81,8 @@ func (n1 *Count64) Increment(n2 Count64) {
8181
*n1 = n1.Plus(n2)
8282
}
8383

84-
// Adjust `*n1` to be `max(*n1, n2)` and return true iff n2 was
85-
// bigger. Favor `*n1` if they are equal.
84+
// AdjustMaxIfNecessary adjusts `*n1` to be `max(*n1, n2)`. Return
85+
// true iff `n2` was greater than `*n1`.
8686
func (n1 *Count64) AdjustMaxIfNecessary(n2 Count64) bool {
8787
if n2 > *n1 {
8888
*n1 = n2
@@ -92,8 +92,8 @@ func (n1 *Count64) AdjustMaxIfNecessary(n2 Count64) bool {
9292
}
9393
}
9494

95-
// Adjust `*n1` to be `max(*n1, n2)` and return true iff n2 was
96-
// bigger. Favor `n2` if they are equal.
95+
// AdjustMaxIfPossible adjusts `*n1` to be `max(*n1, n2)`. Return true
96+
// iff `n2` was greater than or equal to `*n1`.
9797
func (n1 *Count64) AdjustMaxIfPossible(n2 Count64) bool {
9898
if n2 > *n1 {
9999
*n1 = n2

counts/counts_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package counts_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/github/git-sizer/counts"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestCount32(t *testing.T) {
12+
assert := assert.New(t)
13+
14+
c := counts.NewCount32(0)
15+
assert.Equalf(uint64(0), c.ToUint64(), "NewCount32(0).ToUint64() should be 0")
16+
17+
c.Increment(counts.Count32(0xf0000000))
18+
assert.Equalf(uint64(0xf0000000), c.ToUint64(), "Count32(0xf0000000).ToUint64() value")
19+
20+
c.Increment(counts.Count32(0xf0000000))
21+
assert.Equalf(uint64(0xffffffff), c.ToUint64(), "Count32(0xffffffff).ToUint64() value")
22+
}
23+
24+
func TestCount64(t *testing.T) {
25+
assert := assert.New(t)
26+
27+
c := counts.NewCount64(0)
28+
assert.Equalf(uint64(0), c.ToUint64(), "NewCount64(0).ToUint64() should be 0")
29+
30+
c.Increment(counts.Count64(0xf000000000000000))
31+
assert.Equalf(uint64(0xf000000000000000), c.ToUint64(), "Count64(0xf000000000000000).ToUint64() value")
32+
33+
c.Increment(counts.Count64(0xf000000000000000))
34+
assert.Equalf(uint64(0xffffffffffffffff), c.ToUint64(), "Count64(0xffffffffffffffff).ToUint64() value")
35+
}

vendor/github.com/davecgh/go-spew/LICENSE

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypass.go

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)