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

Function TestRle16InversionOfIntervals018

runcontainer_test.go:1436–1489  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1434}
1435
1436func TestRle16InversionOfIntervals018(t *testing.T) {
1437 t.Run("runContainer `invert` operation should do a NOT on the set of intervals, in-place", func(t *testing.T) {
1438 seed := int64(42)
1439 rand.Seed(seed)
1440
1441 trials := []trial{
1442 {n: 1000, percentFill: .90, ntrial: 1},
1443 }
1444
1445 tester := func(tr trial) {
1446 for j := 0; j < tr.ntrial; j++ {
1447 ma := make(map[int]bool)
1448 hashNotA := make(map[int]bool)
1449
1450 n := tr.n
1451 a := []uint16{}
1452
1453 // hashNotA will be NOT ma
1454 // for i := 0; i < n; i++ {
1455 for i := 0; i < MaxUint16+1; i++ {
1456 hashNotA[i] = true
1457 }
1458
1459 draw := int(float64(n) * tr.percentFill)
1460 for i := 0; i < draw; i++ {
1461 r0 := rand.Intn(n)
1462 a = append(a, uint16(r0))
1463 ma[r0] = true
1464 delete(hashNotA, r0)
1465 }
1466
1467 // RunContainer's invert
1468 rc := newRunContainer16FromVals(false, a...)
1469
1470 inv := rc.invert()
1471
1472 assert.Equal(t, 1+MaxUint16-rc.getCardinality(), inv.getCardinality())
1473
1474 for k := 0; k < n; k++ {
1475 if hashNotA[k] {
1476 assert.True(t, inv.contains(uint16(k)))
1477 }
1478 }
1479
1480 // skip for now, too big to do 2^16-1
1481 assert.Equal(t, len(hashNotA), inv.getCardinality())
1482 }
1483 }
1484
1485 for i := range trials {
1486 tester(trials[i])
1487 }
1488 })
1489}
1490
1491func TestRle16SubtractionOfIntervals019(t *testing.T) {
1492 t.Run("runContainer `subtract` operation removes an interval in-place", func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

invertMethod · 0.80
getCardinalityMethod · 0.65
containsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…