add more test for subset

master
kevin 4 years ago
parent 621d33ecbe
commit 760d3c8c4b

@ -150,7 +150,7 @@ go-zero是一个集成了各种工程实践的包含web和rpc框架有如下
go run greet.go -f etc/greet-api.json go run greet.go -f etc/greet-api.json
``` ```
默认侦听在8888端口可以通过curl请求 默认侦听在8888端口(可以在配置文件里修改)可以通过curl请求
```shell ```shell
➜ go-zero git:(master) curl -w "\ncode: %{http_code}\n" http://localhost:8888/greet/from/kevin ➜ go-zero git:(master) curl -w "\ncode: %{http_code}\n" http://localhost:8888/greet/from/kevin

@ -12,7 +12,7 @@ import (
const ( const (
DiscovScheme = "discov" DiscovScheme = "discov"
EndpointSep = "," EndpointSep = ","
subsetSize = 36 subsetSize = 32
) )
var builder discovBuilder var builder discovBuilder

@ -37,29 +37,18 @@ func TestSubset(t *testing.T) {
m := make(map[interface{}]int) m := make(map[interface{}]int)
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
set := subset(append([]string(nil), vals...), test.sub) set := subset(append([]string(nil), vals...), test.sub)
for _, val := range set { if test.sub < test.set {
m[val]++ assert.Equal(t, test.sub, len(set))
} } else {
} assert.Equal(t, test.set, len(set))
assert.True(t, mathx.CalcEntropy(m) > 0.95)
})
}
}
func TestSubsetLess(t *testing.T) {
var vals []string
for i := 0; i < 100; i++ {
vals = append(vals, strconv.Itoa(i))
} }
m := make(map[interface{}]int)
for i := 0; i < 1000; i++ {
set := subset(append([]string(nil), vals...), 200)
for _, val := range set { for _, val := range set {
m[val]++ m[val]++
} }
} }
assert.True(t, mathx.CalcEntropy(m) > 0.95) assert.True(t, mathx.CalcEntropy(m) > 0.95)
})
}
} }

Loading…
Cancel
Save