Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix testcase and add a new one

  • Loading branch information...
commit 5ee17ed1aecd9f7612f4adf32d41a0cd9c400e0d 1 parent 737678e
@lformella authored
View
2  Server.Plugin.General.Webserver.Test/Json.cs
@@ -102,7 +102,7 @@ public void Serialize()
bot.AddPacket(packet);
Assert.AreEqual(
- "{\"State\":0,\"LastMessage\":\"Test Message\",\"LastMessageTime\":\"" + JsonDate(bot.LastMessageTime) + "\",\"LastContact\":\"" + JsonDate(bot.LastContact) + "\",\"QueuePosition\":16,\"QueueTime\":16,\"InfoSpeedMax\":16,\"InfoSpeedCurrent\":16,\"InfoSlotTotal\":16,\"InfoSlotCurrent\":16,\"InfoQueueTotal\":16,\"InfoQueueCurrent\":16,\"Speed\":0,\"ParentGuid\":\"00000000-0000-0000-0000-000000000000\",\"Guid\":\"00000000-0000-0000-0000-000000000000\",\"Name\":\"Test Bot\",\"Connected\":true,\"Enabled\":true}",
+ "{\"State\":0,\"LastMessage\":\"Test Message\",\"LastMessageTime\":\"" + JsonDate(bot.LastMessageTime) + "\",\"LastContact\":\"" + JsonDate(bot.LastContact) + "\",\"QueuePosition\":16,\"QueueTime\":16,\"InfoSpeedMax\":16,\"InfoSpeedCurrent\":16,\"InfoSlotTotal\":16,\"InfoSlotCurrent\":16,\"InfoQueueTotal\":16,\"InfoQueueCurrent\":16,\"Speed\":0,\"HasNetworkProblems\":false,\"ParentGuid\":\"00000000-0000-0000-0000-000000000000\",\"Guid\":\"00000000-0000-0000-0000-000000000000\",\"Name\":\"Test Bot\",\"Connected\":true,\"Enabled\":true}",
JsonConvert.SerializeObject(bot, jsonSerializerSettings)
);
}
View
2  Server.Plugin.General.Webserver.Test/Server.Plugin.General.Webserver.Test.mdp
@@ -15,6 +15,8 @@
</Configurations>
<Contents>
<File subtype="Code" buildaction="Compile" name="Json.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Websocket" />
+ <File subtype="Code" buildaction="Compile" name="Websocket/Server.cs" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
View
78 Server.Plugin.General.Webserver.Test/Websocket/Server.cs
@@ -0,0 +1,78 @@
+//
+// Server.cs
+//
+// Author:
+// Lars Formella <ich@larsformella.de>
+//
+// Copyright (c) 2012 Lars Formella
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+
+using System;
+using NUnit.Framework;
+
+using XG.Server.Plugin.General.Webserver.Websocket;
+using System.Collections.Generic;
+
+namespace XG.Server.Plugin.General.Webserver.Websocket.Test
+{
+ [TestFixture()]
+ public class Server
+ {
+ [Test()]
+ public void FilterDuplicateEntries ()
+ {
+ var server = new Websocket.Server();
+
+ var oldList = new List<Int64[]>();
+ oldList.Add(new Int64[]{11, 1});
+ oldList.Add(new Int64[]{12, 1});
+ oldList.Add(new Int64[]{13, 2});
+ oldList.Add(new Int64[]{14, 2});
+ oldList.Add(new Int64[]{15, 2});
+ oldList.Add(new Int64[]{16, 2});
+ oldList.Add(new Int64[]{17, 3});
+ oldList.Add(new Int64[]{18, 3});
+ oldList.Add(new Int64[]{19, 3});
+ oldList.Add(new Int64[]{20, 1});
+ oldList.Add(new Int64[]{21, 1});
+ oldList.Add(new Int64[]{22, 2});
+ oldList.Add(new Int64[]{23, 2});
+ oldList.Add(new Int64[]{24, 3});
+ oldList.Add(new Int64[]{25, 1});
+ oldList.Add(new Int64[]{26, 1});
+ oldList.Add(new Int64[]{27, 1});
+
+ var newList = new List<Int64[]>();
+ newList.Add(new Int64[]{11, 1});
+ newList.Add(new Int64[]{12, 1});
+ newList.Add(new Int64[]{13, 2});
+ newList.Add(new Int64[]{16, 2});
+ newList.Add(new Int64[]{17, 3});
+ newList.Add(new Int64[]{19, 3});
+ newList.Add(new Int64[]{20, 1});
+ newList.Add(new Int64[]{21, 1});
+ newList.Add(new Int64[]{22, 2});
+ newList.Add(new Int64[]{23, 2});
+ newList.Add(new Int64[]{24, 3});
+ newList.Add(new Int64[]{25, 1});
+ newList.Add(new Int64[]{27, 1});
+
+ Assert.AreEqual(newList, server.FilterDuplicateEntries(oldList.ToArray()));
+ }
+ }
+}
+
View
31 Server.Plugin.General.Webserver/Websocket/Server.cs
@@ -740,6 +740,37 @@ Flot[] Snapshots2Flot(Snapshots aSnapshots)
return tObjects.ToArray();
}
+ public Int64[][] FilterDuplicateEntries(Int64[][] aEntries)
+ {
+ var list = new List<Int64[]>();
+
+ Int64[] prev = {0, -1};
+ Int64[] stack = null;
+ foreach (Int64[] data in aEntries)
+ {
+ if (prev[1] != data[1])
+ {
+ if (stack != null)
+ {
+ list.Add(stack);
+ stack = null;
+ }
+ list.Add(data);
+ prev = data;
+ }
+ else
+ {
+ stack = data;
+ }
+ }
+ if (stack != null)
+ {
+ list.Add(stack);
+ }
+
+ return list.ToArray();
+ }
+
#endregion
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.