Esempio n. 1
0
func TestAppendNext(t *testing.T) {
	for i, tt := range appendNextTests {
		c, err := makeTable(tt.in)
		if err != nil {
			t.Errorf("%d: error creating table: %v", i, err)
			continue
		}
		for j, chk := range tt.chk {
			ws, n := c.t.AppendNext(nil, []byte(chk.in))
			if n != chk.n {
				t.Errorf("%d:%d: bytes consumed was %d; want %d", i, j, n, chk.n)
			}
			out := convertFromWeights(chk.out)
			if len(ws) != len(out) {
				t.Errorf("%d:%d: len(ws) was %d; want %d (%X vs %X)\n%X", i, j, len(ws), len(out), ws, out, chk.in)
				continue
			}
			for k, w := range ws {
				w, _ = colltab.MakeElem(w.Primary(), w.Secondary(), int(w.Tertiary()), 0)
				if w != out[k] {
					t.Errorf("%d:%d: Weights %d was %X; want %X", i, j, k, w, out[k])
				}
			}
		}
	}
}
Esempio n. 2
0
func makeCE(w []int) colltab.Elem {
	ce, err := colltab.MakeElem(w[0], w[1], w[2], uint8(w[3]))
	if err != nil {
		panic(err)
	}
	return ce
}
Esempio n. 3
0
func convertFromWeights(ws []Weights) []colltab.Elem {
	out := make([]colltab.Elem, len(ws))
	for i, w := range ws {
		out[i], _ = colltab.MakeElem(w.Primary, w.Secondary, w.Tertiary, 0)
		if out[i] == colltab.Ignore && w.Quaternary > 0 {
			out[i] = colltab.MakeQuaternary(w.Quaternary)
		}
	}
	return out
}
Esempio n. 4
0
func TestGetColElems(t *testing.T) {
	for i, tt := range appendNextTests {
		c, err := makeTable(tt.in)
		if err != nil {
			// error is reported in TestAppendNext
			continue
		}
		// Create one large test per table
		str := make([]byte, 0, 4000)
		out := ColElems{}
		for len(str) < 3000 {
			for _, chk := range tt.chk {
				str = append(str, chk.in[:chk.n]...)
				out = append(out, chk.out...)
			}
		}
		for j, chk := range append(tt.chk, check{string(str), len(str), out}) {
			out := convertFromWeights(chk.out)
			ce := c.getColElems([]byte(chk.in)[:chk.n])
			if len(ce) != len(out) {
				t.Errorf("%d:%d: len(ws) was %d; want %d", i, j, len(ce), len(out))
				continue
			}
			cnt := 0
			for k, w := range ce {
				w, _ = colltab.MakeElem(w.Primary(), w.Secondary(), int(w.Tertiary()), 0)
				if w != out[k] {
					t.Errorf("%d:%d: Weights %d was %X; want %X", i, j, k, w, out[k])
					cnt++
				}
				if cnt > 10 {
					break
				}
			}
		}
	}
}
Esempio n. 5
0
func makeCE(ce rawCE) (uint32, error) {
	v, e := colltab.MakeElem(ce.w[0], ce.w[1], ce.w[2], ce.ccc)
	return uint32(v), e
}