Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine NextDistinct methods with current IComparableGenerator<T> functionality #41

Open
carusology opened this issue Jan 9, 2017 · 0 comments
Assignees

Comments

@carusology
Copy link
Contributor

Problem

I'm using data generated from this library to generate values for data models. In one particular instance, I'm generating data for an field (let's call it Updated) that must be greater than or equal to another field (let's call it Created). In that situation, I can use IComparableGenerator<T>.GreaterThanOrEqualTo(T other) to pass in the value for Created, and generate a value that is greater than or equal to it for Updated. However, if I want to generate a distinct value from the current one that ever fulfills this range requirement, I have to create a new generator for Updated that covers the range of greater than or equal to Created and then invoke IComparableGenerator<T>.NextDistinct(T other) to get the needed value.

Solution

Since IComparableGenerator<T> inherits from IDistinctGenerator<T>, we can fulfill this need by adding four methods to the IComparableGenerator<T> interface:

public interface IComparableGenerator<T> {

     [ ... current methods ... ]

    T NextDistinctGreaterThanOrEqualTo(T distinctFrom, T inclusiveLowerBound);
    T NextDistinctGreaterThan(T distinctFrom, T exclusiveLowerBound);
    T NextDistinctLessThanOrEqualTo(T distinctFrom, T inclusiveUpperBound);
    T NextDistinctLessThan(T distinctFrom, T exclusiveUpperBound);
}

Given the above example, we would use NextDistinctGreaterThanOrEqualTo(), put the current value for Updated into distinctFrom and put the current value for Created into inclusiveLowerBound. That would give us a new value for Updated that still fulfilled its requirement to be greater than or equal to Created.

@carusology carusology self-assigned this Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant