本文整理汇总了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
}
示例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)
}
}
示例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)
})
})
}