Skip to content

Commit

Permalink
adding min function
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Nov 6, 2013
1 parent 49c6217 commit e333f08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ func randomTimeout(minVal time.Duration) <-chan time.Time {
extra := (time.Duration(rand.Int63()) % minVal)
return time.After(minVal + extra)
}

// min returns the minimum.
func min(a, b uint64) uint64 {
if a <= b {
return a
}
return b
}
12 changes: 12 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ func TestRandomTimeout(t *testing.T) {
t.Fatalf("timeout")
}
}

func TestMin(t *testing.T) {
if min(1, 1) != 1 {
t.Fatalf("bad min")
}
if min(2, 1) != 1 {
t.Fatalf("bad min")
}
if min(1, 2) != 1 {
t.Fatalf("bad min")
}
}

0 comments on commit e333f08

Please sign in to comment.