当前位置: 首页>>代码示例>>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;未经允许,请勿转载。