Skip to content

Commit

Permalink
add unit test for store
Browse files Browse the repository at this point in the history
  • Loading branch information
micutio committed Aug 21, 2022
1 parent 28fd010 commit beaadf1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.19

require (
github.com/micutio/goptional v0.0.0-20220819142109-68da6ecd08c6
github.com/tidwall/btree v1.4.1
github.com/tidwall/btree v1.4.2
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ github.com/micutio/goptional v0.0.0-20220819142109-68da6ecd08c6 h1:44g/6zxiIkCMx
github.com/micutio/goptional v0.0.0-20220819142109-68da6ecd08c6/go.mod h1:NVRk8/MaoB4b4Tu+YADH6PvkMWrBAk1CMw5QnRYepEc=
github.com/tidwall/btree v1.4.1 h1:m0XE8xxIrI7LiNOypNWm260JyfX4hi8Yfm8ESFfpi+k=
github.com/tidwall/btree v1.4.1/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
github.com/tidwall/btree v1.4.2 h1:PpkaieETJMUxYNADsjgtNRcERX7mGc/GP2zp/r5FM3g=
github.com/tidwall/btree v1.4.2/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
2 changes: 1 addition & 1 deletion pkg/tuplespace/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ type SimpleStore struct {
tree *btree.BTreeG[Tuple]
}

func New() *SimpleStore {
func NewSimpleStore() *SimpleStore {
return &SimpleStore{tree: btree.NewBTreeG(TupleOrder)}
}
37 changes: 37 additions & 0 deletions pkg/tuplespace/store_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
package gotupolis

import (
"testing"

option "github.com/micutio/goptional"
)

func TestStore(t *testing.T) {
store := getStoreImpl()
tup := MakeTuple(I(1), I(2), F(3.14), S("Foo!"), T(MakeTuple(S("hurz"))))

// test insertion
store.Out(tup)

// test read
var tupleOpt1 option.Maybe[Tuple] = store.Read(tup)
if !tupleOpt1.IsPresent() {
t.Errorf("Error: cannot find inserted tuple %v", tup)
}

// test out
// since we've only read the tuple, it should still be in the store
var tupleOpt2 option.Maybe[Tuple] = store.In(tup)
if !tupleOpt2.IsPresent() {
t.Errorf("Error: cannot find inserted tuple %v", tup)
}

// now the tuple should be gone
var tupleOpt3 option.Maybe[Tuple] = store.In(tup)
if tupleOpt3.IsPresent() {
t.Errorf("Error: store should not contain tuple %v anymore", tup)
}
}

func getStoreImpl() Store {
return NewSimpleStore()
}

0 comments on commit beaadf1

Please sign in to comment.