예제 #1
0
파일: Program.cs 프로젝트: MatasGos/BMAN
        public static void FlyweightDemo()
        {
            int       countOfIterations = 1000;
            Stopwatch sw = new Stopwatch();

            string[] pictures          = { "wall", "bomb", "box" };
            var      graphics          = new GraphicsRepository <Bitmap, Color>();
            var      picturesFlyweight = new PictureFlyweight <Bitmap, Color>();

            sw.Start();
            Color[,] temp;
            for (int i = 0; i < countOfIterations; i++)
            {
                GraphicsAdapter <Bitmap, Color> pic = graphics.CreateGraphicsObject(25, 25);
                pic.SetImage(Images.wall);
                temp = pic.GetColorArray();
                pic.SetImage(Images.bomb);
                temp = pic.GetColorArray();
                pic.SetImage(Images.box);
                temp = pic.GetColorArray();
            }
            sw.Stop();
            Console.WriteLine("Time to read " + countOfIterations + " elements without flyweight " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();
            sw.Start();
            for (int i = 0; i < countOfIterations; i++)
            {
                for (int j = 0; j < pictures.Length; j++)
                {
                    temp = picturesFlyweight.GetPictureArray(pictures[j]);
                }
            }
            sw.Stop();
            Console.WriteLine("Time to read " + countOfIterations + " elements with flyweight " + sw.ElapsedMilliseconds + "ms");
        }
예제 #2
0
        public void WrongTypesTest()
        {
            GraphicsRepository <Color, Bitmap> graphics = new GraphicsRepository <Color, Bitmap>();
            bool exceptionThrown = false;

            try
            {
                var bgColor = graphics.GetBackgroundColor();
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;
            try
            {
                var bgColor = graphics.CreateGraphicsObject(10, 10);
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;
            try
            {
                var bgColor = graphics.ColorFromArgb(10, 10, 10, 10);
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;
            try
            {
                var bgColor = graphics.ColorA(new Bitmap(10, 10));
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;
            try
            {
                var bgColor = graphics.ColorB(new Bitmap(10, 10));
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;
            try
            {
                var bgColor = graphics.ColorR(new Bitmap(10, 10));
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            exceptionThrown = false;
            try
            {
                var bgColor = graphics.ColorG(new Bitmap(10, 10));
            }
            catch
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
        }
예제 #3
0
 public void CreateGraphicsObjectTest()
 {
     GraphicsRepository <Bitmap, Color> graphics = new GraphicsRepository <Bitmap, Color>();
     var gObject = graphics.CreateGraphicsObject(10, 10);
 }