Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage to 100% #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.out
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ Once you have [installed Go][golang-install], run this command
to install the `bit` package:

go get github.com/yourbasic/bit


### Testing

go test -v -coverprofile coverage.out && go tool cover -html coverage.out -o coverage.html

### Benchmarking

go test -bench . -benchmem -cpu 1

### Documentation

There is an online reference for the package at
Expand Down
8 changes: 7 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package bit_test

import (
"fmt"
"github.com/yourbasic/bit"
"math"

"github.com/yourbasic/bit"
)

// Create, combine, compare and print bit sets.
Expand All @@ -25,7 +26,12 @@ func Example_basics() {
if X.Equal(Y) {
fmt.Println(X)
}

// Compute A ∩ B
Z := A.And(B)
fmt.Println(Z)
// Output: {1..49 100..149 200}
// {0 50..99}
}

// Create the set of all primes less than n in O(n log log n) time.
Expand Down
1 change: 1 addition & 0 deletions example_union_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bit_test

import (
"fmt"

"github.com/yourbasic/bit"
)

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/yourbasic/bit

go 1.9
6 changes: 3 additions & 3 deletions set.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//go:build !go1.9
// +build !go1.9

// Package bit provides a bit array implementation.
//
// Bit set
// # Bit set
//
// A bit set, or bit array, is an efficient set data structure
// that consists of an array of 64-bit words. Because it uses
// bit-level parallelism, limits memory access, and efficiently uses
// the data cache, a bit set often outperforms other data structures.
//
// Tutorial
// # Tutorial
//
// The Basics example shows how to create, combine, compare and
// print bit sets.
Expand All @@ -19,7 +20,6 @@
//
// Union is a more advanced example demonstrating how to build
// an efficient variadic Union function using the SetOr method.
//
package bit

import (
Expand Down
6 changes: 3 additions & 3 deletions set_1_10.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//go:build go1.10
// +build go1.10

// Package bit provides a bit array implementation.
//
// Bit set
// # Bit set
//
// A bit set, or bit array, is an efficient set data structure
// that consists of an array of 64-bit words. Because it uses
// bit-level parallelism, limits memory access, and efficiently uses
// the data cache, a bit set often outperforms other data structures.
//
// Tutorial
// # Tutorial
//
// The Basics example shows how to create, combine, compare and
// print bit sets.
Expand All @@ -19,7 +20,6 @@
//
// Union is a more advanced example demonstrating how to build
// an efficient variadic Union function using the SetOr method.
//
package bit

import (
Expand Down
9 changes: 4 additions & 5 deletions set_1_9.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// +build go1.9
// +build !go1.10
//go:build go1.9 && !go1.10
// +build go1.9,!go1.10

// Package bit provides a bit array implementation.
//
// Bit set
// # Bit set
//
// A bit set, or bit array, is an efficient set data structure
// that consists of an array of 64-bit words. Because it uses
// bit-level parallelism, limits memory access, and efficiently uses
// the data cache, a bit set often outperforms other data structures.
//
// Tutorial
// # Tutorial
//
// The Basics example shows how to create, combine, compare and
// print bit sets.
Expand All @@ -20,7 +20,6 @@
//
// Union is a more advanced example demonstrating how to build
// an efficient variadic Union function using the SetOr method.
//
package bit

import (
Expand Down
8 changes: 4 additions & 4 deletions set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ func TestVisit(t *testing.T) {
t.Errorf("%v.Visit(func(n int) { s.DeleteRange(0, n+1); s += Itoa(n) }) -> s=%q; want %q", s, res, x.res)
}
}
s := New(1, 2)
s := New(1, 2, 3)
count := 0
aborted := s.Visit(func(n int) (skip bool) {
count++
if n == 1 {
if n == 2 {
skip = true
return
}
Expand All @@ -312,7 +312,7 @@ func TestVisit(t *testing.T) {
if aborted == false {
t.Errorf("Visit returned false when aborted.")
}
if count > 1 {
if count > 2 {
t.Errorf("Visit didn't abort.")
}
count = 0
Expand All @@ -323,7 +323,7 @@ func TestVisit(t *testing.T) {
if aborted == true {
t.Errorf("Visit returned true when not aborted.")
}
if count != 2 {
if count != 3 {
t.Errorf("Visit aborted.")
}
}
Expand Down