OSDN Git Service

PriorityQueueTest
authorkomutan <t_komuta@nifty.com>
Sat, 4 Apr 2015 15:09:00 +0000 (00:09 +0900)
committerkomutan <t_komuta@nifty.com>
Sat, 4 Apr 2015 15:09:00 +0000 (00:09 +0900)
src/LibNMeCabTest/PriorityQueueTest.cs [new file with mode: 0644]

diff --git a/src/LibNMeCabTest/PriorityQueueTest.cs b/src/LibNMeCabTest/PriorityQueueTest.cs
new file mode 100644 (file)
index 0000000..baf3b5b
--- /dev/null
@@ -0,0 +1,93 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace LibNMeCabTest
+{
+    [TestClass]
+    public class PriorityQueueTest
+    {
+        [TestMethod]
+        public void TestMethod1()
+        {
+            var target = new NMeCab.Core.PriorityQueue<int>();
+            var count = 0;
+
+            for (int i = 0; i < 10; i++)
+            {
+                for (int j = 0; j < 10; j++)
+                {
+                    target.Push(j);
+                    count++;
+                    Assert.AreEqual(target.Count, count);
+                }
+            }
+
+            int wrk1 = 0;
+            for (int k = 0; k < count; k++)
+            {
+                int wrk2 = target.Pop();
+                count--;
+                Assert.AreEqual(target.Count, count);
+                Assert.IsTrue(wrk1 <= wrk2);
+                wrk1 = wrk2;
+            }
+        }
+
+        [TestMethod]
+        public void TestMethod2()
+        {
+            var target = new NMeCab.Core.PriorityQueue<int>();
+            var count = 0;
+
+            for (int i = 0; i < 10; i++)
+            {
+                for (int j = 10; j >= 0; j--)
+                {
+                    target.Push(j);
+                    count++;
+                    Assert.AreEqual(target.Count, count);
+                }
+            }
+
+            int wrk1 = 0;
+            for (int k = 0; k < count; k++)
+            {
+                int wrk2 = target.Pop();
+                count--;
+                Assert.AreEqual(target.Count, count);
+                Assert.IsTrue(wrk1 <= wrk2);
+                wrk1 = wrk2;
+            }
+        }
+
+        [TestMethod]
+        public void TestMethod3()
+        {
+            var target = new NMeCab.Core.PriorityQueue<int>();
+            var count = 0;
+            var rnd = new Random();
+
+            for (int i = 0; i < 1000; i++)
+            {
+                int repeat = rnd.Next(10);
+                for (int j = 0; j < repeat; j++)
+                {
+                    target.Push(rnd.Next(10));
+                    count++;
+                    Assert.AreEqual(target.Count, count);
+                }
+
+                repeat = rnd.Next(target.Count);
+                int wrk1 = 0;
+                for (int k = 0; k < repeat; k++)
+                {
+                    int wrk2 = target.Pop();
+                    count--;
+                    Assert.AreEqual(target.Count, count);
+                    Assert.IsTrue(wrk1 <= wrk2);
+                    wrk1 = wrk2;
+                }
+            }
+        }
+    }
+}