Skip to content

Commit

Permalink
added tests and removed an unused global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfOne committed Aug 27, 2014
1 parent e51b058 commit deec6be
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions sync/spinlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import (
"testing"
)

func TestTryLock(t *testing.T) {
var sl SpinLock
if !sl.TryLock() {
t.Error("TryLock failed.")
}
}

func TestLock(t *testing.T) {
var sl SpinLock
sl.Lock()

if sl.TryLock() {
t.Error("TryLock() returned true when it shouldn't have, w t f mate?")
}

sl.Unlock()

if !sl.TryLock() {
t.Error("TryLock() returned false when it shouldn't have.")
}

}

type SpinMap struct {
SpinLock
m map[int]bool
Expand Down Expand Up @@ -62,9 +85,8 @@ func (mm *RWMutexMap) Get(i int) (b bool) {
const N = 1e3

var (
sm = SpinMap{m: map[int]bool{}}
mm = MutexMap{m: map[int]bool{}}
rmm = RWMutexMap{m: map[int]bool{}}
sm = SpinMap{m: map[int]bool{}}
mm = MutexMap{m: map[int]bool{}}
)

func BenchmarkSpinL(b *testing.B) {
Expand Down

0 comments on commit deec6be

Please sign in to comment.