@@ -2135,3 +2135,99 @@ func TestWord(t *testing.T) {
21352135 })
21362136 }
21372137}
2138+
2139+ func TestPreviousSet (t * testing.T ) {
2140+ v := New (128 )
2141+ v .Set (0 )
2142+ v .Set (2 )
2143+ v .Set (4 )
2144+ v .Set (120 )
2145+ for _ , tt := range []struct {
2146+ index uint
2147+ want uint
2148+ wantFound bool
2149+ }{
2150+ {0 , 0 , true },
2151+ {1 , 0 , true },
2152+ {2 , 2 , true },
2153+ {3 , 2 , true },
2154+ {4 , 4 , true },
2155+ {5 , 4 , true },
2156+ {100 , 4 , true },
2157+ {120 , 120 , true },
2158+ {121 , 120 , true },
2159+ {1024 , 0 , false },
2160+ } {
2161+ t .Run (fmt .Sprintf ("@%d" , tt .index ), func (t * testing.T ) {
2162+ got , found := v .PreviousSet (tt .index )
2163+ if got != tt .want || found != tt .wantFound {
2164+ t .Errorf ("PreviousSet(%d) = %d, %v, want %d, %v" , tt .index , got , found , tt .want , tt .wantFound )
2165+ }
2166+ })
2167+ }
2168+ v .ClearAll ()
2169+ for _ , tt := range []struct {
2170+ index uint
2171+ want uint
2172+ wantFound bool
2173+ }{
2174+ {0 , 0 , false },
2175+ {120 , 0 , false },
2176+ {1024 , 0 , false },
2177+ } {
2178+ t .Run (fmt .Sprintf ("@%d" , tt .index ), func (t * testing.T ) {
2179+ got , found := v .PreviousSet (tt .index )
2180+ if got != tt .want || found != tt .wantFound {
2181+ t .Errorf ("PreviousSet(%d) = %d, %v, want %d, %v" , tt .index , got , found , tt .want , tt .wantFound )
2182+ }
2183+ })
2184+ }
2185+ }
2186+
2187+ func TestPreviousClear (t * testing.T ) {
2188+ v := New (128 )
2189+ v .Set (0 )
2190+ v .Set (2 )
2191+ v .Set (4 )
2192+ v .Set (120 )
2193+ for _ , tt := range []struct {
2194+ index uint
2195+ want uint
2196+ wantFound bool
2197+ }{
2198+ {0 , 0 , false },
2199+ {1 , 1 , true },
2200+ {2 , 1 , true },
2201+ {3 , 3 , true },
2202+ {4 , 3 , true },
2203+ {5 , 5 , true },
2204+ {100 , 100 , true },
2205+ {120 , 119 , true },
2206+ {121 , 121 , true },
2207+ {1024 , 0 , false },
2208+ } {
2209+ t .Run (fmt .Sprintf ("@%d" , tt .index ), func (t * testing.T ) {
2210+ got , found := v .PreviousClear (tt .index )
2211+ if got != tt .want || found != tt .wantFound {
2212+ t .Errorf ("PreviousClear(%d) = %d, %v, want %d, %v" , tt .index , got , found , tt .want , tt .wantFound )
2213+ }
2214+ })
2215+ }
2216+ v .SetAll ()
2217+ for _ , tt := range []struct {
2218+ index uint
2219+ want uint
2220+ wantFound bool
2221+ }{
2222+ {0 , 0 , false },
2223+ {120 , 0 , false },
2224+ {1024 , 0 , false },
2225+ } {
2226+ t .Run (fmt .Sprintf ("@%d" , tt .index ), func (t * testing.T ) {
2227+ got , found := v .PreviousClear (tt .index )
2228+ if got != tt .want || found != tt .wantFound {
2229+ t .Errorf ("PreviousClear(%d) = %d, %v, want %d, %v" , tt .index , got , found , tt .want , tt .wantFound )
2230+ }
2231+ })
2232+ }
2233+ }
0 commit comments