@Test public void testObservableFloatValue(){ ObservableFloatValue actual = new SimpleFloatProperty(10f); assertThat(actual).hasValue(10f); assertThat(actual).hasSameValue(actual); }
@Test public void should_fail_if_actual_has_wrong_value(){ try{ ObservableFloatValue actual = new SimpleFloatProperty(10.123F); new ObservableNumberValueAssertions(actual).hasValue(10.12F, offset(0.001F)); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("less than <0.001> but difference was <0.0030002594>"); } }
@Test public void should_fail_if_offset_is_null(){ try{ ObservableFloatValue actual = new SimpleFloatProperty(10.123F); new ObservableNumberValueAssertions(actual).hasValue(10.123F, null); fail("Should throw an AssertionError"); }catch(NullPointerException error){ assertThat(error).hasMessageContaining("offset may not be null"); } }
@Test public void should_fail_if_actual_has_wrong_value(){ try{ ObservableFloatValue actual = new SimpleFloatProperty(1234.56F); new ObservableValueAssertions<>(actual).hasValue(1234F); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("<1234.0> but was <1234.56>"); } }
public FloatBinding selectFloat(Function<S, ? extends ObservableFloatValue> childPropertyAccessor) { return selectFloat(childPropertyAccessor, 0.0f); }
public FloatBinding selectFloat(Function<S, ? extends ObservableFloatValue> childPropertyAccessor, float defaultValue) { return new FloatBindingAdapter(new ChainBinding<>(rootProperty, childPropertyAccessor), defaultValue); }
@Test public void should_pass_if_actual_has_given_value_with_offset(){ ObservableFloatValue actual = new SimpleFloatProperty(10.123F); new ObservableNumberValueAssertions(actual).hasValue(10.12F, offset(0.01F)); }
@Test public void should_pass_if_actual_has_given_value(){ ObservableFloatValue actual = new SimpleFloatProperty(1234.56F); new ObservableValueAssertions<>(actual).hasValue(1234.56F); }
@SuppressWarnings("unchecked") @Test public void testScalb(){ MathBindingsTestHelper.<Float, Integer, ObservableFloatValue, ObservableIntegerValue, Number> testTwoArgBinding1(MathBindings::scalb, Math::scalb, new Args<>(12f, 12), new Args<>(Float.NaN, 12), new Args<>(Float.POSITIVE_INFINITY, 3), new Args<>(0f, 3)); MathBindingsTestHelper.<Float, Integer, ObservableIntegerValue, Number> testTwoArgBinding2(MathBindings::scalb, Math::scalb, new Args<>(12f, 12), new Args<>(Float.NaN, 12), new Args<>(Float.POSITIVE_INFINITY, 3), new Args<>(0f, 3)); MathBindingsTestHelper.<Float, Integer, ObservableFloatValue, Number> testTwoArgBinding3(MathBindings::scalb, Math::scalb, new Args<>(12f, 12), new Args<>(Float.NaN, 12), new Args<>(Float.POSITIVE_INFINITY, 3), new Args<>(0f, 3)); MathBindingsTestHelper.<Double, Integer, ObservableDoubleValue, ObservableIntegerValue, Number> testTwoArgBinding1(MathBindings::scalb, Math::scalb, new Args<>(12d, 12), new Args<>(Double.NaN, 12), new Args<>(Double.POSITIVE_INFINITY, 3), new Args<>(0d, 3)); MathBindingsTestHelper.<Double, Integer, ObservableIntegerValue, Number> testTwoArgBinding2(MathBindings::scalb, Math::scalb, new Args<>(12d, 12), new Args<>(Double.NaN, 12), new Args<>(Double.POSITIVE_INFINITY, 3), new Args<>(0d, 3)); MathBindingsTestHelper.<Double, Integer, ObservableDoubleValue, Number> testTwoArgBinding3(MathBindings::scalb, Math::scalb, new Args<>(12d, 12), new Args<>(Double.NaN, 12), new Args<>(Double.POSITIVE_INFINITY, 3), new Args<>(0d, 3)); }
/** * Binding for {@link java.lang.Math#abs(float)} * * @param a the argument whose absolute value is to be determined as observableValue * @return the absolute value of the argument. */ public static FloatBinding abs(final ObservableFloatValue a) { return createFloatBinding(() -> Math.abs(a.get()), a); }
/** * Binding for {@link java.lang.Math#copySign(float, float)} * * @param magnitude the parameter providing the magnitude of the result * @param sign the parameter providing the sign of the result * @return a value with the magnitude of {@code magnitude} * and the sign of {@code sign}. */ public static FloatBinding copySign(final ObservableFloatValue magnitude, ObservableFloatValue sign) { return createFloatBinding(() -> Math.copySign(magnitude.get(), sign.get()), magnitude, sign); }
/** * Binding for {@link java.lang.Math#copySign(float, float)} * * @param magnitude the parameter providing the magnitude of the result * @param sign the parameter providing the sign of the result * @return a value with the magnitude of {@code magnitude} * and the sign of {@code sign}. */ public static FloatBinding copySign(final float magnitude, ObservableFloatValue sign) { return createFloatBinding(() -> Math.copySign(magnitude, sign.get()), sign); }
/** * Binding for {@link java.lang.Math#copySign(float, float)} * * @param magnitude the parameter providing the magnitude of the result * @param sign the parameter providing the sign of the result * @return a value with the magnitude of {@code magnitude} * and the sign of {@code sign}. */ public static FloatBinding copySign(final ObservableFloatValue magnitude, float sign) { return createFloatBinding(() -> Math.copySign(magnitude.get(), sign), magnitude); }
/** * Binding for {@link java.lang.Math#getExponent(float)} * * @param f a {@code float} value * @return the unbiased exponent of the argument */ public static IntegerBinding getExponent(final ObservableFloatValue f) { return createIntegerBinding(() -> Math.getExponent(f.get()), f); }
/** * Binding for {@link java.lang.Math#max(float, float)} * * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static FloatBinding max(final ObservableFloatValue a, final ObservableFloatValue b) { return createFloatBinding(() -> Math.max(a.get(), b.get()), a, b); }
/** * Binding for {@link java.lang.Math#max(float, float)} * * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static FloatBinding max(final float a, final ObservableFloatValue b) { return createFloatBinding(() -> Math.max(a, b.get()), b); }
/** * Binding for {@link java.lang.Math#max(float, float)} * * @param a an argument. * @param b another argument. * @return the larger of {@code a} and {@code b}. */ public static FloatBinding max(final ObservableFloatValue a, final float b) { return createFloatBinding(() -> Math.max(a.get(), b), a); }
/** * Binding for {@link java.lang.Math#min(float, float)} * * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b}. */ public static FloatBinding min(final ObservableFloatValue a, final ObservableFloatValue b) { return createFloatBinding(() -> Math.min(a.get(), b.get()), a, b); }
/** * Binding for {@link java.lang.Math#min(float, float)} * * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b}. */ public static FloatBinding min(final float a, final ObservableFloatValue b) { return createFloatBinding(() -> Math.min(a, b.get()), b); }
/** * Binding for {@link java.lang.Math#min(float, float)} * * @param a an argument. * @param b another argument. * @return the smaller of {@code a} and {@code b}. */ public static FloatBinding min(final ObservableFloatValue a, final float b) { return createFloatBinding(() -> Math.min(a.get(), b), a); }
/** * Binding for {@link java.lang.Math#nextAfter(float, double)} * * @param start starting floating-point value * @param direction value indicating which of * {@code start}'s neighbors or {@code start} should * be returned * @return The floating-point number adjacent to {@code start} in the * direction of {@code direction}. */ public static FloatBinding nextAfter(final ObservableFloatValue start, final ObservableFloatValue direction) { return createFloatBinding(() -> Math.nextAfter(start.get(), direction.get()), start, direction); }
/** * Binding for {@link java.lang.Math#nextAfter(float, double)} * * @param start starting floating-point value * @param direction value indicating which of * {@code start}'s neighbors or {@code start} should * be returned * @return The floating-point number adjacent to {@code start} in the * direction of {@code direction}. */ public static FloatBinding nextAfter(final float start, final ObservableFloatValue direction) { return createFloatBinding(() -> Math.nextAfter(start, direction.get()), direction); }
/** * Binding for {@link java.lang.Math#nextAfter(float, double)} * * @param start starting floating-point value * @param direction value indicating which of * {@code start}'s neighbors or {@code start} should * be returned * @return The floating-point number adjacent to {@code start} in the * direction of {@code direction}. */ public static FloatBinding nextAfter(final ObservableFloatValue start, final float direction) { return createFloatBinding(() -> Math.nextAfter(start.get(), direction), start); }
/** * Binding for {@link java.lang.Math#nextDown(float)} * * @param f starting floating-point value * @return The adjacent floating-point value closer to negative * infinity. */ public static FloatBinding nextDown(final ObservableFloatValue f) { return createFloatBinding(() -> Math.nextDown(f.get()), f); }
/** * Binding for {@link java.lang.Math#nextUp(float)} * * @param f starting floating-point value * @return The adjacent floating-point value closer to positive * infinity. */ public static FloatBinding nextUp(final ObservableFloatValue f) { return createFloatBinding(() -> Math.nextUp(f.get()), f); }
/** * Binding for {@link java.lang.Math#round(float)} * * @param a a floating-point value to be rounded to an integer. * @return the value of the argument rounded to the nearest * {@code int} value. */ public static IntegerBinding round(final ObservableFloatValue a) { return createIntegerBinding(() -> Math.round(a.get()), a); }
/** * Binding for {@link java.lang.Math#scalb(float, int)} * * @param f number to be scaled by a power of two. * @param scaleFactor power of 2 used to scale {@code f} * @return {@code f} × 2<sup>{@code scaleFactor}</sup> */ public static FloatBinding scalb(final ObservableFloatValue f, final ObservableIntegerValue scaleFactor) { return createFloatBinding(()->Math.scalb(f.get(), scaleFactor.get()),f, scaleFactor); }
/** * Binding for {@link java.lang.Math#scalb(float, int)} * * @param f number to be scaled by a power of two. * @param scaleFactor power of 2 used to scale {@code f} * @return {@code f} × 2<sup>{@code scaleFactor}</sup> */ public static FloatBinding scalb(final ObservableFloatValue f, final int scaleFactor) { return createFloatBinding(()->Math.scalb(f.get(), scaleFactor),f); }
/** * Binding for {@link java.lang.Math#signum(float)} * * @param f the floating-point value whose signum is to be returned * @return the signum function of the argument */ public static FloatBinding signum(final ObservableFloatValue f) { return createFloatBinding(() -> Math.signum(f.get()), f); }
/** * Binding for {@link java.lang.Math#ulp(float)} * * @param f the floating-point value whose ulp is to be returned * @return the size of an ulp of the argument */ public static FloatBinding ulp(final ObservableFloatValue f) { return createFloatBinding(() -> Math.ulp(f.get()), f); }