File: hashtable_test.go

package info (click to toggle)
golang-github-ulikunitz-xz 0.5.15-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 11,496 kB
  • sloc: makefile: 7; sh: 5
file content (47 lines) | stat: -rw-r--r-- 981 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2014-2022 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package lzma

import (
	"fmt"
	"testing"
)

func TestHashTable(t *testing.T) {
	ht, err := newHashTable(32, 2)
	if err != nil {
		t.Fatalf("newHashTable: error %s", err)
	}
	//    01234567890123456
	s := "abcabcdefghijklmn"
	n, err := ht.Write([]byte(s))
	if err != nil {
		t.Fatalf("ht.Write: error %s", err)
	}
	if n != len(s) {
		t.Fatalf("ht.Write returned %d; want %d", n, len(s))
	}
	tests := []struct {
		s string
		w string
	}{
		{"ab", "[3 0]"},
		{"bc", "[4 1]"},
		{"ca", "[2]"},
		{"xx", "[]"},
		{"gh", "[9]"},
		{"mn", "[15]"},
	}
	distances := make([]int64, 20)
	for _, c := range tests {
		distances := distances[:20]
		k := ht.Matches([]byte(c.s), distances)
		distances = distances[:k]
		o := fmt.Sprintf("%v", distances)
		if o != c.w {
			t.Errorf("%s: offsets %s; want %s", c.s, o, c.w)
		}
	}
}