com.redfin.fuzzy.cases.FloatNumericCase Maven / Gradle / Ivy
package com.redfin.fuzzy.cases;
import com.redfin.fuzzy.Any;
import com.redfin.fuzzy.Case;
import com.redfin.fuzzy.Subcase;
import com.redfin.fuzzy.Subcases;
import java.util.HashSet;
import java.util.Set;
public class FloatNumericCase implements Case {
public static final float MAX_GENERATED = 1e38f;
public static final float MIN_GENERATED = -MAX_GENERATED;
private Float min;
private Float max;
private final Set excluding = new HashSet<>();
public Case inRange(float minInclusive, float maxInclusive) {
if(maxInclusive <= minInclusive) {
throw new IllegalArgumentException("minInclusive must be less than maxInclusive.");
}
min = minInclusive;
max = maxInclusive;
return this;
}
public Case lessThan(float maxExclusive) {
max = maxExclusive;
min = null;
excluding.add((double)maxExclusive);
return this;
}
public Case lessThanOrEqualTo(float maxInclusive) {
max = maxInclusive;
min = null;
return this;
}
public Case greaterThan(float minExclusive) {
max = null;
min = minExclusive;
excluding.add((double)minExclusive);
return this;
}
public Case greaterThanOrEqualTo(float minInclusive) {
max = null;
min = minInclusive;
return this;
}
@Override
public Case excluding(Iterable values) {
if(values != null)
for(Float f : values)
if(f != null)
excluding.add(f.doubleValue());
return this;
}
@Override
public Set> getSubcases() {
Case baseCase = Any
.doublePrecisionNumber()
.inRange(min == null ? MIN_GENERATED : min, max == null ? MAX_GENERATED : max)
.excluding(excluding);
return Subcases.mapOutput(baseCase.getSubcases(), Double::floatValue);
}
}