示例#1
0
func partitionRandomly(t *testing.T, nw *nettestutil.Network, n int) {
	nparts := rand.Intn(n) + 1
	parts := make([][]int, nparts)
	for i := 0; i < n; i++ {
		p := rand.Intn(nparts)
		parts[p] = append(parts[p], i)
	}
	nw.Partition(parts...)
	if testing.Verbose() {
		for _, pp := range parts {
			for i := range pp {
				pp[i]++
			}
		}
		t.Logf("partition! %v", parts)
	}
}
示例#2
0
func partitionMajorityMinority(t *testing.T, nw *nettestutil.Network, n, offset int) {
	m := majority(n)
	main := make([]int, 0, m)
	encl := make([]int, 0, n-m)
	for i := 0; i < n; i++ {
		if (i+offset)%n < m {
			main = append(main, i)
		} else {
			encl = append(encl, i)
		}
	}
	nw.Partition(main, encl)
	if testing.Verbose() {
		for i := range main {
			main[i]++
		}
		for i := range encl {
			encl[i]++
		}
		t.Logf("partition! (%v, %v)", main, encl)
	}
}