From f28f02bf7a30b82ac52c8117ac6e5799cc6864fd Mon Sep 17 00:00:00 2001 From: "SND\\rene87_cp" Date: Sat, 19 Nov 2011 19:15:10 +0000 Subject: [PATCH] add CurveTest --- .../ANX.Framework.TestCenter.csproj | 1 + ANX.Framework.TestCenter/AssertHelper.cs | 89 ++++++++- .../classTests/CurveTest.cs | 173 ++++++++++++++++++ 3 files changed, 260 insertions(+), 3 deletions(-) create mode 100644 ANX.Framework.TestCenter/classTests/CurveTest.cs diff --git a/ANX.Framework.TestCenter/ANX.Framework.TestCenter.csproj b/ANX.Framework.TestCenter/ANX.Framework.TestCenter.csproj index ed826def..e7b26d25 100644 --- a/ANX.Framework.TestCenter/ANX.Framework.TestCenter.csproj +++ b/ANX.Framework.TestCenter/ANX.Framework.TestCenter.csproj @@ -53,6 +53,7 @@ + diff --git a/ANX.Framework.TestCenter/AssertHelper.cs b/ANX.Framework.TestCenter/AssertHelper.cs index b9091778..2d012164 100644 --- a/ANX.Framework.TestCenter/AssertHelper.cs +++ b/ANX.Framework.TestCenter/AssertHelper.cs @@ -142,6 +142,24 @@ using ANXStorageDevice = ANX.Framework.Storage.StorageDevice; using XNAStorageContainer = Microsoft.Xna.Framework.Storage.StorageContainer; using ANXStorageContainer = ANX.Framework.Storage.StorageContainer; +using XNACurve = Microsoft.Xna.Framework.Curve; +using ANXCurve = ANX.Framework.Curve; + +using XNACurveKey = Microsoft.Xna.Framework.CurveKey; +using ANXCurveKey = ANX.Framework.CurveKey; + +using XNACurveContinuity = Microsoft.Xna.Framework.CurveContinuity; +using ANXCurveContinuity = ANX.Framework.CurveContinuity; + +using XNACurveLoopType = Microsoft.Xna.Framework.CurveLoopType; +using ANXCurveLoopType = ANX.Framework.CurveLoopType; + +using XNACurveKeyCollection = Microsoft.Xna.Framework.CurveKeyCollection; +using ANXCurveKeyCollection = ANX.Framework.CurveKeyCollection; + +using XNACurveTangent = Microsoft.Xna.Framework.CurveTangent; +using ANXCurveTangent = ANX.Framework.CurveTangent; + #endregion // Datatype usings namespace ANX.Framework.TestCenter @@ -728,7 +746,7 @@ namespace ANX.Framework.TestCenter public static void ConvertEquals(XNAStorageDevice xna, ANXStorageDevice anx, String test) { - if (CompareStorageDevice(xna, anx)) + if (Compare(xna, anx)) { Assert.Pass(test + " passed"); } @@ -738,14 +756,14 @@ namespace ANX.Framework.TestCenter } } - private static bool CompareStorageDevice(XNAStorageDevice xna, ANXStorageDevice anx) + private static bool Compare(XNAStorageDevice xna, ANXStorageDevice anx) { return (xna.FreeSpace == anx.FreeSpace) && (xna.IsConnected == anx.IsConnected) && (xna.TotalSpace == anx.TotalSpace); } public static void ConvertEquals(XNAStorageContainer xna, ANXStorageContainer anx, String test) { - if ((CompareStorageDevice(xna.StorageDevice, anx.StorageDevice))&&(xna.IsDisposed==anx.IsDisposed)&&(xna.DisplayName==anx.DisplayName)) + if ((Compare(xna.StorageDevice, anx.StorageDevice))&&(xna.IsDisposed==anx.IsDisposed)&&(xna.DisplayName==anx.DisplayName)) { Assert.Pass(test + " passed"); } @@ -754,5 +772,70 @@ namespace ANX.Framework.TestCenter Assert.Fail(String.Format("{0} failed: xna({1}) anx({2})", test, xna.ToString(), anx.ToString())); } } + + internal static void ConvertEquals(XNACurve xna, ANXCurve anx, String test) + { + if (Compare(xna, anx)) + { + Assert.Pass(test + " passed"); + } + else + { + Assert.Fail(String.Format("{0} failed: xna({1}) anx({2})", test, xna.ToString(), anx.ToString())); + } + } + + public static void ConvertEquals(XNACurve xna, XNACurve xna2, ANXCurve anx, ANXCurve anx2, String test) + { + if (Compare(xna, anx) && Compare(xna2, anx) && Compare(xna2, anx2)) + { + Assert.Pass(test + " passed"); + } + else + { + Assert.Fail(String.Format("{0} failed: xna({1}) anx({2})", test, xna.ToString(), anx.ToString())); + } + } + + private static bool Compare(XNACurve xna, ANXCurve anx) + { + return (xna.IsConstant == anx.IsConstant) && (Compare(xna.Keys, anx.Keys)) && (Compare(xna.PreLoop, anx.PreLoop)) && (Compare(xna.PostLoop, anx.PostLoop)); + } + + private static bool Compare(XNACurveLoopType xna, ANXCurveLoopType anx) + { + return ((int)xna == (int)anx); + } + + private static bool Compare(XNACurveKeyCollection xna, ANXCurveKeyCollection anx) + { + if (xna.Count!=anx.Count) + { + return false; + } + else + { + for (int i = 0; i < xna.Count; i++) + { + if (!Compare(xna[i],anx[i])) + { + return false; + } + } + } + return true; + } + + private static bool Compare(XNACurveKey xna, ANXCurveKey anx) + { + return xna.Position == anx.Position && xna.Value == anx.Value && xna.TangentIn == anx.TangentIn && xna.TangentOut == anx.TangentOut && Compare(xna.Continuity,anx.Continuity); + } + + private static bool Compare(XNACurveContinuity xna, ANXCurveContinuity anx) + { + return ((int)xna == (int)anx); + } + + } } diff --git a/ANX.Framework.TestCenter/classTests/CurveTest.cs b/ANX.Framework.TestCenter/classTests/CurveTest.cs new file mode 100644 index 00000000..afa70e2a --- /dev/null +++ b/ANX.Framework.TestCenter/classTests/CurveTest.cs @@ -0,0 +1,173 @@ +#region Using Statements +using System; +using System.IO; +using ANX.Framework.NonXNA; +using NUnit.Framework; +#endregion // Using Statements + +using XNACurve = Microsoft.Xna.Framework.Curve; +using ANXCurve = ANX.Framework.Curve; + +using XNACurveKey = Microsoft.Xna.Framework.CurveKey; +using ANXCurveKey = ANX.Framework.CurveKey; + +using XNACurveLoopType = Microsoft.Xna.Framework.CurveLoopType; +using ANXCurveLoopType = ANX.Framework.CurveLoopType; + +using XNACurveKeyCollection = Microsoft.Xna.Framework.CurveKeyCollection; +using ANXCurveKeyCollection = ANX.Framework.CurveKeyCollection; + +using XNACurveTangent = Microsoft.Xna.Framework.CurveTangent; +using ANXCurveTangent = ANX.Framework.CurveTangent; + + + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License +namespace ANX.Framework.TestCenter.classTest +{ + [TestFixture] + class CurveTest + { + static object[] inoutsame = + { + new object[] {XNACurveTangent.Flat,ANXCurveTangent.Flat , DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000) }, + new object[] {XNACurveTangent.Linear,ANXCurveTangent.Linear, DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000)}, + new object[] {XNACurveTangent.Smooth,ANXCurveTangent.Smooth, DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000), DataFactory.RandomValueMinMax(float.Epsilon, 1000)} + + }; + + [TestCaseSource("inoutsame")] + public void Curve(XNACurveTangent xnainout, ANXCurveTangent anxinout, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15, float f16) + { + XNACurve xna = new XNACurve(); + ANXCurve anx = new ANXCurve(); + + xna.Keys.Add(new XNACurveKey(f1, f2)); + //xna.Keys.Add(new XNACurveKey(f3, f4)); + //xna.Keys.Add(new XNACurveKey(f5, f6)); + //xna.Keys.Add(new XNACurveKey(f7, f8)); + //xna.Keys.Add(new XNACurveKey(f9, f10)); + //xna.Keys.Add(new XNACurveKey(f11, f12)); + //xna.Keys.Add(new XNACurveKey(f13, f14)); + //xna.Keys.Add(new XNACurveKey(f15, f16)); + + anx.Keys.Add(new ANXCurveKey(f1, f2)); + //anx.Keys.Add(new ANXCurveKey(f3, f4)); + //anx.Keys.Add(new ANXCurveKey(f5, f6)); + //anx.Keys.Add(new ANXCurveKey(f7, f8)); + //anx.Keys.Add(new ANXCurveKey(f9, f10)); + //anx.Keys.Add(new ANXCurveKey(f11, f12)); + //anx.Keys.Add(new ANXCurveKey(f13, f14)); + //anx.Keys.Add(new ANXCurveKey(f15, f16)); + + AssertHelper.ConvertEquals(xna, anx, "Curve"); + } + + [TestCaseSource("inoutsame")] + public void Clone(XNACurveTangent xnainout, ANXCurveTangent anxinout, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15, float f16) + { + XNACurve xna = new XNACurve(); + ANXCurve anx = new ANXCurve(); + + xna.Keys.Add(new XNACurveKey(f1, f2)); + xna.Keys.Add(new XNACurveKey(f3, f4)); + xna.Keys.Add(new XNACurveKey(f5, f6)); + xna.Keys.Add(new XNACurveKey(f7, f8)); + xna.Keys.Add(new XNACurveKey(f9, f10)); + xna.Keys.Add(new XNACurveKey(f11, f12)); + xna.Keys.Add(new XNACurveKey(f13, f14)); + xna.Keys.Add(new XNACurveKey(f15, f16)); + + anx.Keys.Add(new ANXCurveKey(f1, f2)); + anx.Keys.Add(new ANXCurveKey(f3, f4)); + anx.Keys.Add(new ANXCurveKey(f5, f6)); + anx.Keys.Add(new ANXCurveKey(f7, f8)); + anx.Keys.Add(new ANXCurveKey(f9, f10)); + anx.Keys.Add(new ANXCurveKey(f11, f12)); + anx.Keys.Add(new ANXCurveKey(f13, f14)); + anx.Keys.Add(new ANXCurveKey(f15, f16)); + + XNACurve xna2 = xna.Clone(); + ANXCurve anx2 = anx.Clone(); + + AssertHelper.ConvertEquals(xna,xna2,anx, anx2,"Clone"); + + } + + [TestCaseSource("inoutsame")] + public void ComputeTangents(XNACurveTangent xnainout, ANXCurveTangent anxinout, float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15, float f16) + { + XNACurve xna = new XNACurve(); + ANXCurve anx = new ANXCurve(); + + xna.Keys.Add(new XNACurveKey(f1, f2)); + xna.Keys.Add(new XNACurveKey(f3, f4)); + xna.Keys.Add(new XNACurveKey(f5, f6)); + xna.Keys.Add(new XNACurveKey(f7, f8)); + xna.Keys.Add(new XNACurveKey(f9, f10)); + xna.Keys.Add(new XNACurveKey(f11, f12)); + xna.Keys.Add(new XNACurveKey(f13, f14)); + xna.Keys.Add(new XNACurveKey(f15, f16)); + + anx.Keys.Add(new ANXCurveKey(f1, f2)); + anx.Keys.Add(new ANXCurveKey(f3, f4)); + anx.Keys.Add(new ANXCurveKey(f5, f6)); + anx.Keys.Add(new ANXCurveKey(f7, f8)); + anx.Keys.Add(new ANXCurveKey(f9, f10)); + anx.Keys.Add(new ANXCurveKey(f11, f12)); + anx.Keys.Add(new ANXCurveKey(f13, f14)); + anx.Keys.Add(new ANXCurveKey(f15, f16)); + + xna.ComputeTangents(xnainout); + anx.ComputeTangents(anxinout); + + AssertHelper.ConvertEquals(xna, anx, "ComputeTangents"); + } + + } +}