コード例 #1
0
ファイル: BufferTester.cs プロジェクト: pawerrs/TSST-Project
        public void TestDivideQueueByFrequency()
        {
            //stworzenie bufora
            Buffer b = new Buffer();

            //i jego kolejki
            b.queue = generatePackageQueueFrequencies();

            //sortowanie po adresach IP
            b.queue = Buffer.sortQueueByFrequency(ref b.queue);

            //Podzial na grupy z konkretnymi adresami IP
            List <Queue <byte[]> > listOfQueues = Buffer.divideSortedQueueByFrequency(ref b.queue);

            //Wyciagniecie kolejek w postaci tablic bo wygodniej
            var array0 = listOfQueues[0].ToArray();
            var array1 = listOfQueues[1].ToArray();
            var array2 = listOfQueues[2].ToArray();

            //Sprawdzenie, czy czestotliwosci sie dobrze przydzielily
            Assert.AreEqual(1, Package.extractFrequency(array0[0]));
            Assert.AreEqual(1, Package.extractFrequency(array0[1]));
            Assert.AreEqual(2, Package.extractFrequency(array1[0]));
            Assert.AreEqual(2, Package.extractFrequency(array1[1]));
            Assert.AreEqual(3, Package.extractFrequency(array2[0]));
            Assert.AreEqual(3, Package.extractFrequency(array2[1]));
            Assert.AreEqual(3, Package.extractFrequency(array2[2]));
        }
コード例 #2
0
ファイル: BufferTester.cs プロジェクト: pawerrs/TSST-Project
        public void testSortQueue()
        {
            Buffer b = new Buffer();

            //generacja losowej kolejki
            b.queue = generatePackageQueueFrequencies();

            //sortowanie po czestotliwosci
            b.queue = Buffer.sortQueueByFrequency(ref b.queue);

            //lista z bajtami
            List <byte[]> packageBytes = new List <byte[]>();

            packageBytes.AddRange(b.queue);

            //Adresy IP powinny byc dobrze powpisywane
            Assert.AreEqual(1, Package.extractFrequency(packageBytes[0]));
            Assert.AreEqual(1, Package.extractFrequency(packageBytes[1]));
            Assert.AreEqual(2, Package.extractFrequency(packageBytes[2]));
            Assert.AreEqual(2, Package.extractFrequency(packageBytes[3]));
            Assert.AreEqual(3, Package.extractFrequency(packageBytes[4]));
            Assert.AreEqual(3, Package.extractFrequency(packageBytes[5]));
            Assert.AreEqual(3, Package.extractFrequency(packageBytes[6]));
        }
コード例 #3
0
ファイル: BufferTester.cs プロジェクト: pawerrs/TSST-Project
        public void testSort()
        {
            var array = generatePackageQueue().ToArray();

            Queue <byte[]> queue = new Queue <byte[]>();

            Package P;

            //tabela wartosci pola w naglowku, nieposortowane
            short[] shorts = { 5, 3, 6, 1, 2, 4, 0 };

            //Tworzenie nieposortowanej tablicy(wedlug nru pakietu)
            for (int i = 0; i < shorts.Length; i++)
            {
                P = new Package(array[i]);
                P.changePackageNumber(shorts[i]);
                array[i] = P.toBytes();
                queue.Enqueue(array[i]);
            }

            //sortowanie
            queue = Buffer.sortQueueByPackageNumber(ref queue);

            //sprawdzanie, czy sie posortowaly
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual(i, Package.extractPackageNumber(queue.Dequeue()));
            }

            //ID
            //Tworzenie nieposortowanej tablicy(wedlug ID)
            for (int i = 0; i < shorts.Length; i++)
            {
                P = new Package(array[i]);
                P.changeID(shorts[i]);
                array[i] = P.toBytes();
                queue.Enqueue(array[i]);
            }

            //sortowanie po ID
            queue = Buffer.sortQueueByID(ref queue);

            //srawdzanie, czy sie posortowaly
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual(i, Package.extractPackageNumber(queue.Dequeue()));
            }

            //Czestotliwosc
            //Tworzenie nieposortowanej tablicy(wedlug czestotliwosci)
            for (int i = 0; i < shorts.Length; i++)
            {
                P = new Package(array[i]);
                P.changeFrequency(shorts[i]);
                array[i] = P.toBytes();
                queue.Enqueue(array[i]);
            }

            //sortowanie po czestotliwosci
            queue = Buffer.sortQueueByFrequency(ref queue);

            //srawdzanie, czy sie posortowaly
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual(i, Package.extractPackageNumber(queue.Dequeue()));
            }
        }