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


Golang T.Sub方法代碼示例

本文整理匯總了Golang中testing.T.Sub方法的典型用法代碼示例。如果您正苦於以下問題:Golang T.Sub方法的具體用法?Golang T.Sub怎麽用?Golang T.Sub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testing.T的用法示例。


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

示例1: testAfterQueuing

func testAfterQueuing(t *testing.T, delta Duration) error {
	// make the result channel buffered because we don't want
	// to depend on channel queueing semantics that might
	// possibly change in the future.
	result := make(chan afterResult, len(slots))

	t0 := Now()
	for _, slot := range slots {
		go await(slot, result, After(Duration(slot)*delta))
	}
	var order []int
	var times []Time
	for range slots {
		r := <-result
		order = append(order, r.slot)
		times = append(times, r.t)
	}
	for i := range order {
		if i > 0 && order[i] < order[i-1] {
			return fmt.Errorf("After calls returned out of order: %v", order)
		}
	}
	for i, t := range times {
		dt := t.Sub(t0)
		target := Duration(order[i]) * delta
		if dt < target-delta/2 || dt > target+delta*10 {
			return fmt.Errorf("After(%s) arrived at %s, expected [%s,%s]", target, dt, target-delta/2, target+delta*10)
		}
	}
	return nil
}
開發者ID:RajibTheKing,項目名稱:gcc,代碼行數:31,代碼來源:sleep_test.go

示例2: TestNatSub

func TestNatSub(t *testing.T) {
	tester = t
	test_msg = "NatSubA"
	nat_eq(0, nat_zero.Sub(nat_zero), nat_zero)
	nat_eq(1, c.Sub(nat_zero), c)

	test_msg = "NatSubB"
	for i := uint64(0); i < 100; i++ {
		t := sum(i, c)
		for j := uint64(0); j <= i; j++ {
			t = t.Sub(mul(Nat(j), c))
		}
		nat_eq(uint(i), t, nat_zero)
	}
}
開發者ID:rapgamer,項目名稱:golang-china,代碼行數:15,代碼來源:bignum_test.go

示例3: TestEventual

func TestEventual(t *testing.T) {
	Convey("eventual basic functionality, no mandatory, no exclusive", t, func() {
		e := New()

		t, err := e.Register("test.topic", false, false)
		So(err, ShouldBeNil)
		So(t.GetTopic(), ShouldEqual, "test.topic")
		So(t.IsMandatory(), ShouldBeFalse)
		So(t.IsExclusive(), ShouldBeFalse)

		Convey("pub/sub test", func() {
			s1 := t.Sub()
			s2 := t.Sub()
			t.Sub() // This must pass, since its not mandatory
			wg := sync.WaitGroup{}
			wg.Add(2)

			var resp1, resp2 IEvent
			go func() {
				defer wg.Done()
				resp1 = <-s1
			}()

			go func() {
				defer wg.Done()
				resp2 = <-s2
			}()

			// Make sure the readers are ready. I know this is not accurate, but
			// I don't know any beter way
			time.Sleep(time.Second)
			t.Pub(mockIEvent{1})

			wg.Wait()
			So(resp1.Data().(int), ShouldEqual, 1)
			So(resp2.Data().(int), ShouldEqual, 1)
		})

		Convey("pub/sub test on another channel", func() {
			t1, err := e.Register("test.topic", false, false)
			So(err, ShouldBeNil)

			s1 := t.Sub()
			wg := sync.WaitGroup{}
			wg.Add(1)

			var resp IEvent
			go func() {
				defer wg.Done()
				resp = <-s1
			}()
			time.Sleep(time.Second)

			t1.Pub(mockIEvent{2})

			wg.Wait()
			So(resp.Data().(int), ShouldEqual, 2)
		})
	})
}
開發者ID:fzerorubigd,項目名稱:eventual,代碼行數:60,代碼來源:eventual_test.go


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