### Question:
PreferenceDomain implements Serializable { public double clampValue(double v) { if (v < minimum) { return minimum; } else if (v > maximum) { return maximum; } else { return v; } } PreferenceDomain(double min, double max, double prec);  PreferenceDomain(double min, double max); double getMinimum(); double getMaximum(); boolean hasPrecision(); double getPrecision(); double clampValue(double v); Long2DoubleSortedMap clampVector(Map<Long,Double> scores); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object o); @Nonnull static PreferenceDomain fromString(@Nonnull String spec); static PreferenceDomainBuilder newBuilder(); static final long serialVersionUID; }### Answer:
@Test public void testClampValue() { PreferenceDomain d = PreferenceDomain.fromString("[1.0,5.0]"); for (Map<Long,Double> vec: someMaps(longs(), doubles(0.0, 8.0))) { Long2DoubleMap clamped = d.clampVector(vec); assertThat(clamped.keySet(), equalTo(vec.keySet())); for (Long k: vec.keySet()) { double v = vec.get(k); if (v < 1.0) { assertThat(clamped, hasEntry(k, 1.0)); } else if (v > 5.0) { assertThat(clamped, hasEntry(k, 5.0)); } else { assertThat(clamped, hasEntry(k, v)); } } } }