-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support writing Unaries above 255 * Improve unary test error messages * Update comment on "44 - ...flac" test
- Loading branch information
1 parent
a0261e6
commit 2223fc0
Showing
3 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package bits_test | ||
|
||
import ( | ||
"bytes" | ||
"github.com/icza/bitio" | ||
"github.com/mewkiz/flac/internal/bits" | ||
"testing" | ||
) | ||
|
||
func TestUnary(t *testing.T) { | ||
w := new(bytes.Buffer) | ||
bw := bitio.NewWriter(w) | ||
|
||
var want uint64 | ||
for ; want < 1000; want++ { | ||
// Write unary | ||
if err := bits.WriteUnary(bw, want); err != nil { | ||
t.Fatalf("unable to write unary; %v", err) | ||
} | ||
// Flush buffer | ||
if err := bw.Close(); err != nil { | ||
t.Fatalf("unable to close (flush) the bit buffer; %v", err) | ||
} | ||
|
||
// Read written unary | ||
r := bits.NewReader(w) | ||
got, err := r.ReadUnary() | ||
if err != nil { | ||
t.Fatalf("unable to read unary; %v", err) | ||
} | ||
|
||
if got != want { | ||
t.Fatalf("the written and read unary doesn't match the original value, got: %v, expected: %v", got, want) | ||
} | ||
} | ||
} |