From 708c65febc4e0ffe807efabad629a8d934f194b7 Mon Sep 17 00:00:00 2001 From: "SND\\floAr_cp" Date: Sat, 8 Sep 2012 08:32:48 +0000 Subject: [PATCH] Extended DataFactory.cs to provide a full test set containing: - extreme value permutation test - linear test for 1 and 0 - permutation of 0 and minimum value - permutation of 0 and maximum value --- ANX.Framework.TestCenter/DataFactory.cs | 57 ++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/ANX.Framework.TestCenter/DataFactory.cs b/ANX.Framework.TestCenter/DataFactory.cs index edc4b352..e7794c71 100644 --- a/ANX.Framework.TestCenter/DataFactory.cs +++ b/ANX.Framework.TestCenter/DataFactory.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Reflection; #endregion // Using Statements @@ -14,7 +15,43 @@ namespace ANX.Framework.TestCenter { class DataFactory { - static Random r=new Random(); + static Random r = new Random(); + + public static object[] createFullTestSet(int numberOfElements) where T : struct, IComparable, IEquatable, IConvertible + { + return createFullTestSet(numberOfElements, 0); + } + public static object[] createFullTestSet(int numberOfElements, int numberOfRandomSets) where T : struct, IComparable, IEquatable, IConvertible + { + T maxValue = ReadStaticField("MaxValue"); + T MinValue = ReadStaticField("MinValue"); + object[] random = new object[numberOfRandomSets]; + for (int i = 0; i < numberOfRandomSets; ++i) + { + + } + return createLinear(0, numberOfElements).Concat( + createLinear(1, numberOfElements).Concat( + createPermutation(maxValue, MinValue, numberOfElements).Concat( + createPermutation(maxValue, 0, numberOfElements).Concat( + createPermutation(0, MinValue, numberOfElements))))).ToArray(); + } + + /// + /// Create a test dataset filled with constant numbers + /// + /// Number which should fill the test set + /// How many values are needed + /// + public static object[] createLinear(object value, int numberOfElements) + { + object[] result = new object[numberOfElements]; + for (int i = 0; i < numberOfElements; ++i) + result[i] = value; + return result; + } + + /// /// Create a test-dataset with a permutation of extreme value /// @@ -59,6 +96,22 @@ namespace ANX.Framework.TestCenter return result; } + + private static T ReadStaticField(string name) + { + FieldInfo field = typeof(T).GetField(name, + BindingFlags.Public | BindingFlags.Static); + if (field == null) + { + // There's no TypeArgumentException, unfortunately. You might want + // to create one :) + throw new InvalidOperationException("Invalid type argument for NumericUpDown: " + typeof(T).Name); + } + return (T)field.GetValue(null); + } + + #region OLD + static object[] generateTestData(int numOfTests, int numOfElements, int min, int max) { object[] result = new object[numOfTests]; @@ -108,5 +161,7 @@ namespace ANX.Framework.TestCenter { return r.Next(min, max); } + //*/ + #endregion } }