forked from RoaringBitmap/roaring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RoaringBitmap#322 from Oppen/frozen_support
Support CRoaring's frozen format
- Loading branch information
Showing
17 changed files
with
406 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// +build 386,!appengine amd64,!appengine arm,!appengine arm64,!appengine ppc64le,!appengine mipsle,!appengine mips64le,!appengine mips64p32le,!appengine wasm,!appengine | ||
|
||
package roaring | ||
|
||
import ( | ||
"io/ioutil" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestFrozenFormat(t *testing.T) { | ||
tests := [...]struct{ | ||
name, frozenPath, portablePath string | ||
}{ | ||
{ | ||
name: "bitmaps only", | ||
frozenPath: "testfrozendata/bitmaps_only.frozen", | ||
portablePath: "testfrozendata/bitmaps_only.portable", | ||
}, | ||
{ | ||
name: "arrays only", | ||
frozenPath: "testfrozendata/arrays_only.frozen", | ||
portablePath: "testfrozendata/arrays_only.portable", | ||
}, | ||
{ | ||
name: "runs only", | ||
frozenPath: "testfrozendata/runs_only.frozen", | ||
portablePath: "testfrozendata/runs_only.portable", | ||
}, | ||
{ | ||
name: "mixed", | ||
frozenPath: "testfrozendata/mixed.frozen", | ||
portablePath: "testfrozendata/mixed.portable", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
// NOTE: opted for loading files twice rather than optimizing it because: | ||
// 1. It's still cheap enough, it's small files; and | ||
// 2. In a buggy scenario one of the tests may write into the buffer and cause | ||
// a race condition, making it harder to figure out why the tests fail. | ||
name, fpath, ppath := test.name, test.frozenPath, test.portablePath | ||
t.Run("view " + name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
frozenBuf, err := ioutil.ReadFile(fpath) | ||
if err != nil { | ||
t.Fatalf("failed to open %s: %s", fpath, err) | ||
} | ||
portableBuf, err := ioutil.ReadFile(ppath) | ||
if err != nil { | ||
t.Fatalf("failed to open %s: %s", ppath, err) | ||
} | ||
|
||
frozen, portable := New(), New() | ||
if err := frozen.FrozenView(frozenBuf); err != nil { | ||
t.Fatalf("failed to load bitmap from %s: %s", fpath, err) | ||
} | ||
if _, err := portable.FromBuffer(portableBuf); err != nil { | ||
t.Fatalf("failed to load bitmap from %s: %s", ppath, err) | ||
} | ||
|
||
if !frozen.Equals(portable) { | ||
t.Fatalf("bitmaps for %s and %s differ", fpath, ppath) | ||
} | ||
}) | ||
t.Run("freeze " + name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
frozenBuf, err := ioutil.ReadFile(fpath) | ||
if err != nil { | ||
t.Fatalf("failed to open %s: %s", fpath, err) | ||
} | ||
portableBuf, err := ioutil.ReadFile(ppath) | ||
if err != nil { | ||
t.Fatalf("failed to open %s: %s", ppath, err) | ||
} | ||
|
||
portable := New() | ||
if _, err := portable.FromBuffer(portableBuf); err != nil { | ||
t.Fatalf("failed to load bitmap from %s: %s", ppath, err) | ||
} | ||
|
||
frozenSize := portable.GetFrozenSizeInBytes() | ||
if int(frozenSize) != len(frozenBuf) { | ||
t.Errorf("size for serializing %s differs from %s's size", ppath, fpath) | ||
} | ||
frozen, err := portable.Freeze() | ||
if err != nil { | ||
t.Fatalf("can't freeze %s: %s", ppath, err) | ||
} | ||
if !reflect.DeepEqual(frozen, frozenBuf) { | ||
t.Fatalf("frozen file for %s and %s differ", fpath, ppath) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.