Exemplo n.º 1
0
        public void TestSingleLine()
        {
            MyList<MyPoint> set1 = new MyList<MyPoint>();
            set1.Add(new MyPoint(1, 5));
            set1.Add(new MyPoint(2, 8));
            set1.Add(new MyPoint(3, 11));
            set1.Add(new MyPoint(4, 14));
            set1.Add(new MyPoint(5, 17));
            set1.Add(new MyPoint(6, 20));
            set1.Add(new MyPoint(7, 23));
            set1.Add(new MyPoint(8, 26));

            uint set = 0;
            for (int i = 0; i < 8; i++)
            {
             set |= (uint)Solution.PowOfTwo[i];
            }

            uint workSet = set;

            Assert.AreEqual(8, Solution.CountBits(workSet));

            int idxi = Solution.GetItemIndex(workSet, 0);
            int idxj = Solution.GetItemIndex(workSet, 1);

            uint currentLine = 0;
            currentLine |= (uint)Solution.PowOfTwo[idxi];
            currentLine |= (uint)Solution.PowOfTwo[idxj];
            LineParams par = new LineParams(set1[idxi], set1[idxj]);

            workSet &= (~currentLine);

            Assert.AreEqual(6, Solution.CountBits(workSet));

            int counter = Solution.CountBits(workSet);
            for (int k = counter-1; k >= 0; --k)
            {
                int id = Solution.GetItemIndex(workSet, k);
                if (par.IsCollinear(set1[id]))
                {
                    currentLine |= (uint)Solution.PowOfTwo[id];
                    workSet &= (uint)~Solution.PowOfTwo[id];
                }
                else
                {
                    throw new Exception("All points should be in this line");
                }
            }
            Assert.AreEqual(8, Solution.CountBits(currentLine));
        }
Exemplo n.º 2
0
        public void SpeedTest2()
        {
            ItemSet seta = new ItemSet();
            seta.SetUp(10);

            for (int i = 0; i < 100000; ++i)
            {
                MyList<MyPoint> set1 = new MyList<MyPoint>();
                set1.Add(new MyPoint(1, 6));
                set1.Add(new MyPoint(2, 6));
                set1.Add(new MyPoint(5, 6));
                set1.Add(new MyPoint(3, 6));
                set1.Add(new MyPoint(2, 5));
                set1.Add(new MyPoint(3, 5));
                set1.Add(new MyPoint(5, 5));
                set1.Add(new MyPoint(3, 4));
                set1.Add(new MyPoint(3, 7));
                set1.Add(new MyPoint(6, 4));

                ItemSet workSet = seta.Clone();
                ItemSet currentLine = new ItemSet();

                currentLine.Add(0);
                currentLine.Add(1);
                LineParams par = new LineParams(set1[0], set1[1]);

                workSet.RemoveAt(0);
                workSet.RemoveAt(1);

                for (int k = 0; k < workSet.Count; ++k)
                {
                    int id = workSet.GetItemIndex(k);
                    if (par.IsCollinear(set1[id]))
                    {
                        currentLine.Add(id);
                        workSet.RemoveAt(id);
                    }
                }
            }
        }