]> Sergey Matveev's repositories - btrtrc.git/blob - requesting_test.go
gofumpt
[btrtrc.git] / requesting_test.go
1 package torrent
2
3 import (
4         "testing"
5
6         pp "github.com/anacrolix/torrent/peer_protocol"
7         qt "github.com/frankban/quicktest"
8 )
9
10 func keysAsSlice(m map[Request]struct{}) (sl []Request) {
11         for k := range m {
12                 sl = append(sl, k)
13         }
14         return
15 }
16
17 func makeTypicalRequests() map[Request]struct{} {
18         m := make(map[Request]struct{})
19         for p := pp.Integer(0); p < 4; p++ {
20                 for c := pp.Integer(0); c < 16; c++ {
21                         m[Request{p, ChunkSpec{c * defaultChunkSize, defaultChunkSize}}] = struct{}{}
22                 }
23         }
24         return m
25 }
26
27 func TestLogExampleRequestMapOrdering(t *testing.T) {
28         for k := range makeTypicalRequests() {
29                 t.Log(k)
30         }
31 }
32
33 func TestRequestMapOrderingPersistent(t *testing.T) {
34         m := makeTypicalRequests()
35         // Shows that map order is persistent across separate range statements.
36         qt.Assert(t, keysAsSlice(m), qt.ContentEquals, keysAsSlice(m))
37 }
38
39 func TestRequestMapOrderAcrossInstances(t *testing.T) {
40         // This shows that different map instances with the same contents can have the same range order.
41         qt.Assert(t, keysAsSlice(makeTypicalRequests()), qt.ContentEquals, keysAsSlice(makeTypicalRequests()))
42 }