Tests a model provided by the constructor
(t *testing.T, N int, model func() Model)
| 7 | |
| 8 | // Tests a model provided by the constructor |
| 9 | func 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 | |
| 33 | func TestShiftModel(t *testing.T) { |
| 34 | ModelTest(t, 3, func() Model { return &Shift{Prob(0.5), 3} }) |
no test coverage detected