Skip to content

Commit

Permalink
test: make the test bit cleaner
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed Aug 16, 2016
1 parent 9437b3a commit a63b5c3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions blocks/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
k "github.com/ipfs/go-ipfs/blocks/key"
)

const (
tAdd int = 1 << iota
tRemove
tReAdd
)

func exampleKeys() []k.Key {
res := make([]k.Key, 1<<8)
gen := bu.NewBlockGenerator()
Expand All @@ -17,15 +23,15 @@ func exampleKeys() []k.Key {
}
func checkSet(set BlockSet, keySlice []k.Key, t *testing.T) {
for i, key := range keySlice {
if i&(1<<2) == 0 {
if i&tReAdd == 0 {
if set.HasKey(key) == false {
t.Error("key should be in the set")
}
} else if i&(1<<1) == 0 {
} else if i&tRemove == 0 {
if set.HasKey(key) == true {
t.Error("key shouldn't be in the set")
}
} else if i&(1<<0) == 0 {
} else if i&tAdd == 0 {
if set.HasKey(key) == false {
t.Error("key should be in the set")
}
Expand All @@ -38,17 +44,17 @@ func TestSetWorks(t *testing.T) {
keys := exampleKeys()

for i, key := range keys {
if i&(1<<0) == 0 {
if i&tAdd == 0 {
set.AddBlock(key)
}
}
for i, key := range keys {
if i&(1<<1) == 0 {
if i&tRemove == 0 {
set.RemoveBlock(key)
}
}
for i, key := range keys {
if (i)&(1<<2) == 0 {
if i&tReAdd == 0 {
set.AddBlock(key)
}
}
Expand Down

0 comments on commit a63b5c3

Please sign in to comment.