MCPcopy Create free account
hub / github.com/egonelbre/exp / TestRandomEncodeDecode

Function TestRandomEncodeDecode

coder/arith/encoding_test.go:13–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11}
12
13func TestRandomEncodeDecode(t *testing.T) {
14 bits := make([]pair, 2141)
15 for i := range bits {
16 bits[i].bit = uint(rand.Intn(2))
17 bits[i].prob = P(rand.Intn(MaxP))
18 }
19
20 enc := NewEncoder()
21 for _, v := range bits {
22 enc.Encode(v.bit, v.prob)
23 }
24 enc.Close()
25 data := enc.Bytes()
26
27 dec := NewDecoder(data)
28 for i, v := range bits {
29 x := dec.Decode(v.prob)
30 if x != v.bit {
31 t.Fatalf("fail %v: %v got %v exp %v", bits, i, x, v.bit)
32 }
33 }
34}
35
36func TestPacking(t *testing.T) {
37 const N = 1 << 16

Callers

nothing calls this directly

Calls 7

EncodeMethod · 0.95
CloseMethod · 0.95
BytesMethod · 0.95
DecodeMethod · 0.95
NewEncoderFunction · 0.85
PTypeAlias · 0.70
NewDecoderFunction · 0.70

Tested by

no test coverage detected