當前位置: 首頁>>代碼示例>>Golang>>正文


Golang vector.Vector類代碼示例

本文整理匯總了Golang中doozer/vector.Vector的典型用法代碼示例。如果您正苦於以下問題:Golang Vector類的具體用法?Golang Vector怎麽用?Golang Vector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Vector類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestRecvInvalidPacket

func TestRecvInvalidPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}
	p := recvPacket(q, Packet{x, invalidProtobuf})
	assert.Equal(t, (*packet)(nil), p)
	assert.Equal(t, 0, q.Len())
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:7,代碼來源:manager_test.go

示例2: TestRecvEmptyPacket

func TestRecvEmptyPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}

	p := recvPacket(q, Packet{x, []byte{}})
	assert.Equal(t, (*packet)(nil), p)
	assert.Equal(t, 0, q.Len())
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:8,代碼來源:manager_test.go

示例3: avg

func avg(v *vector.Vector) (n int64) {
	t := time.Nanoseconds()
	if v.Len() == 0 {
		return -1
	}
	for _, x := range []interface{}(*v) {
		n += x.(trigger).t - t
	}
	return n / int64(v.Len())
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:10,代碼來源:manager.go

示例4: TestRunSchedulesTick

func TestRunSchedulesTick(t *testing.T) {
	var r run
	r.seqn = 1
	r.bound = 10
	r.out = make(chan Packet, 100)
	ticks := new(vector.Vector)

	r.update(&packet{msg: *newPropose("foo")}, -1, ticks)

	assert.Equal(t, 1, ticks.Len())
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:11,代碼來源:run_test.go

示例5: applyTriggers

func applyTriggers(packets, ticks *vector.Vector, now int64, tpl *msg) (n int) {
	for ticks.Len() > 0 {
		tt := ticks.At(0).(trigger)
		if tt.t > now {
			break
		}

		heap.Pop(ticks)

		p := new(packet)
		p.msg = *tpl
		p.msg.Seqn = &tt.n
		log.Println("applying", *p.Seqn, msg_Cmd_name[int32(*p.Cmd)])
		heap.Push(packets, p)
		n++
	}
	return
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:18,代碼來源:manager.go

示例6: TestRecvPacket

func TestRecvPacket(t *testing.T) {
	q := new(vector.Vector)
	x := &net.UDPAddr{net.IP{1, 2, 3, 4}, 5}

	p := recvPacket(q, Packet{x, mustMarshal(&msg{
		Seqn: proto.Int64(1),
		Cmd:  invite,
	})})
	assert.Equal(t, &packet{x, msg{Seqn: proto.Int64(1), Cmd: invite}}, p)
	p = recvPacket(q, Packet{x, mustMarshal(&msg{
		Seqn: proto.Int64(2),
		Cmd:  invite,
	})})
	assert.Equal(t, &packet{x, msg{Seqn: proto.Int64(2), Cmd: invite}}, p)
	p = recvPacket(q, Packet{x, mustMarshal(&msg{
		Seqn: proto.Int64(3),
		Cmd:  invite,
	})})
	assert.Equal(t, &packet{x, msg{Seqn: proto.Int64(3), Cmd: invite}}, p)
	assert.Equal(t, 3, q.Len())
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:21,代碼來源:manager_test.go

示例7: TestSchedTrigger

func TestSchedTrigger(t *testing.T) {
	q := new(vector.Vector)
	d := int64(15e8)

	t0 := time.Nanoseconds()
	ts := t0 + d
	schedTrigger(q, 1, t0, d)

	assert.Equal(t, 1, q.Len())
	f, ok := q.At(0).(trigger)
	assert.Tf(t, ok, "expected a trigger, got a %T", q.At(0))
	assert.Equal(t, int64(1), f.n)
	assert.T(t, f.t == ts)
}
開發者ID:bgentry,項目名稱:doozerd,代碼行數:14,代碼來源:manager_test.go


注:本文中的doozer/vector.Vector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。