Skip to content

Commit

Permalink
Add Once test
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 15, 2014
1 parent b861551 commit b5ec427
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestEvery(t *testing.T) {
Every(2*time.Millisecond, func() {
i++
})
time.Sleep(5 * time.Millisecond)
<-time.After(5 * time.Millisecond)
Expect(t, i, 2)
}

Expand All @@ -20,7 +20,7 @@ func TestAfter(t *testing.T) {
After(1*time.Millisecond, func() {
i++
})
time.Sleep(2 * time.Millisecond)
<-time.After(2 * time.Millisecond)
Expect(t, i, 1)
}

Expand All @@ -41,9 +41,24 @@ func TestOn(t *testing.T) {
i = data.(int)
})
Publish(e, 10)
time.Sleep(1 * time.Millisecond)
<-time.After(1 * time.Millisecond)
Expect(t, i, 10)
}
func TestOnce(t *testing.T) {
i := 0
e := NewEvent()
Once(e, func(data interface{}) {
i += data.(int)
})
On(e, func(data interface{}) {
i += data.(int)
})
Publish(e, 10)
<-time.After(1 * time.Millisecond)
Publish(e, 10)
<-time.After(1 * time.Millisecond)
Expect(t, i, 30)
}

func TestFromScale(t *testing.T) {
Expect(t, FromScale(5, 0, 10), 0.5)
Expand Down

0 comments on commit b5ec427

Please sign in to comment.