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

Function ModelTest

coder/arith/models_test.go:9–31  ·  view source on GitHub ↗

Tests a model provided by the constructor

(t *testing.T, N int, model func() Model)

Source from the content-addressed store, hash-verified

7
8// Tests a model provided by the constructor
9func ModelTest(t *testing.T, N int, model func() Model) {
10 encm, decm := model(), model()
11 mask := uint(1<<encm.NBits() - 1)
12
13 bits := make([]uint, N)
14 for i := range bits {
15 bits[i] = uint(rand.Int()) & mask
16 }
17
18 enc := NewEncoder()
19 for _, bit := range bits {
20 encm.Encode(enc, bit)
21 }
22 enc.Close()
23
24 dec := NewDecoder(enc.Bytes())
25 for i, v := range bits {
26 x := decm.Decode(dec) & mask
27 if x != v {
28 t.Fatalf("fail %v: %v got %v exp %v", bits, i, x, v)
29 }
30 }
31}
32
33func TestShiftModel(t *testing.T) {
34 ModelTest(t, 3, func() Model { return &Shift{Prob(0.5), 3} })

Callers 3

TestShiftModelFunction · 0.85
TestShift2ModelFunction · 0.85
TestTreeModelFunction · 0.85

Calls 7

CloseMethod · 0.95
BytesMethod · 0.95
NewEncoderFunction · 0.85
NewDecoderFunction · 0.70
NBitsMethod · 0.65
EncodeMethod · 0.65
DecodeMethod · 0.65

Tested by

no test coverage detected