Beispiel #1
0
        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");
        }
Beispiel #2
0
        public void ColorBTest()
        {
            GraphicsRepository <Bitmap, Color> graphics = new GraphicsRepository <Bitmap, Color>();
            Color color = Color.Red;

            Assert.AreEqual(color.B, graphics.ColorB(color));
        }
Beispiel #3
0
        public void ColorFromArgbTest()
        {
            GraphicsRepository <Bitmap, Color> graphics = new GraphicsRepository <Bitmap, Color>();
            Color color = graphics.ColorFromArgb(0, 1, 2, 3);

            Assert.AreEqual(0, color.A);
            Assert.AreEqual(1, color.R);
            Assert.AreEqual(2, color.G);
            Assert.AreEqual(3, color.B);
        }
Beispiel #4
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);
        }
Beispiel #5
0
 public void CreateGraphicsObjectTest()
 {
     GraphicsRepository <Bitmap, Color> graphics = new GraphicsRepository <Bitmap, Color>();
     var gObject = graphics.CreateGraphicsObject(10, 10);
 }
Beispiel #6
0
 public void GetBackgroundColorTest()
 {
     GraphicsRepository <Bitmap, Color> graphics = new GraphicsRepository <Bitmap, Color>();
     Color bgColor = graphics.GetBackgroundColor();
 }