| 1881 | } |
| 1882 | |
| 1883 | func testBitset(t *testing.T, x *BigInt) { |
| 1884 | n := x.BitLen() |
| 1885 | z := new(BigInt).Set(x) |
| 1886 | z1 := new(BigInt).Set(x) |
| 1887 | for i := 0; i < n+10; i++ { |
| 1888 | old := z.Bit(i) |
| 1889 | old1 := altBit(z1, i) |
| 1890 | if old != old1 { |
| 1891 | t.Errorf("bitset: inconsistent value for Bit(%s, %d), got %v want %v", z1, i, old, old1) |
| 1892 | } |
| 1893 | z := new(BigInt).SetBit(z, i, 1) |
| 1894 | z1 := altSetBit(new(BigInt), z1, i, 1) |
| 1895 | if z.Bit(i) == 0 { |
| 1896 | t.Errorf("bitset: bit %d of %s got 0 want 1", i, x) |
| 1897 | } |
| 1898 | if z.Cmp(z1) != 0 { |
| 1899 | t.Errorf("bitset: inconsistent value after SetBit 1, got %s want %s", z, z1) |
| 1900 | } |
| 1901 | z.SetBit(z, i, 0) |
| 1902 | altSetBit(z1, z1, i, 0) |
| 1903 | if z.Bit(i) != 0 { |
| 1904 | t.Errorf("bitset: bit %d of %s got 1 want 0", i, x) |
| 1905 | } |
| 1906 | if z.Cmp(z1) != 0 { |
| 1907 | t.Errorf("bitset: inconsistent value after SetBit 0, got %s want %s", z, z1) |
| 1908 | } |
| 1909 | altSetBit(z1, z1, i, old) |
| 1910 | z.SetBit(z, i, old) |
| 1911 | if z.Cmp(z1) != 0 { |
| 1912 | t.Errorf("bitset: inconsistent value after SetBit old, got %s want %s", z, z1) |
| 1913 | } |
| 1914 | } |
| 1915 | if z.Cmp(x) != 0 { |
| 1916 | t.Errorf("bitset: got %s want %s", z, x) |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | var bitsetTests = []struct { |
| 1921 | x string |