Skip to content

Commit

Permalink
added get function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BazookaMusic committed Apr 8, 2019
1 parent ae0e488 commit 566f95a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ optimistic lazy Skiplist algorithm from the paper by Maurice Herlihy,Yossi Lev o

The implementation includes tests and the repository is connected with Travis for continuous integration.

The skiplist acts as a set and supports insert,contains,remove operations in O(logn) expected time and union and intersection operations in O(n + m) expected time.
The skiplist acts as a set or a map and supports insert,contains,remove and get (to function as a map) operations in O(logn) expected time and union and intersection operations in O(n + m) expected time.

Example usage:
```golang
Expand Down
34 changes: 34 additions & 0 deletions skiplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ func TestRemove(t *testing.T) {

}

func TestGet(t *testing.T) {
fmt.Println("---------------------------------------")
fmt.Println("Sequential integer add and get")
fmt.Println("----------------------------------------")

rand.Seed(time.Now().UTC().UnixNano())

var head = New(0.5, 30, FAST)

//var wg sync.WaitGroup

fmt.Println("Inserting numbers from 0 to", dataAmount-1)
for index := 0; index < dataAmount; index++ {
if !head.Insert(Int(index)) {
t.Errorf("Could not insert item %d", index)
}
}

for index := 0; index < dataAmount; index++ {
if head.Get((Int(index))) == nil {
t.Errorf("Inserted number %d but not contained in Skiplist", index)
}
}

invalidItem := head.Get(Int(dataAmount + 2))
if invalidItem != nil {
t.Errorf("Key %d should not match any values but matches %d", dataAmount+2, invalidItem)

}

fmt.Println("OK!")
fmt.Println("----------------------------------------")
}

func TestRandOperation(t *testing.T) {
fmt.Println("------------------------------------")
fmt.Println("Random integer add, check and remove")
Expand Down

0 comments on commit 566f95a

Please sign in to comment.