예제 #1
0
 public void When_calling_ToString_on_a_BitSet()
 {
     var sut = new Pdb70BitSet(0);
     sut[0] = true;
     sut[1] = true;
     sut[3] = true;
     sut[5] = true;
     sut[31] = true;
     Assert.Equal(
         "1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1",
         sut.ToString());
 }
예제 #2
0
        public void When_expanding_an_empty_BitSet_it_should_expand()
        {
            var sut = new Pdb70BitSet(0);
            sut[0] = true;

            Assert.NotNull(sut.Words);
            Assert.Equal(1, sut.Words.Length);
            Assert.False(sut.IsEmpty);

            Assert.Equal(1u, sut.Words[0]);
            Assert.True(sut[0]);

            sut[0] = false;

            Assert.Equal(0u, sut.Words[0]);
            Assert.False(sut[0]);

            sut[0x28] = true;

            Assert.Equal(2, sut.Words.Length);
            Assert.Equal(0x100u, sut.Words[1]);
            Assert.True(sut[0x28]);
        }
예제 #3
0
        /// <summary>
        /// Asynchronously reads a bit set from the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A <see cref="Task{Pdb20BitSet}"/> that represents the asynchronous read operation.
        /// </returns>
        public static async Task<Pdb70BitSet> ReadAsync(AsyncBinaryReader reader, CancellationToken cancellationToken)
        {
            var result = new Pdb70BitSet(await reader.ReadInt32Async(cancellationToken));
            if (result.Words.Length != 0)
            {
                var bytes = await reader.ReadBytesAsync(result.Words.Length * sizeof(int), cancellationToken);
                Buffer.BlockCopy(bytes, 0, result.Words, 0, bytes.Length);
            }

            return result;
        }
예제 #4
0
 public void When_calling_ToString_on_an_empty_BitSet()
 {
     var sut = new Pdb70BitSet(0);
     Assert.Equal("", sut.ToString());
 }
예제 #5
0
        public async Task When_writing_a_bit_set()
        {
            var sut = new Pdb70BitSet();
            sut[0x0] = true;
            sut[0x28] = true;

            var ms = new MemoryStream();
            var writer = new AsyncBinaryWriter(new TestStream(ms));
            await sut.WriteAsync(writer, CancellationToken.None);

            Assert.Equal(new byte[] {
                2, 0, 0, 0,
                1, 0, 0, 0,
                0, 1, 0, 0
            }, ms.ToArray());
        }
예제 #6
0
 public void When_creating_an_empty_BitSet()
 {
     var sut = new Pdb70BitSet(0);
     Assert.Equal(0, sut.Words.Length);
     Assert.True(sut.IsEmpty);
 }
예제 #7
0
        public void When_deallocating_in_a_BitSet_free_list()
        {
            var sut = new Pdb70BitSet();
            sut[0x28] = false; // Allocates two words

            sut.Deallocate(0x28);
            Assert.Equal(2, sut.Words.Length);
            Assert.True(sut[0x28]);
        }
예제 #8
0
        public void When_allocating_in_a_null_BitSet_free_list()
        {
            var sut = new Pdb70BitSet();

            var index = sut.Allocate();
            Assert.Equal(0x0, index);
            Assert.False(sut[0x0]);
        }
예제 #9
0
 public void When_creating_a_null_BitSet()
 {
     var sut = new Pdb70BitSet();
     Assert.Null(sut.Words);
     Assert.True(sut.IsEmpty);
 }
예제 #10
0
        public void When_allocating_in_a_BitSet_free_list()
        {
            var sut = new Pdb70BitSet();
            sut[0x28] = true;

            var index = sut.Allocate();
            Assert.Equal(0x28, index);
            Assert.False(sut[0x28]);

            index = sut.Allocate();
            Assert.Equal(0x40, index);
            Assert.Equal(3, sut.Words.Length);
            Assert.Equal(0xFFFFFFFFu ^ 0x1u, sut.Words[2]);
        }
예제 #11
0
        public void When_retrieving_an_item_past_the_end_of_a_bitset()
        {
            var sut = new Pdb70BitSet();
            sut.Words = new uint[] { 0u };

            Assert.False(sut[64]);
            Assert.Equal(1, sut.Words.Length);
        }