• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mewkiz / flac / 6713408042

31 Oct 2023 11:04PM UTC coverage: 68.265% (+4.9%) from 63.409%
6713408042

push

github

mewmew
internal/bits: minor updates of TestUnary for consistency

Run `goimports -w` to sort imports and change order of
"expected xx, got xx" to match other test cases
(e.g. TestZigZag).

1680 of 2461 relevant lines covered (68.26%)

4364391.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/internal/bits/unary.go
1
package bits
2

3
import (
4
        "github.com/icza/bitio"
5
)
6

7
// ReadUnary decodes and returns an unary coded integer, whose value is
8
// represented by the number of leading zeros before a one.
9
//
10
// Examples of unary coded binary on the left and decoded decimal on the right:
11
//
12
//        1       => 0
13
//        01      => 1
14
//        001     => 2
15
//        0001    => 3
16
//        00001   => 4
17
//        000001  => 5
18
//        0000001 => 6
19
func (br *Reader) ReadUnary() (x uint64, err error) {
1,000✔
20
        for {
501,500✔
21
                bit, err := br.Read(1)
500,500✔
22
                if err != nil {
500,500✔
23
                        return 0, err
×
24
                }
×
25
                if bit == 1 {
501,500✔
26
                        break
1,000✔
27
                }
28
                x++
499,500✔
29
        }
30
        return x, nil
1,000✔
31
}
32

33
// WriteUnary encodes x as an unary coded integer, whose value is represented by
34
// the number of leading zeros before a one.
35
//
36
// Examples of unary coded binary on the left and decoded decimal on the right:
37
//
38
//        0 => 1
39
//        1 => 01
40
//        2 => 001
41
//        3 => 0001
42
//        4 => 00001
43
//        5 => 000001
44
//        6 => 0000001
45
func WriteUnary(bw *bitio.Writer, x uint64) error {
1,000✔
46
        for ; x > 8; x -= 8 {
62,876✔
47
                if err := bw.WriteByte(0x0); err != nil {
61,876✔
48
                        return err
×
49
                }
×
50
        }
51

52
        bits := uint64(1)
1,000✔
53
        n := byte(x + 1)
1,000✔
54
        if err := bw.WriteBits(bits, n); err != nil {
1,000✔
55
                return err
×
56
        }
×
57
        return nil
1,000✔
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc