public object?Simplify(IFuzzProfile profile, object?input, Func <object?, bool> isValid) { if (input is null) { return(null); } var simplified = CopyDataObject(input); // Assume each property is independent, and simplify separately foreach (var property in input.GetType().GetDataProperties()) { var initialValue = property.GetValue(input); if (initialValue == null) { continue; } // Use the dynamic type var simplifier = profile.SimplifierFor(initialValue.GetType()); var simplifiedProperty = simplifier.Simplify(profile, initialValue, candidate => { // Note that mutating `simplified` is okay, because it is completely hidden from the recursive call property.SetValue(simplified, candidate); return(isValid(simplified)); }); property.SetValue(simplified, simplifiedProperty); } return(simplified); }
public override T SimplifyInstance(IFuzzProfile profile, T input, Func <object?, bool> isValid) { if (isValid(DomainMinimum)) { return(DomainMinimum); } // predicate(high) is always true var high = input; // predicate(low) is always false var low = DomainMinimum; while (true) { var midpoint = Midpoint(low, high); if (midpoint.Equals(low)) { // Convergence has been achieved return(high); } else if (isValid(midpoint)) { high = midpoint; } else { low = midpoint; } } }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { var constructor = random.Choice(type.GetConstructors()); var arguments = constructor.GetParameters() .Select(p => profile.Generate(p.ParameterType, random)); return(constructor.Invoke(arguments.ToArray())); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { // Only find direct subclasses. Indirect subclasses can be found recursively var candidateClasses = DirectSubclassesOf(type) .ToList(); var generatedType = random.Choice(candidateClasses); return(profile.Generate(generatedType, random)); }
public static IGenerator GeneratorForOrThrow(this IFuzzProfile profile, Type type) { var generator = profile.GeneratorFor(type); if (generator == null) { throw new NotImplementedException($"{profile.GetType()} does not gave a generator which can generate a {type.FullName}"); } return(generator); }
/// <inheritdoc/> public object?Simplify(IFuzzProfile profile, object?input, Func <object?, bool> isValid) { // If the input is null, always consider it simplified if (input == null) { return(null); } if (!(input is T inputT)) { throw new ArgumentException(); } return(SimplifyInstance(profile, inputT, isValid)); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { var constructor = type.GetConstructor(Array.Empty <Type>()) !; var instance = constructor.Invoke(Array.Empty <object?>()); foreach (var property in type.GetDataProperties()) { if (!property.CanWrite) { continue; } var value = profile.Generate(property.PropertyType, random); property.SetValue(instance, value); } return(instance); }
public override T SimplifyInstance(IFuzzProfile profile, T input, Func <object?, bool> isValid) { var simplest = input; IEnumerable <T> candidates = new[] { input }; while (candidates.Any()) { var next = candidates.First(); if (isValid(next)) { simplest = next; candidates = SimplificationCandidates(simplest); } else { candidates = candidates.Skip(1); } } return(simplest); }
public override bool CanGenerate(IFuzzProfile profile, Type type) => type == typeof(int);
public static object?Generate(this IFuzzProfile profile, Type type, FuzzRandom random) { var generator = profile.GeneratorForOrThrow(type); return(generator.Generate(profile, type, random)); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { return(random.Choice(_items)); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { return(_value); }
public override bool CanGenerate(IFuzzProfile profile, Type type) { return(_value == null || type.IsAssignableFrom(_value.GetType())); }
public override bool CanGenerate(IFuzzProfile profile, Type type) { return(type.IsAbstract && DirectSubclassesOf(type).All(t => profile.GeneratorFor(t) != null)); }
public abstract object?Generate(IFuzzProfile profile, Type type, FuzzRandom random);
public bool CanGenerate(IFuzzProfile profile, Type type) { return(true); }
public override bool CanGenerate(IFuzzProfile profile, Type type) { return(ItemType.IsAssignableFrom(type)); }
public abstract T SimplifyInstance(IFuzzProfile profile, T input, Func <object?, bool> isValid);
public override bool CanGenerate(IFuzzProfile profile, Type type) { return(type.GetConstructors().Length > 0 && !type.ContainsGenericParameters); }
public override bool CanGenerate(IFuzzProfile profile, Type type) { return(type.IsDataObject() && type.GetDataProperties().All(p => profile.GeneratorFor(p.PropertyType) != null)); }
public override bool CanGenerate(IFuzzProfile profile, Type type) { return(type.IsEnum); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { Check.IsTrue(type.IsEnum); return(random.Choice(type.GetEnumValues())); }
public bool CanSimplify(IFuzzProfile profile, Type type) { return(typeof(T).IsAssignableFrom(type)); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { return(random.Poisson(Mean)); }
public override object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { return(random.Uniform(Min, Max)); }
public object?Simplify(IFuzzProfile profile, object?input, Func <object?, bool> isValid) => input;
public object?Generate(IFuzzProfile profile, Type type, FuzzRandom random) { return(null); }
public bool CanSimplify(IFuzzProfile profile, Type type) => true;
public abstract bool CanGenerate(IFuzzProfile profile, Type type);
public bool CanSimplify(IFuzzProfile profile, Type type) { return(type.IsDataObject()); }