Ejemplo n.º 1
0
        [TestMethod]//23
        public void Zip_CheckArrayOrder_TwoListsOfInts()
        {
            // arrange

            ListB <int> listB      = new ListB <int>();
            ListB <int> listA      = new ListB <int>();
            ListB <int> zippedList = new ListB <int>();
            int         expected   = 5;
            int         actual;

            //act
            listB.Add(1);
            listB.Add(7);
            listB.Add(9);
            listB.Add(2);
            listA.Add(4);
            listA.Add(8);
            listA.Add(5);
            listA.Add(6);
            listA.Add(5);

            zippedList = listB.Zip(listA);



            actual = zippedList[5];


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        [TestMethod]//21
        public void Zip_CheckCount_TwoListsOfInts()
        {
            // arrange

            ListB <int> listB      = new ListB <int>();
            ListB <int> listA      = new ListB <int>();
            ListB <int> zippedList = new ListB <int>();
            int         expected   = 9;
            int         actual;

            //act
            listB.Add(1);
            listB.Add(2);
            listB.Add(3);
            listB.Add(5);
            listA.Add(1);
            listA.Add(4);
            listA.Add(5);
            listA.Add(6);
            listA.Add(7);

            zippedList = listB.Zip(listA);



            actual = zippedList.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        [TestMethod]//23
        public void Zip_CheckArrayOrder_TwoListsOfStrings()
        {
            // arrange

            ListB <string> listB      = new ListB <string>();
            ListB <string> listA      = new ListB <string>();
            ListB <string> zippedList = new ListB <string>();
            string         expected   = "R";
            string         actual;

            //act
            listB.Add("A");
            listB.Add("B");
            listB.Add("C");
            listB.Add("D");
            listA.Add("Z");
            listA.Add("R");
            listA.Add("S");
            listA.Add("T");
            listA.Add("U");

            zippedList = listB.Zip(listA);



            actual = zippedList[3];


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        [TestMethod]//15
        public void OverloadAdditionOfLists_CheckCount_TwoListsOfIntegers()
        {
            // arrange

            ListB <int> listB        = new ListB <int>();
            ListB <int> listA        = new ListB <int>();
            ListB <int> combinedList = new ListB <int>();
            int         expected     = 8;
            int         actual;

            //act
            listB.Add(3);
            listB.Add(9);
            listB.Add(55);
            listA.Add(22);
            listA.Add(23);
            listA.Add(24);
            listA.Add(25);
            listA.Add(26);

            combinedList = listB + listA;



            actual = combinedList.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        [TestMethod]//22
        public void Zip_CheckCount_TwoListsOfStrings()
        {
            // arrange

            ListB <string> listB      = new ListB <string>();
            ListB <string> listA      = new ListB <string>();
            ListB <string> zippedList = new ListB <string>();
            int            expected   = 9;
            int            actual;

            //act
            listB.Add("A");
            listB.Add("A");
            listB.Add("A");
            listB.Add("A");
            listA.Add("A");
            listA.Add("A");
            listA.Add("A");
            listA.Add("A");
            listA.Add("A");

            zippedList = listB.Zip(listA);



            actual = zippedList.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public int Pop()
        {
            if (IsEmpty)
            {
                throw new KeyNotFoundException("Heap is empty");
            }

            int value;

            if (ListA.Count > 0 && ListB.Count > 0)
            {
                if (ListA[0] <= ListB[0])
                {
                    value = ListA[0];
                    ListA.RemoveAt(0);
                }
                else
                {
                    value = ListB[0];
                    ListB.RemoveAt(0);
                }
            }
            else if (ListA.Count > 0)
            {
                value = ListA[0];
                ListA.RemoveAt(0);
            }
            else
            {
                value = ListB[0];
                ListB.RemoveAt(0);
            }

            return(value);
        }
Ejemplo n.º 7
0
        [TestMethod]//18
        public void OverloadSubtractionOfLists_CheckCount_TwoListsOfStrings()
        {
            // arrange

            ListB <string> listB        = new ListB <string>();
            ListB <string> listA        = new ListB <string>();
            ListB <string> combinedList = new ListB <string>();
            int            expected     = 2;
            int            actual;

            //act
            listB.Add("B");
            listB.Add("e");
            listB.Add("n");
            listA.Add("B");
            listA.Add("a");
            listA.Add("m");
            listA.Add("i");
            listA.Add("p");

            combinedList = listB - listA;



            actual = combinedList.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        [TestMethod]//7
        public void Remove_CheckCount_RemoveMultipleValues()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            int         expected = 2;
            int         actual;

            //act
            listB.Add(24);
            listB.Add(12);
            listB.Add(56);
            listB.Add(2);
            listB.Add(3);
            listB.Add(53);
            listB.Remove(24);
            listB.Remove(3);
            listB.Remove(56);
            listB.Remove(53);
            actual = listB.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public void OverloadAdditionOfLists_CheckCount_TwoListsOfStrings()
        {
            // arrange

            ListB<string> listB = new ListB<string>();
            ListB<string> listA = new ListB<string>();
            ListB<string> combinedList = new ListB<string>();
            int expected = 8;
            int actual;

            //act
            listB.Add("J");
            listB.Add("e");
            listB.Add("f");
            listA.Add("f");
            listA.Add("r");
            listA.Add("e");
            listA.Add("y");
            listA.Add("C");

            combinedList = listB + listA;



            actual = combinedList.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public void ToString_CheckCoversion_ListOfStrings()
        {
            // arrange

            ListB<string> listB = new ListB<string>();
            string expected = "Packers Suck";
            string actual;

            //act
            listB.Add("P");
            listB.Add("a");
            listB.Add("c");
            listB.Add("k");
            listB.Add("e");
            listB.Add("r");
            listB.Add("s");
            listB.Add(" ");
            listB.Add("S");
            listB.Add("u");
            listB.Add("c");
            listB.Add("k");


            actual = listB.ToString();


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        [TestMethod]//20
        public void OverloadSubtractionOfLists_CheckCountOfOriginalList_TwoListsOfInts()
        {
            // arrange

            ListB <int> listB        = new ListB <int>();
            ListB <int> listA        = new ListB <int>();
            ListB <int> combinedList = new ListB <int>();
            int         expected     = 3;
            int         actual;

            //act
            listB.Add(1);
            listB.Add(2);
            listB.Add(3);
            listA.Add(1);
            listA.Add(4);
            listA.Add(5);
            listA.Add(6);
            listA.Add(7);

            combinedList = listB - listA;



            actual = listB.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void Drawitem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            e.DrawBackground();
            e.DrawFocusRectangle();
            var _with12 = e.Graphics;

            _with12.SmoothingMode     = SmoothingMode.HighQuality;
            _with12.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            _with12.InterpolationMode = InterpolationMode.HighQualityBicubic;
            _with12.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            if (String.Compare(e.State.ToString(), "Selected,") > 0)
            {
                _with12.FillRectangle(new SolidBrush(_BaseColour), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
                _with12.DrawLine(new Pen(_BorderColour), e.Bounds.X, e.Bounds.Y + e.Bounds.Height, e.Bounds.Width, e.Bounds.Y + e.Bounds.Height);
                _with12.DrawString(" " + ListB.GetItemText(Items[e.Index]), new Font("Segoe UI", 9, FontStyle.Bold), new SolidBrush(_TextColour), e.Bounds.X, e.Bounds.Y + 2);
            }
            else
            {
                _with12.FillRectangle(new SolidBrush(_BaseColour), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
                _with12.DrawString(" " + ListB.GetItemText(Items[e.Index]), new Font("Segoe UI", 8), new SolidBrush(_TextColour), e.Bounds.X, e.Bounds.Y + 2);
            }
            _with12.Dispose();
        }
Ejemplo n.º 13
0
        [TestMethod]//17
        public void OverloadAdditionOfLists_CheckArrayOrderAfterCombining_TwoListsOfStrings()
        {
            // arrange

            ListB <string> listB        = new ListB <string>();
            ListB <string> listA        = new ListB <string>();
            ListB <string> combinedList = new ListB <string>();
            string         expected     = "m";
            string         actual;

            //act
            listB.Add("B");
            listB.Add("e");
            listB.Add("n");
            listA.Add("j");
            listA.Add("a");
            listA.Add("m");
            listA.Add("i");
            listA.Add("n");

            combinedList = listB + listA;



            actual = combinedList[5];


            //assert
            Assert.AreEqual(expected, actual);
        }
    static void Main(string[] args)
    {
        var specialList = new List <C>();

        specialList.AddRange(listA.Where(x => ListB.Where(c => c.Name == x.Name).Any()).Select(x => new C()
        {
            Name = x.Name
        }));
    }
Ejemplo n.º 15
0
    private static void Main(string[] args)
    {
        IMyList a = new ListA {
            new ClassA {
                ClassAFoo = "I'm an A"
            }
        };
        IMyList b = new ListB {
            new ClassB {
                ClassBFoo = "I'm a B"
            }
        };

        a.CommonOperation();
        b.CommonOperation();
    }
Ejemplo n.º 16
0
        [TestMethod]//2
        public void Add_CheckCount_AddPositiveNumber()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            int         value    = 23;
            int         expected = 1;
            int         actual;

            //act
            listB.Add(value);
            actual = listB.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void Indexer_CheckForExceptionCode()
        {
            ListB <int> listB = new ListB <int>();



            //act
            listB.Add(23);
            listB.Add(33);
            listB.Add(43);
            listB.Add(38);
            listB.Add(55);

            Console.WriteLine($"{listB[7]}");

            //assert
        }
Ejemplo n.º 18
0
        /// <summary>
        /// performs exactly one iteration of the algorithm
        /// </summary>
        public override void DoOneRun()
        {
            if (Finished)
            {
                throw new GSTException("algorithm is finished");
            }

            var watch = Stopwatch.StartNew();

            var listMatches = new List <Tile <T> >();

            LastMaximumMatch = MinimumMatchLength;

            // for every token in A that is unmarked
            foreach (var tA in ListA.Where(t => !t.Marked))
            {
                var tokA = tA; // CLOSURE
                int indA = ListA.IndexOf(tokA);

                // for every token in B that is unmarked and matches tokA
                foreach (var tB in ListB.Where(t => !t.Marked).Where(tokA.EqualsTokenValue))
                {
                    //counter++;
                    var tokB = tB; // CLOSURE
                    int indB = ListB.IndexOf(tokB);

                    int matchLength = CalculateMatchLength(indA, indB);

                    if (matchLength >= LastMaximumMatch)
                    {
                        var tile = AbstractGSTAlgorithm.CreateTile(ListA, indA, indB, matchLength);
                        AddTileToMatchList(listMatches, matchLength, tile);
                    }
                } // foreach in B
            }     // foreach in A

            foreach (var tile in listMatches)
            {
                MarkTileAsMatched(tile);
                ListTiles.Add(tile);
            }

            TilesMatchedInLastRun = listMatches;
            //Console.WriteLine("one run({1}) took {0} ms", watch.ElapsedMilliseconds, counter);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// compares two lists of HashingEntity objects
        /// </summary>
        /// <param name="listA"></param>
        /// <param name="listB"></param>
        private void CompareLists(IList <HashingEntity> listA, IList <HashingEntity> listB)
        {
            foreach (var entityA in listA)
            {
                var indA = ListA.IndexOf(entityA.Tokens[0]);
                //Console.WriteLine("indexA: " + indA);
                foreach (var entityB in listB)
                {
                    var indB = ListB.IndexOf(entityB.Tokens[0]);

                    int matchLength = CalculateMatchLength(indA, indB);
                    //Console.WriteLine("indexB: {0}, ML: {1}", indB, matchLength);
                    if (matchLength >= LastMaximumMatch)
                    {
                        var tile = AbstractGSTAlgorithm.CreateTile(ListA, indA, indB, matchLength);
                        AddTileToMatchList(MatchesList, matchLength, tile);
                    }
                } // foreach in B
            }     // foreach in A
        }
Ejemplo n.º 20
0
        [TestMethod]//11
        public void Remove_CheckCount_RemoveAValueThatHasADuplicateValue()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            int         expected = 3;
            int         actual;

            //act
            listB.Add(24);
            listB.Add(12);
            listB.Add(24);
            listB.Add(33);
            listB.Remove(24);

            actual = listB.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 21
0
        [TestMethod]//3
        public void Add_CheckIfNewArrayIsMade_Add5thElement()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            int         value    = 23;
            int         expected = 8;
            int         actual;

            //act
            listB.Add(value);
            listB.Add(value + 10);
            listB.Add(value + 20);
            listB.Add(value + 15);
            listB.Add(value + 32);
            actual = listB.Capacity;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 22
0
        public void ToString_CheckCoversion_ListOfDoubles()
        {
            // arrange

            ListB<double> listB = new ListB<double>();
            string expected = "56.323.21";
            string actual;

            //act
            listB.Add(56.32);
            listB.Add(3.21);




            actual = listB.ToString();


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 23
0
        [TestMethod]//5
        public void Add_CheckArrayOrderStayedSame_Add5thElement()
        {
            // arrange

            ListB <int> listB = new ListB <int>();

            int expected = 43;
            int actual   = 0;

            //act
            listB.Add(23);
            listB.Add(33);
            listB.Add(43);
            listB.Add(38);
            listB.Add(55);


            actual = listB[2];
            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 24
0
        [TestMethod]//4
        public void Add_CheckListCount_Add5thElement()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            int         value    = 23;
            int         expected = 5;
            int         actual;

            //act
            listB.Add(value);
            listB.Add(value + 10);
            listB.Add(value + 20);
            listB.Add(value + 15);
            listB.Add(value + 32);
            actual = listB.Count;


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        [TestMethod]//14
        public void ToString_CheckCoversion_ListOfStrings()
        {
            // arrange

            ListB <string> listB    = new ListB <string>();
            string         expected = "BenJ";
            string         actual;

            //act
            listB.Add("B");
            listB.Add("e");
            listB.Add("n");
            listB.Add("J");



            actual = listB.ToString();


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 26
0
        [TestMethod]//8
        public void Remove_CheckIndexOrder_RemoveMiddleValue()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            int         expected = 3;
            int         actual;

            //act
            listB.Add(24);
            listB.Add(12);
            listB.Add(56);
            listB.Add(2);
            listB.Add(3);
            listB.Add(53);
            listB.Remove(2);
            actual = listB[3];


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 27
0
        [TestMethod]//13
        public void ToString_CheckCoversion_ListOfIntegers()
        {
            // arrange

            ListB <int> listB    = new ListB <int>();
            string      expected = "3456";
            string      actual;

            //act
            listB.Add(3);
            listB.Add(4);
            listB.Add(5);
            listB.Add(6);



            actual = listB.ToString();


            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dirA"></param>
        /// <param name="dirB"></param>
        public DirComparison(string dirA, string dirB)
        {
            this.DirA = dirA;
            this.DirB = dirB;
            ListA     = DirComparison.Parse(dirA);
            ListB     = DirComparison.Parse(dirB);

            DiffersInA = new List <DirItem>();
            foreach (DirItem item in ListA)
            {
                if (!ListB.Contains(item))
                {
                    DiffersInA.Add(item);
                }
            }
            DiffersInB = new List <DirItem>();
            foreach (DirItem item in ListB)
            {
                if (!ListA.Contains(item))
                {
                    DiffersInB.Add(item);
                }
            }
        }