From 566f95a1afdc0373b1e71a44943a53b73f38430c Mon Sep 17 00:00:00 2001 From: gerrish Date: Mon, 8 Apr 2019 04:11:00 +0300 Subject: [PATCH] added get function tests --- README.md | 2 +- skiplist_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b18b38..a9cabdb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/skiplist_test.go b/skiplist_test.go index e8e8508..d0a32d9 100644 --- a/skiplist_test.go +++ b/skiplist_test.go @@ -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")