File tree Expand file tree Collapse file tree 3 files changed +40
-11
lines changed Expand file tree Collapse file tree 3 files changed +40
-11
lines changed Original file line number Diff line number Diff line change 3
3
go build -o bin/yaml-readme .
4
4
copy : build
5
5
cp bin/yaml-readme /usr/local/bin
6
-
6
+ test :
7
+ go test ./...
8
+ benchmark :
9
+ go test -benchmem -run=^$$ -bench ^BenchmarkGetTopN$$ github.com/linuxsuren/yaml-readme/function
Original file line number Diff line number Diff line change @@ -373,18 +373,22 @@ func TestGetTopN(t *testing.T) {
373
373
count int
374
374
expect map [string ]int
375
375
}{{
376
- name : "normal" ,
376
+ name : "normal" ,
377
+ values : items ,
378
+ count : 3 ,
379
+ expect : map [string ]int {
380
+ "seven" : 11 ,
381
+ "six" : 10 ,
382
+ "five" : 9 ,
383
+ },
384
+ }, {
385
+ name : "less data" ,
377
386
values : map [string ]int {
378
- "linuxsuren" : 1 ,
379
- "fake" : 2 ,
380
- "test" : 3 ,
381
- "rick" : 4 ,
387
+ "linuxsuren" : 2 ,
382
388
},
383
- count : 3 ,
389
+ count : 2 ,
384
390
expect : map [string ]int {
385
- "rick" : 4 ,
386
- "test" : 3 ,
387
- "fake" : 2 ,
391
+ "linuxsuren" : 2 ,
388
392
},
389
393
}}
390
394
for _ , tt := range tests {
@@ -394,3 +398,23 @@ func TestGetTopN(t *testing.T) {
394
398
})
395
399
}
396
400
}
401
+
402
+ var items = map [string ]int {
403
+ "linuxsuren" : 1 ,
404
+ "fake" : 2 ,
405
+ "test" : 3 ,
406
+ "rick" : 4 ,
407
+ "one" : 5 ,
408
+ "two" : 6 ,
409
+ "three" : 7 ,
410
+ "four" : 8 ,
411
+ "five" : 9 ,
412
+ "six" : 10 ,
413
+ "seven" : 11 ,
414
+ }
415
+
416
+ func BenchmarkGetTopN (b * testing.B ) {
417
+ for i := 0 ; i < b .N ; i ++ {
418
+ getTopN (items , 3 )
419
+ }
420
+ }
Original file line number Diff line number Diff line change 6
6
"io/ioutil"
7
7
"reflect"
8
8
"testing"
9
+
10
+ "github.com/stretchr/testify/assert"
9
11
)
10
- import "github.com/stretchr/testify/assert"
11
12
12
13
func Test_sortBy (t * testing.T ) {
13
14
type args struct {
@@ -302,6 +303,7 @@ printGHTable
302
303
printHelp
303
304
printPages
304
305
printStarHistory
306
+ printStargazers
305
307
printToc
306
308
printVisitorCount
307
309
render
You can’t perform that action at this time.
0 commit comments