structure/for_test.go

60 lines
1004 B
Go
Raw Permalink Normal View History

2019-03-20 11:20:06 +00:00
package structure
import (
"bytes"
"encoding/gob"
"io/ioutil"
"log"
"os"
"testing"
randomdata "github.com/Pallinder/go-randomdata"
)
2019-03-24 14:21:25 +00:00
const CompartorSize = 1000000
2019-03-20 11:20:06 +00:00
const NumberMax = 50000000
func TestSave(t *testing.T) {
2019-04-21 05:31:39 +00:00
f, err := os.OpenFile("l.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
2019-03-20 11:20:06 +00:00
if err != nil {
log.Println(err)
}
//fmt.Println(userBytes)
var l []int
// for i := 0; len(l) < 1000; i++ {
// v := randomdata.Number(0, 65535)
// l = append(l, v)
// }
//m := make(map[int]int)
for i := 0; len(l) < CompartorSize; i++ {
v := randomdata.Number(0, NumberMax)
// if _, ok := m[v]; !ok {
// m[v] = v
l = append(l, v)
// }
}
var result bytes.Buffer
encoder := gob.NewEncoder(&result)
encoder.Encode(l)
lbytes := result.Bytes()
f.Write(lbytes)
}
func loadTestData() []int {
data, err := ioutil.ReadFile("../l.log")
if err != nil {
log.Println(err)
}
var l []int
decoder := gob.NewDecoder(bytes.NewReader(data))
decoder.Decode(&l)
return l
}