<commit_before>﻿using ImagePipeline.Memory;
using ImagePipeline.Testing;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using System;
using System.Collections.Generic;
using Windows.Graphics.Imaging;

namespace ImagePipeline.Tests.Memory
{
    /**
     * Basic tests for BitmapPool 
     */
    [TestClass]
    public class BitmapPoolTests
    {
        private const int MAX_BUFFER_SIZE = 224;

        private BitmapPool _pool;

        [TestInitialize]
        public void Initialize()
        {
            _pool = new BitmapPool(
                new MockMemoryTrimmableRegistry(),
                new PoolParams(MAX_BUFFER_SIZE, new Dictionary<int, int>()),
                new MockPoolStatsTracker());
        }

        [TestMethod]
        public void TestFree()
        {
            SoftwareBitmap bitmap = _pool.Alloc(12);
            _pool.Free(bitmap);
            bool disposed = false;

            // Check if object has been disposed
            try
            {
                disposed = (bitmap.PixelWidth == 0);
            }
            catch (ObjectDisposedException e)
            {
                disposed = true;
            }

            Assert.IsTrue(disposed);
        }

        // Tests out the GetBucketedSize method
        [TestMethod]
        public void TestGetBucketedSize()
        {
            Assert.AreEqual(12, _pool.GetBucketedSize(12));
            Assert.AreEqual(56, _pool.GetBucketedSize(56));
        }

        // Tests out the GetBucketedSizeForValue method
        [TestMethod]
        public void TestGetBucketedSizeForValue()
        {
            SoftwareBitmap bitmap1 = _pool.Alloc(12);
            SoftwareBitmap bitmap2 = _pool.Alloc(56);
            SoftwareBitmap bitmap3 = MockBitmapFactory.Create(7, 8, BitmapPixelFormat.Rgba8);
            SoftwareBitmap bitmap4 = MockBitmapFactory.Create(7, 8, BitmapPixelFormat.Rgba16);
            Assert.AreEqual(12, _pool.GetBucketedSizeForValue(bitmap1));
            Assert.AreEqual(56, _pool.GetBucketedSizeForValue(bitmap2));
            Assert.AreEqual(224, _pool.GetBucketedSizeForValue(bitmap3));
            Assert.AreEqual(448, _pool.GetBucketedSizeForValue(bitmap4));
        }

        [TestMethod]
        public void TestGetSizeInBytes()
        {
            Assert.AreEqual(48, _pool.GetSizeInBytes(48));
            Assert.AreEqual(224, _pool.GetSizeInBytes(224));
        }

        // Test out bitmap reusability
        [TestMethod]
        public void TestIsReusable()
        {
            SoftwareBitmap b1 = _pool.Alloc(12);
            Assert.IsTrue(_pool.IsReusable(b1));
            SoftwareBitmap b2 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Bgra8);
            Assert.IsTrue(_pool.IsReusable(b2));
            SoftwareBitmap b3 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Gray16);
            Assert.IsTrue(_pool.IsReusable(b3));
            SoftwareBitmap b4 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Bgra8);
            b4.Dispose();
            Assert.IsFalse(_pool.IsReusable(b4));
            SoftwareBitmap b5 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Bgra8).GetReadOnlyView();
            Assert.IsFalse(_pool.IsReusable(b5));
        }
    }
}
<commit_msg>Updated unit tests.<commit_after>﻿using ImagePipeline.Memory;
using ImagePipeline.Testing;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using System;
using System.Collections.Generic;
using Windows.Graphics.Imaging;

namespace ImagePipeline.Tests.Memory
{
    /**
     * Basic tests for BitmapPool 
     */
    [TestClass]
    public class BitmapPoolTests
    {
        private const int MAX_BUFFER_SIZE = 224;

        private BitmapPool _pool;

        [TestInitialize]
        public void Initialize()
        {
            _pool = new BitmapPool(
                new MockMemoryTrimmableRegistry(),
                new PoolParams(MAX_BUFFER_SIZE, new Dictionary<int, int>()),
                new MockPoolStatsTracker());
        }

        [TestMethod]
        public void TestFree()
        {
            using (SoftwareBitmap bitmap = _pool.Alloc(12))
            {
                _pool.Free(bitmap);
                bool disposed = false;

                // Check if object has been disposed
                try
                {
                    disposed = (bitmap.PixelWidth == 0);
                }
                catch (ObjectDisposedException e)
                {
                    disposed = true;
                }

                Assert.IsTrue(disposed);
            }
        }

        // Tests out the GetBucketedSize method
        [TestMethod]
        public void TestGetBucketedSize()
        {
            Assert.AreEqual(12, _pool.GetBucketedSize(12));
            Assert.AreEqual(56, _pool.GetBucketedSize(56));
        }

        // Tests out the GetBucketedSizeForValue method
        [TestMethod]
        public void TestGetBucketedSizeForValue()
        {
            using (SoftwareBitmap bitmap1 = _pool.Alloc(12),
                                  bitmap2 = _pool.Alloc(56),
                                  bitmap3 = MockBitmapFactory.Create(7, 8, BitmapPixelFormat.Rgba8),
                                  bitmap4 = MockBitmapFactory.Create(7, 8, BitmapPixelFormat.Rgba16))
            {
                Assert.AreEqual(12, _pool.GetBucketedSizeForValue(bitmap1));
                Assert.AreEqual(56, _pool.GetBucketedSizeForValue(bitmap2));
                Assert.AreEqual(224, _pool.GetBucketedSizeForValue(bitmap3));
                Assert.AreEqual(448, _pool.GetBucketedSizeForValue(bitmap4));
            }
        }

        [TestMethod]
        public void TestGetSizeInBytes()
        {
            Assert.AreEqual(48, _pool.GetSizeInBytes(48));
            Assert.AreEqual(224, _pool.GetSizeInBytes(224));
        }

        // Test out bitmap reusability
        [TestMethod]
        public void TestIsReusable()
        {
            using (SoftwareBitmap b1 = _pool.Alloc(12),
                                  b2 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Bgra8),
                                  b3 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Gray16),
                                  b4 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Bgra8),
                                  b5 = MockBitmapFactory.Create(3, 4, BitmapPixelFormat.Bgra8).GetReadOnlyView())
            {
                Assert.IsTrue(_pool.IsReusable(b1));
                Assert.IsTrue(_pool.IsReusable(b2));
                Assert.IsTrue(_pool.IsReusable(b3));
                b4.Dispose();
                Assert.IsFalse(_pool.IsReusable(b4));
                Assert.IsFalse(_pool.IsReusable(b5));
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08961424332344213, 'fraction_numerical': 0.02344213649851632, 'mean_word_length': 1.7901490066225165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '934679', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1784, 'n_words': 326}