Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
[#46] Added examples for Toggle
Browse files Browse the repository at this point in the history
One 'simple' example which uses 000 and 1011

One regular example with the output bada55
  • Loading branch information
Gman98ish committed Oct 31, 2017
1 parent 161495f commit 1d56d10
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DEFAULT_GOAL := test

test: ## Start tests
@go test -coverprofile=/tmp/byteslice-cover .

bench: ## Start benchmark
@go test -bench=. .

help: ## Print this message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: bench help test
6 changes: 4 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ image:https://coveralls.io/repos/github/rlespinasse/byteslice/badge.svg?branch=m

== How to

Run `make help` to see the available commands.

=== test it with coverage

[source,shell]
-----
$ go test -coverprofile=/tmp/byteslice-cover .
$ make test
ok github.com/rlespinasse/byteslice 0.007s coverage: 100.0% of statements
-----

=== launch the benchmark

[source,shell]
-----
$ go test -bench=. .
$ make bench
goos: ...
goarch: ...
pkg: github.com/rlespinasse/byteslice
Expand Down
20 changes: 19 additions & 1 deletion example_byteslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@ func ExampleReverse() {

func ExampleLPad() {
data := []byte{0x55, 0xDA, 0xBA}

fmt.Printf("%x\n", LPad(data, 5, 0x22))
// Output: 222255daba
}

func ExampleToggle() {
data := []byte{0xbb, 0xdb, 0x54}
toggle := []byte{0x01, 0x01, 0x01}

output, _ := Toggle(data, toggle)
fmt.Printf("%x\n", output)
// Output: bada55
}

func ExampleToggle_simple() {
data := []byte{0x00, 0x01, 0x00}
toggle := []byte{0x01, 0x00, 0x01}

output, _ := Toggle(data, toggle)
fmt.Printf("%x\n", output)
// Output: 010101
}

0 comments on commit 1d56d10

Please sign in to comment.