Пример #1
0
func ExampleUniq() {
	data := sort.IntSlice{5, 7, 3, 3, 5}

	sort.Sort(data)     // sort the data first
	n := set.Uniq(data) // Uniq returns the size of the set
	data = data[:n]     // trim the duplicate elements

	fmt.Println(data)
	// Output: [3 5 7]
}
Пример #2
0
func TestUniq(t *testing.T) {
	for _, tt := range uniqs {
		// make copy of the input
		s := sort.IntSlice(append([]int(nil), tt.in...))
		size := set.Uniq(s)
		s = s[:size]
		if len(s) != len(tt.out) {
			t.Errorf(format, "Uniq", tt.in, s, tt.out)
			continue
		}
		for i := range s {
			if s[i] != tt.out[i] {
				t.Errorf(format, "Uniq", tt.in, s, tt.out)
				break
			}
		}
	}
}