[longomatch] Start adding tests back
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Start adding tests back
- Date: Fri, 27 Feb 2015 10:31:11 +0000 (UTC)
commit 92494e53119103e92f38b8c322bdaee612bcde5f
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Feb 26 21:16:01 2015 +0100
Start adding tests back
LongoMatch.sln | 6 ++
Tests/Core/TestCategory.cs | 13 +--
Tests/Core/TestPlay.cs | 77 -----------------
Tests/Core/TestSubCategory.cs | 7 +-
Tests/Core/TestTime.cs | 46 ++++++++++
Tests/Core/TestTimeNode.cs | 104 +++++++++++++++++++++++-
Tests/Core/TestTimelineEvent.cs | 176 +++++++++++++++++++++++++++++++++++++++
Tests/Tests.csproj | 58 +++++++++++++
8 files changed, 396 insertions(+), 91 deletions(-)
---
diff --git a/LongoMatch.sln b/LongoMatch.sln
index 0d67063..f92a30a 100644
--- a/LongoMatch.sln
+++ b/LongoMatch.sln
@@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LongoMatch.Plugins.GStreame
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LongoMatch.Plugins.Stats",
"LongoMatch.Plugins.Stats\LongoMatch.Plugins.Stats.csproj", "{F03D161E-CC4D-4FE6-968A-04F884AB0939}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj",
"{F042D024-3283-4E60-9A85-76E6BBBBB2C1}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -103,6 +105,10 @@ Global
{F03D161E-CC4D-4FE6-968A-04F884AB0939}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F03D161E-CC4D-4FE6-968A-04F884AB0939}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F03D161E-CC4D-4FE6-968A-04F884AB0939}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F042D024-3283-4E60-9A85-76E6BBBBB2C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F042D024-3283-4E60-9A85-76E6BBBBB2C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F042D024-3283-4E60-9A85-76E6BBBBB2C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F042D024-3283-4E60-9A85-76E6BBBBB2C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = LongoMatch\LongoMatch.csproj
diff --git a/Tests/Core/TestCategory.cs b/Tests/Core/TestCategory.cs
index c0ab162..9a8a7ff 100644
--- a/Tests/Core/TestCategory.cs
+++ b/Tests/Core/TestCategory.cs
@@ -16,13 +16,12 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
using System;
-using NUnit.Framework;
-using Newtonsoft.Json;
-
+using System.Collections.Generic;
+using System.IO;
using LongoMatch.Core.Common;
using LongoMatch.Core.Store;
-using System.IO;
-using System.Collections.Generic;
+using NUnit.Framework;
+using Newtonsoft.Json;
namespace Tests.Core
{
@@ -82,9 +81,5 @@ namespace Tests.Core
Assert.AreEqual (newcat.Tags[0].Value, "foo");
Assert.AreEqual (newcat.Tags[0].Group, "bar");
}
-
- public static void Main (string [] args)
- {
- }
}
}
diff --git a/Tests/Core/TestSubCategory.cs b/Tests/Core/TestSubCategory.cs
index 0f04004..7b15b6a 100644
--- a/Tests/Core/TestSubCategory.cs
+++ b/Tests/Core/TestSubCategory.cs
@@ -16,13 +16,12 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
using System;
-using System.IO;
using System.Collections.Generic;
+using System.IO;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Store;
using NUnit.Framework;
-using LongoMatch.Common;
-using LongoMatch.Store;
-
namespace Tests.Core
{
[TestFixture()]
diff --git a/Tests/Core/TestTime.cs b/Tests/Core/TestTime.cs
index 74b48e5..08ea689 100644
--- a/Tests/Core/TestTime.cs
+++ b/Tests/Core/TestTime.cs
@@ -30,6 +30,52 @@ namespace Tests.Core
Time t = new Time (1000);
Utils.CheckSerialization (t);
}
+
+ [Test()]
+ public void TestProperties ()
+ {
+ Time t = new Time (12323456);
+ Assert.AreEqual (t.NSeconds, 12323456000000);
+ Assert.AreEqual (t.TotalSeconds, 12323);
+ Assert.AreEqual (t.Hours, 3);
+ Assert.AreEqual (t.Minutes, 25);
+ Assert.AreEqual (t.Seconds, 23);
+ }
+
+ [Test()]
+ public void TestStrings ()
+ {
+ Time t = new Time (2323456);
+ Assert.AreEqual (t.ToMSecondsString (false), "38:43,456");
+ Assert.AreEqual (t.ToMSecondsString (true), "0:38:43,456");
+ Assert.AreEqual (t.ToSecondsString (false), "38:43");
+ Assert.AreEqual (t.ToSecondsString (true), "0:38:43");
+ }
+
+ [Test()]
+ public void TestOperators ()
+ {
+ Time t1 = new Time (2000);
+ Time t2 = new Time (1000);
+
+ Assert.IsTrue (t1 > t2);
+ Assert.IsTrue (t2 < t1);
+ t2.MSeconds = 2000;
+ Assert.IsTrue (t1 >= t2);
+ Assert.IsTrue (t1 <= t2);
+ Assert.IsTrue (t1 == t2);
+ t2.MSeconds = 1000;
+ Assert.IsFalse (t1 == t2);
+ t2.MSeconds = 0;
+ Assert.IsTrue (t1 != t2);
+ t2.MSeconds = 1000;
+ Assert.AreEqual ((t1 + 100).MSeconds, 2100);
+ Assert.AreEqual ((t1 - 100).MSeconds, 1900);
+ Assert.AreEqual ((t1 + t2).MSeconds, 3000);
+ Assert.AreEqual ((t1 - t2).MSeconds, 1000);
+ Assert.AreEqual ((t1 * 2).MSeconds, 4000);
+ Assert.AreEqual ((t1 / 2).MSeconds, 1000);
+ }
}
}
diff --git a/Tests/Core/TestTimeNode.cs b/Tests/Core/TestTimeNode.cs
index b644c27..bff8254 100644
--- a/Tests/Core/TestTimeNode.cs
+++ b/Tests/Core/TestTimeNode.cs
@@ -17,7 +17,6 @@
//
using System;
using NUnit.Framework;
-using LongoMatch.Core.Common;
using LongoMatch.Core.Store;
namespace Tests.Core
@@ -54,6 +53,109 @@ namespace Tests.Core
tn.Stop = new Time (2000);
Assert.AreEqual (tn.Duration, tn.Stop - tn.Start);
}
+
+ [Test()]
+ public void TestUpdateEventTime ()
+ {
+ TimeNode tn = new TimeNode();
+ tn.Start = new Time (1000);
+ tn.Stop = new Time (2000);
+ Assert.AreEqual (tn.EventTime, tn.Start);
+ tn.EventTime = new Time (1500);
+ Assert.AreEqual (tn.EventTime.MSeconds, 1500);
+ /* EventTime is updated to match the time node boundaries */
+ tn.Stop = new Time (1400);
+ Assert.AreEqual (tn.EventTime, tn.Stop);
+ tn.Start = new Time (1405);
+ Assert.AreEqual (tn.EventTime, tn.Start);
+ }
+
+ [Test()]
+ public void TestMove ()
+ {
+ TimeNode tn = new TimeNode();
+ tn.Start = new Time (1000);
+ tn.EventTime = new Time (1500);
+ tn.Stop = new Time (2000);
+ tn.Move (new Time (100));
+ Assert.AreEqual (tn.Start.MSeconds, 1100);
+ Assert.AreEqual (tn.EventTime.MSeconds, 1600);
+ Assert.AreEqual (tn.Stop.MSeconds, 2100);
+ }
+
+ [Test()]
+ public void TestJoin ()
+ {
+ TimeNode tn;
+ TimeNode tn1 = new TimeNode();
+ TimeNode tn2 = new TimeNode();
+ tn1.Start = new Time (1000);
+ tn1.Stop = new Time (2000);
+
+ /* Lower outbound join */
+ tn2.Start = new Time (0);
+ tn2.Stop = new Time (900);
+ Assert.IsNull (tn1.Join (tn2));
+
+ /* Upper limit join */
+ tn2.Start = new Time (2100);
+ tn2.Stop = new Time (3000);
+ Assert.IsNull (tn1.Join (tn2));
+
+ /* Lower limit join */
+ tn2.Start = new Time (0);
+ tn2.Stop = new Time (1000);
+ tn = tn1.Join (tn2);
+ Assert.AreEqual (tn.Start, tn2.Start);
+ Assert.AreEqual (tn.Stop, tn1.Stop);
+
+ /* Upper limit join */
+ tn2.Start = new Time (2000);
+ tn2.Stop = new Time (2100);
+ tn = tn1.Join (tn2);
+ Assert.AreEqual (tn.Start, tn1.Start);
+ Assert.AreEqual (tn.Stop, tn2.Stop);
+
+ /* Upper Join */
+ tn2.Start = new Time (1900);
+ tn = tn1.Join (tn2);
+ Assert.AreEqual (tn.Start, tn1.Start);
+ Assert.AreEqual (tn.Stop, tn2.Stop);
+
+ /* Lower Join */
+ tn2.Start = new Time (500);
+ tn2.Stop = new Time (1500);
+ tn = tn1.Join (tn2);
+ Assert.AreEqual (tn.Start, tn2.Start);
+ Assert.AreEqual (tn.Stop, tn1.Stop);
+
+ /* Whole Join */
+ tn2.Start = new Time (500);
+ tn2.Stop = new Time (2500);
+ tn = tn1.Join (tn2);
+ Assert.AreEqual (tn.Start, tn2.Start);
+ Assert.AreEqual (tn.Stop, tn2.Stop);
+ }
+
+ [Test()]
+ public void TestIntersect ()
+ {
+ TimeNode tn;
+ TimeNode tn1 = new TimeNode();
+ TimeNode tn2 = new TimeNode();
+ tn1.Start = new Time (1000);
+ tn1.Stop = new Time (2000);
+
+ /* Lower out bounds */
+ tn2.Start = new Time (0);
+ tn2.Stop = new Time (1000);
+ Assert.IsNull (tn1.Intersect (tn2));
+
+ /* Upper out bounds */
+ tn2.Start = new Time (2000);
+ tn2.Stop = new Time (2100);
+ Assert.IsNull (tn1.Intersect (tn2));
+ }
}
}
diff --git a/Tests/Core/TestTimelineEvent.cs b/Tests/Core/TestTimelineEvent.cs
new file mode 100644
index 0000000..d8030cb
--- /dev/null
+++ b/Tests/Core/TestTimelineEvent.cs
@@ -0,0 +1,176 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using NUnit.Framework;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Store;
+using System.Collections.Generic;
+
+namespace Tests.Core
+{
+ [TestFixture()]
+ public class TestTimelineEvent
+ {
+ EventType evtType1;
+
+ public TimelineEvent CreateTimelineEvent () {
+ TimelineEvent evt = new TimelineEvent();
+ evtType1 = new EventType {Name="Cat1"};
+
+ evt.EventType = evtType1;
+ evt.Notes = "notes";
+ evt.Selected = true;
+ evt.Team = Team.LOCAL;
+ evt.FieldPosition = new Coordinates();
+ evt.FieldPosition.Points.Add (new Point (1, 2));
+ evt.HalfFieldPosition = new Coordinates ();
+ evt.HalfFieldPosition.Points.Add (new Point (4,5));
+ evt.GoalPosition = new Coordinates ();
+ evt.GoalPosition.Points.Add (new Point (6, 7));
+ evt.Rate = 1.5f;
+ evt.Name = "Play";
+ evt.Start = new Time(1000);
+ evt.EventTime = new Time(1500);
+ evt.Stop = new Time(2000);
+ evt.Rate = 2.3f;
+
+ evt.Tags.Add(new Tag ("test"));
+ return evt;
+ }
+
+ [Test()]
+ public void TestSerialization ()
+ {
+ TimelineEvent p = new TimelineEvent ();
+ Utils.CheckSerialization (p);
+
+ p = CreateTimelineEvent ();
+ var newp = Utils.SerializeDeserialize (p);
+
+ Assert.AreEqual (p.EventType.ID, newp.EventType.ID);
+ Assert.AreEqual (p.Notes, newp.Notes);
+ Assert.AreEqual (p.Team, newp.Team);
+ Assert.AreEqual (p.FieldPosition, newp.FieldPosition);
+ Assert.AreEqual (p.HalfFieldPosition, newp.HalfFieldPosition);
+ Assert.AreEqual (p.GoalPosition, newp.GoalPosition);
+ Assert.AreEqual (p.Rate, newp.Rate);
+ Assert.AreEqual (p.Name, newp.Name);
+ Assert.AreEqual (p.Start, newp.Start);
+ Assert.AreEqual (p.Stop, newp.Stop);
+ Assert.AreEqual (p.Rate, newp.Rate);
+ }
+
+ [Test()]
+ public void TestProperties ()
+ {
+ TimelineEvent evt = CreateTimelineEvent ();
+ Assert.AreEqual (evt.HasDrawings, false);
+ Assert.AreEqual (evt.Color, evt.EventType.Color);
+ Assert.AreEqual (evt.Description, "Play\ntest\n0:01,000 - 0:02,000 (2,3X)");
+ }
+
+ [Test()]
+ public void TestTagsDescription ()
+ {
+ TimelineEvent evt = CreateTimelineEvent ();
+ Assert.AreEqual (evt.TagsDescription (), "test");
+ evt.Tags.Add (new Tag ("test2"));
+ Assert.AreEqual (evt.TagsDescription (), "test-test2");
+ evt.Tags = new List<Tag> ();
+ Assert.AreEqual (evt.TagsDescription (), "");
+ }
+
+ [Test()]
+ public void TestTimesDescription ()
+ {
+ TimelineEvent evt = CreateTimelineEvent ();
+ Assert.AreEqual (evt.TimesDesription (), "0:01,000 - 0:02,000 (2,3X)");
+ evt.Rate = 1;
+ Assert.AreEqual (evt.TimesDesription (), "0:01,000 - 0:02,000");
+ }
+
+ [Test()]
+ public void TestAddDefaultPositions ()
+ {
+ TimelineEvent evt = new TimelineEvent();
+ evt.EventType = new EventType ();
+ evt.EventType.TagFieldPosition = false;
+ evt.EventType.TagHalfFieldPosition = false;
+ evt.EventType.TagGoalPosition = false;
+
+ Assert.IsNull (evt.FieldPosition);
+ Assert.IsNull (evt.HalfFieldPosition);
+ Assert.IsNull (evt.GoalPosition);
+ evt.AddDefaultPositions ();
+ Assert.IsNull (evt.FieldPosition);
+ Assert.IsNull (evt.HalfFieldPosition);
+ Assert.IsNull (evt.GoalPosition);
+
+ evt.EventType.TagFieldPosition = true;
+ evt.AddDefaultPositions ();
+ Assert.IsNotNull (evt.FieldPosition);
+ Assert.IsNull (evt.HalfFieldPosition);
+ Assert.IsNull (evt.GoalPosition);
+
+ evt.EventType.TagFieldPosition = false;
+ evt.EventType.TagHalfFieldPosition = true;
+ evt.AddDefaultPositions ();
+ Assert.IsNotNull (evt.FieldPosition);
+ Assert.IsNotNull (evt.HalfFieldPosition);
+ Assert.IsNull (evt.GoalPosition);
+
+ evt.EventType.TagFieldPosition = false;
+ evt.EventType.TagHalfFieldPosition = false;
+ evt.EventType.TagGoalPosition = true;
+ evt.AddDefaultPositions ();
+ Assert.IsNotNull (evt.FieldPosition);
+ Assert.IsNotNull (evt.HalfFieldPosition);
+ Assert.IsNotNull (evt.GoalPosition);
+ }
+
+ [Test()]
+ public void TestCoordinatesInFieldPosition ()
+ {
+ TimelineEvent evt = CreateTimelineEvent ();
+ Assert.AreEqual (evt.CoordinatesInFieldPosition (FieldPositionType.Field),
+ evt.FieldPosition);
+ Assert.AreEqual (evt.CoordinatesInFieldPosition (FieldPositionType.HalfField),
+ evt.HalfFieldPosition);
+ Assert.AreEqual (evt.CoordinatesInFieldPosition (FieldPositionType.Goal),
+ evt.GoalPosition);
+ }
+
+ [Test()]
+ public void TestUpdateCoordinates ()
+ {
+ TimelineEvent evt = CreateTimelineEvent ();
+ evt.UpdateCoordinates (FieldPositionType.Field, new List<Point> {new Point (4, 5)});
+ Assert.AreEqual (evt.FieldPosition.Points[0].X, 4);
+ Assert.AreEqual (evt.FieldPosition.Points[0].Y, 5);
+
+ evt.UpdateCoordinates (FieldPositionType.HalfField, new List<Point> {new Point (4,
5)});
+ Assert.AreEqual (evt.HalfFieldPosition.Points[0].X, 4);
+ Assert.AreEqual (evt.HalfFieldPosition.Points[0].Y, 5);
+
+ evt.UpdateCoordinates (FieldPositionType.Goal, new List<Point> {new Point (4, 5)});
+ Assert.AreEqual (evt.GoalPosition.Points[0].X, 4);
+ Assert.AreEqual (evt.GoalPosition.Points[0].Y, 5);
+ }
+ }
+}
+
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
new file mode 100644
index 0000000..d73fa3d
--- /dev/null
+++ b/Tests/Tests.csproj
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>12.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F042D024-3283-4E60-9A85-76E6BBBBB2C1}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>Tests</RootNamespace>
+ <AssemblyName>Tests</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>full</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="nunit.framework">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Newtonsoft.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b9a188c8922137c6">
+ <Private>False</Private>
+ <Package>newtonsoft-json</Package>
+ </Reference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <Compile Include="Utils.cs" />
+ <Compile Include="Core\TestTimelineEvent.cs" />
+ <Compile Include="Core\TestTimeNode.cs" />
+ <Compile Include="Core\TestTime.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
+ <Project>{B70912B2-7ED5-450E-97BD-45A3D45A0358}</Project>
+ <Name>LongoMatch.Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\LongoMatch.Services\LongoMatch.Services.csproj">
+ <Project>{AA2793F9-3B72-4F34-9B34-2E0C18A8A960}</Project>
+ <Name>LongoMatch.Services</Name>
+ </ProjectReference>
+ </ItemGroup>
+</Project>
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]