MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / TestSerializationToFile038

Function TestSerializationToFile038

roaring64/serialization_test.go:87–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestSerializationToFile038(t *testing.T) {
88 rb := BitmapOf(1, 2, 3, 4, 5, 100, 1000)
89 fname := filepath.Join(t.TempDir(), "myfile.bin")
90 fout, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o660)
91 if err != nil {
92 fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
93 return
94 }
95
96 var l int64
97 l, err = rb.WriteTo(fout)
98 if err != nil {
99 fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
100 return
101 }
102
103 assert.EqualValues(t, l, rb.GetSerializedSizeInBytes())
104
105 fout.Close()
106
107 newrb := NewBitmap()
108 fin, err := os.Open(fname)
109 if err != nil {
110 fmt.Fprintf(os.Stderr, "\n\nIMPORTANT: For testing file IO, the roaring library requires disk access.\nWe omit some tests for now.\n\n")
111 return
112 }
113 buf := bytes.NewBuffer(nil)
114 teer := io.TeeReader(fin, buf)
115
116 defer fin.Close()
117
118 _, _ = newrb.ReadFrom(teer)
119 assert.True(t, rb.Equals(newrb))
120
121 newrb2 := NewBitmap()
122 fromUnsafeBytesChecked(t, newrb2, buf.Bytes())
123 assert.True(t, rb.Equals(newrb2))
124}
125
126func TestSerializationBasic2_041(t *testing.T) {
127 rb := BitmapOf(1, 2, 3, 4, 5, 100, 1000, 10000, 100000, 1000000)

Callers

nothing calls this directly

Calls 7

ReadFromMethod · 0.95
fromUnsafeBytesCheckedFunction · 0.85
BitmapOfFunction · 0.70
NewBitmapFunction · 0.70
WriteToMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…