/// <summary> /// Generates the sequence of pairs of type <typeparamref name="T"/> /// using specified instance generator. /// </summary> /// <param name="generator">The instance generator to use.</param> /// <param name="random">The random generator to use.</param> /// <param name="equalityProbability">The item equality probability.</param> /// <returns>Described sequence.</returns> public static IEnumerable <Pair <T> > GetPairs(IInstanceGenerator <T> generator, Random random, double equalityProbability) { bool isValueType = typeof(T).IsValueType; bool isCloneable = typeof(ICloneable).IsAssignableFrom(typeof(T)); while (true) { T x = generator.GetInstance(random); if (random.NextDouble() < equalityProbability) { T y; if (isValueType) { y = x; } else if (isCloneable) { y = (T)((ICloneable)x).Clone(); } else { y = x; } yield return(new Pair <T>(x, x)); } else { yield return(new Pair <T>(x, generator.GetInstance(random))); } } }
private void PerfTestInternal <T>(int count) { // Random random = RandomManager.CreateRandom(SeedVariatorType.CallingMethod); IInstanceGenerator <T> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>(); T instance1 = generator.GetInstance(random); T instance2 = generator.GetInstance(random); Arithmetic <T> arithmetic = Arithmetic <T> .Default; using (new Measurement(typeof(T).Name, count)) { for (int i = 0; i < count; i++) { arithmetic.Add(instance1, instance2); } } }
private static void InternalSetValue <T>(Xtensive.Tuples.Tuple tuple, int fieldIndex, Random random) { IInstanceGenerator <T> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>(); T instance = generator.GetInstance(random); tuple.SetValue(fieldIndex, instance); }
/// <summary> /// Generates the sequence of instances of type <typeparamref name="T"/> /// using specified instance generator. /// </summary> /// <param name="generator">The instance generator to use.</param> /// <param name="random">The random generator to use.</param> /// <param name="equalityProbability">The subsequent item equality probability.</param> /// <returns>Described sequence.</returns> public static IEnumerable <T> GetInstances(IInstanceGenerator <T> generator, Random random, double equalityProbability) { bool isValueType = typeof(T).IsValueType; bool isCloneable = typeof(ICloneable).IsAssignableFrom(typeof(T)); T x = default(T); bool first = true; while (true) { if (first || random.NextDouble() >= equalityProbability) { x = generator.GetInstance(random); } else { T y; if (isValueType) { y = x; } else if (isCloneable) { y = (T)((ICloneable)x).Clone(); } else { y = x; } x = y; } first = false; yield return(x); } }
private static void SetValue <T>(ITuple dummyTuple, ITuple tuple, int fieldIndex, Random random) { IInstanceGenerator <T> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>(); T instance = generator.GetInstance(random); dummyTuple.SetValue(fieldIndex, instance); tuple.SetValue(fieldIndex, instance); }
public void StringTest() { IInstanceGenerator <Guid> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <Guid>(); Random random = RandomManager.CreateRandom(1, SeedVariatorType.CallingMethod); for (int i = 0; i < iterationCount * 100; i++) { OneValueTest <Guid, string>(generator.GetInstance(random), 1); } }
public void Test() { TestLog.Info("{0}", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss.fff %K", CultureInfo.InvariantCulture)); IInstanceGenerator <DateTime> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <DateTime>(); Random random = RandomManager.CreateRandom(1, SeedVariatorType.CallingMethod); for (int i = 0; i < iterationCount * 1; i++) { TestLog.Info("{0}", generator.GetInstance(random).ToString("yyyy/MM/dd hh:mm:ss.fff %K", CultureInfo.InvariantCulture)); } }
public override DateTime GetInstance(Random random) { long randomLong = long.MinValue; // MinValue must be excluded while (randomLong == long.MinValue) { randomLong = longInstanceGeneratorProvider.GetInstance(random); } long correctDateTime = Math.Abs(Math.Abs(randomLong) % (DateTime.MaxValue - DateTime.MinValue).Ticks + DateTime.MinValue.Ticks); return(new DateTime(correctDateTime)); }
public void TwoValuesTest <T>(int count) { Random r = RandomManager.CreateRandom(SeedVariatorType.CallingMethod); IInstanceGenerator <T> g = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>(); IEnumerator <T> sequence = InstanceGenerationUtils <T> .GetInstances(g, r, 1).GetEnumerator(); sequence.MoveNext(); T o1 = sequence.Current; sequence.MoveNext(); T o1c = sequence.Current; T o2 = g.GetInstance(r); AdvancedComparerStruct <T> c1 = AdvancedComparer <T> .System; AdvancedComparerStruct <T> c2 = AdvancedComparer <T> .Default; if (!TestInfo.IsProfileTestRunning) { SimpleComparisonLoop(c1, o1, o2, 1000); } SimpleComparisonLoop(c2, o1, o2, 1000); TestLog.Info("Values comparison:"); TestLog.Info(" Type: {0}, instances: {1} x 2, {2}", typeof(T).GetShortName(), o1, o2); using (IndentManager.IncreaseIndent()) { TestHelper.CollectGarbage(); if (!TestInfo.IsProfileTestRunning) { using (new Measurement("Default comparer (equal) ", MeasurementOptions.Log, count)) SimpleComparisonLoop(c1, o1, o1c, count); TestHelper.CollectGarbage(); using (new Measurement("Default comparer (different)", MeasurementOptions.Log, count)) SimpleComparisonLoop(c1, o1, o2, count); TestHelper.CollectGarbage(); } using (new Measurement("Xtensive comparer (equal) ", MeasurementOptions.Log, count)) SimpleComparisonLoop(c2, o1, o1c, count); using (new Measurement("Xtensive comparer (different)", MeasurementOptions.Log, count)) SimpleComparisonLoop(c2, o1, o2, count); TestHelper.CollectGarbage(); } }
public void CombinedTest() { constants = new Guid[10]; IInstanceGenerator <Guid> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <Guid>(); Random random = RandomManager.CreateRandom(1, SeedVariatorType.CallingMethod); for (int i = 0; i < 10; i++) { constants[i] = generator.GetInstance(random); } foreach (Guid constant in constants) { OneValueTest <Guid, bool>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, byte>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, sbyte>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, short>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, ushort>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, int>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, uint>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, long>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, ulong>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, float>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, double>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, decimal>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, DateTime>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, Guid>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, string>(constant, iterationCount); } foreach (Guid constant in constants) { OneValueTest <Guid, char>(constant, iterationCount); } }
public override sbyte GetInstance(Random random) { unchecked { return((sbyte)byteItemGenerator.GetInstance(random)); } }