| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package bf | |
| 6 | |
| 7 import ( | |
| 8 "testing" | |
| 9 | |
| 10 . "github.com/smartystreets/goconvey/convey" | |
| 11 ) | |
| 12 | |
| 13 func TestBitField(t *testing.T) { | |
| 14 Convey("BitField", t, func() { | |
| 15 bf := Make(2000) | |
| 16 | |
| 17 Convey("Should be sized right", func() { | |
| 18 So(bf.Size(), ShouldEqual, 2000) | |
| 19 So(len(bf.Data), ShouldEqual, 32) | |
| 20 }) | |
| 21 | |
| 22 Convey("Should be empty", func() { | |
| 23 So(bf.All(false), ShouldBeTrue) | |
| 24 So(bf.Data[0], ShouldEqual, 0) | |
| 25 So(bf.CountSet(), ShouldEqual, 0) | |
| 26 So(bf.IsSet(20), ShouldBeFalse) | |
| 27 So(bf.IsSet(200001), ShouldBeFalse) | |
| 28 | |
| 29 Convey("and be unset", func() { | |
| 30 for i := uint64(0); i < 20; i++ { | |
| 31 So(bf.IsSet(i), ShouldBeFalse) | |
| 32 } | |
| 33 }) | |
| 34 }) | |
| 35 | |
| 36 Convey("Boundary conditions are caught", func() { | |
| 37 So(bf.Set(2000), ShouldNotBeNil) | |
| 38 So(bf.Clear(2000), ShouldNotBeNil) | |
| 39 }) | |
| 40 | |
| 41 Convey("and setting [0, 1, 19, 197, 4]", func() { | |
| 42 So(bf.Set(0), ShouldBeNil) | |
| 43 So(bf.Set(1), ShouldBeNil) | |
| 44 So(bf.Set(19), ShouldBeNil) | |
| 45 So(bf.Set(197), ShouldBeNil) | |
| 46 So(bf.Set(1999), ShouldBeNil) | |
| 47 So(bf.Set(4), ShouldBeNil) | |
| 48 | |
| 49 Convey("should count correctly", func() { | |
| 50 So(bf.CountSet(), ShouldEqual, 6) | |
| 51 }) | |
| 52 | |
| 53 Convey("should retrieve correctly", func() { | |
| 54 So(bf.IsSet(2), ShouldBeFalse) | |
| 55 So(bf.IsSet(18), ShouldBeFalse) | |
| 56 | |
| 57 So(bf.IsSet(0), ShouldBeTrue) | |
| 58 So(bf.IsSet(1), ShouldBeTrue) | |
| 59 So(bf.IsSet(4), ShouldBeTrue) | |
| 60 So(bf.IsSet(19), ShouldBeTrue) | |
| 61 So(bf.IsSet(197), ShouldBeTrue) | |
| 62 So(bf.IsSet(1999), ShouldBeTrue) | |
| 63 }) | |
| 64 | |
| 65 Convey("should clear correctly", func() { | |
| 66 So(bf.Clear(3), ShouldBeNil) | |
| 67 So(bf.Clear(4), ShouldBeNil) | |
| 68 So(bf.Clear(197), ShouldBeNil) | |
| 69 | |
| 70 So(bf.IsSet(2), ShouldBeFalse) | |
| 71 So(bf.IsSet(3), ShouldBeFalse) | |
| 72 So(bf.IsSet(18), ShouldBeFalse) | |
| 73 | |
| 74 So(bf.IsSet(4), ShouldBeFalse) | |
| 75 So(bf.IsSet(197), ShouldBeFalse) | |
| 76 | |
| 77 So(bf.IsSet(0), ShouldBeTrue) | |
| 78 So(bf.IsSet(1), ShouldBeTrue) | |
| 79 So(bf.IsSet(19), ShouldBeTrue) | |
| 80 | |
| 81 So(bf.CountSet(), ShouldEqual, 4) | |
| 82 }) | |
| 83 }) | |
| 84 }) | |
| 85 } | |
| OLD | NEW |