예제 #1
0
func TestKeyFromElems(t *testing.T) {
	buf := collate.Buffer{}
	for i, tt := range keyFromElemTests {
		buf.ResetKeys()
		ws := collate.ProcessWeights(tt.opt.alt, tt.opt.top, tt.in)
		res := collate.KeyFromElems(tt.opt.collator(), &buf, ws)
		if len(res) != len(tt.out) {
			t.Errorf("%d: len(ws) was %d; want %d (%X should be %X)", i, len(res), len(tt.out), res, tt.out)
		}
		n := len(res)
		if len(tt.out) < n {
			n = len(tt.out)
		}
		for j, c := range res[:n] {
			if c != tt.out[j] {
				t.Errorf("%d: byte %d was %X; want %X", i, j, c, tt.out[j])
			}
		}
	}
}
예제 #2
0
파일: maketables.go 프로젝트: hfeeki/go
func testCollator(c *collate.Collator) {
	c0 := collate.New("")

	// iterator over all characters for all locales and check
	// whether Key is equal.
	buf := collate.Buffer{}

	// Add all common and not too uncommon runes to the test set.
	for i := rune(0); i < 0x30000; i++ {
		testInput.add(string(i))
	}
	for i := rune(0xE0000); i < 0xF0000; i++ {
		testInput.add(string(i))
	}
	for _, str := range testInput.values() {
		k0 := c0.KeyFromString(&buf, str)
		k := c.KeyFromString(&buf, str)
		if bytes.Compare(k0, k) != 0 {
			failOnError(fmt.Errorf("test:%U: keys differ (%x vs %x)", []rune(str), k0, k))
		}
		buf.ResetKeys()
	}
	fmt.Println("PASS")
}