Skip to content

Commit

Permalink
reorg of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSnow committed May 20, 2024
1 parent 7ddcf05 commit 546f927
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
46 changes: 46 additions & 0 deletions internal/database/blockchainDB/shard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package blockchainDB

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestShard(t *testing.T) {
directory := filepath.Join(os.TempDir(), "ShardTest")
os.Mkdir(directory, os.ModePerm)
defer os.RemoveAll(directory)
filename := filepath.Join(directory, "shard")

shard, err := NewShard(5, filename)
assert.NoError(t, err, err)

entries := make(map[[32]byte][]byte)
fr := NewFastRandom([32]byte{1, 2, 3, 4, 5})

for i := 0; i < 100; i++ {
if i%10 == 0 && i != 0 {
fmt.Printf("%d ",i)
if i%100==0 {
fmt.Println()
}
}
for i := 0; i < 100; i++ {
entries[fr.NextHash()] = fr.RandBuff(100, 500)
}
for k := range entries {
nv := fr.RandBuff(100, 500)
shard.Put(k, nv)
entries[k] = nv
}
for k, v := range entries {
v2, err := shard.Get(k)
assert.NoError(t, err, err)
assert.Equal(t, v, v2, "Didn't get the right value back")
}
}
shard.Close()
}
30 changes: 0 additions & 30 deletions internal/database/blockchainDB/sharddb_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package blockchainDB

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -25,31 +23,3 @@ func TestShardDB(t *testing.T) {
assert.Equal(t, value, v, "did not get the same value back")
}
}

func TestShard(t *testing.T) {
directory := filepath.Join(os.TempDir(),"ShardTest")
os.Mkdir(directory,os.ModePerm)
defer os.RemoveAll(directory)
filename := filepath.Join(directory,"shard")

shard,err := NewShard(5,filename)
assert.NoError(t,err,err)

entries := make(map[[32]byte][]byte)
fr := NewFastRandom([32]byte {1,2,3,4,5})
for i:= 0; i<100000; i++ {
entries[fr.NextHash()] = fr.RandBuff(100,500)
}
for k := range entries {
nv := fr.RandBuff(100,500)
shard.Put(k,nv)
entries[k]=nv
}
for i:=0;i<1000000,i++ {
v2,err := shard.Get(k)
assert.NoError(t,err,err)
assert.Equal(t,v,v2,"Didn't get the right value back")
}

shard.Close()
}

0 comments on commit 546f927

Please sign in to comment.