本文整理匯總了Golang中github.com/mttrs/gopl/io/ch6/intset.IntSet.Len方法的典型用法代碼示例。如果您正苦於以下問題:Golang IntSet.Len方法的具體用法?Golang IntSet.Len怎麽用?Golang IntSet.Len使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mttrs/gopl/io/ch6/intset.IntSet
的用法示例。
在下文中一共展示了IntSet.Len方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSingleAddLen
func TestSingleAddLen(t *testing.T) {
tests := []struct {
input int
want int
}{
{0, 1},
{1, 1},
{64, 1},
{256, 1},
}
// single add value case
for _, test := range tests {
var x intset.IntSet
x.Add(test.input)
if got := x.Len(); got != test.want {
t.Errorf("Len() input %d = %d", test.input, got)
}
}
}
示例2: Example_ex6_1
func Example_ex6_1() {
var x, z intset.IntSet
x.Add(0)
x.Add(128)
x.Add(1)
x.Add(2)
x.Add(37)
x.Add(64)
fmt.Println(x.String())
// Show the number of x elements
fmt.Println(x.Len())
x.Remove(0)
x.Remove(64)
x.Remove(128)
x.Remove(2)
fmt.Println(x.String())
z = x.Copy()
fmt.Println(z.String())
// Confirm that z doesn't have x's reference.
x.Add(5)
fmt.Println(x.String())
fmt.Println(z.String())
// Clear x
x.Clear()
fmt.Println(x.String())
// Output:
// {0 1 2 37 64 128}
// 6
// {1 37}
// {1 37}
// {1 5 37}
// {1 37}
// {}
}
示例3: TestMultiAddLen
func TestMultiAddLen(t *testing.T) {
tests := []struct {
input []int
want int
}{
{[]int{0, 1}, 2},
{[]int{0, 0}, 1}, // duplicated input
{[]int{0, 1, 2}, 3},
{[]int{0, 64, 128}, 3},
}
for _, test := range tests {
var x intset.IntSet
for _, v := range test.input {
x.Add(v)
}
if got := x.Len(); got != test.want {
t.Errorf("Len() input %v = %d", test.input, got)
}
}
}