@Test public void set_long_value() { underTest.setMeasureValue(customMeasure, "123456789", newMetricDto().setValueType(WORK_DUR.name())); assertThat(customMeasure.getValue()).isCloseTo(123456789d, defaultOffset()); }
@Test public void set_boolean_false_value() { underTest.setMeasureValue(customMeasure, "false", newMetricDto().setValueType(BOOL.name())); assertThat(customMeasure.getValue()).isCloseTo(0.0d, defaultOffset()); }
@Test public void set_boolean_true_value() { underTest.setMeasureValue(customMeasure, "true", newMetricDto().setValueType(BOOL.name())); assertThat(customMeasure.getValue()).isCloseTo(1.0d, defaultOffset()); }
@Test public void set_integer_value() { underTest.setMeasureValue(customMeasure, "1984", newMetricDto().setValueType(INT.name())); assertThat(customMeasure.getValue()).isCloseTo(1984d, defaultOffset()); }
@Test public void set_float_value() { underTest.setMeasureValue(customMeasure, "3.14", newMetricDto().setValueType(FLOAT.name())); assertThat(customMeasure.getValue()).isCloseTo(3.14d, defaultOffset()); }
@Test public void insert() { UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true)); CustomMeasureDto measure = newCustomMeasureDto() .setComponentUuid(project.uuid()) .setMetricId(metric.getId()) .setUserUuid(user.getUuid()); underTest.insert(session, measure); CustomMeasureDto result = underTest.selectById(session, measure.getId()); assertThat(result.getId()).isEqualTo(measure.getId()); assertThat(result.getMetricId()).isEqualTo(metric.getId()); assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); assertThat(result.getUserUuid()).isEqualTo(user.getUuid()); assertThat(result.getDescription()).isEqualTo(measure.getDescription()); assertThat(result.getTextValue()).isEqualTo(measure.getTextValue()); assertThat(result.getValue()).isCloseTo(measure.getValue(), offset(0.001d)); assertThat(result.getCreatedAt()).isEqualTo(measure.getCreatedAt()); assertThat(result.getUpdatedAt()).isEqualTo(measure.getUpdatedAt()); }
@Test public void extractFieldsTest() { String event = "{\"meta\":{\"name\":\"OneVehicleDynamicData\",\"timestamp\":" + "\"2017-02-14T10:20:37.629Z\",\"grouping\":\"OneVehicleFinderData\"," + "\"distribution_key\":\"665292e8-6a3b-4702-9666-b5624d6c8320\"},\"position\":{" + "\"latitude\":48.042999267578125,\"longitude\":11.510173797607422,\"foo\":7}," + "\"vehicle_id\":\"abcd\",\"fuel_level\":999," + "\"charge_level\":50.0,\"odometer\":12345}"; JsonObject json = (JsonObject) new JsonParser().parse(event); assertThat(jsonUtil.extractInteger(json, "odometer", -1)).isEqualTo(12345); assertThat(jsonUtil.extractDouble(json, "charge_level", -1)) .isCloseTo(50, Percentage.withPercentage(1)); assertThat(jsonUtil.extractString(json, "vehicle_id")).isEqualTo("abcd"); //check dot-notation paths assertThat(jsonUtil.extractInteger(json, "position.foo", -1)).isEqualTo(7); assertThat(jsonUtil.extractDouble(json, "position.latitude", 0)) .isCloseTo(48.043, Percentage.withPercentage(1)); assertThat(jsonUtil.extractString(json, "meta.name")).isEqualTo("OneVehicleDynamicData"); }
@Property() void squareOfRootIsOriginalValue(@ForAll double aNumber) { double sqrt = Math.sqrt(aNumber); Assertions.assertThat(sqrt * sqrt).isCloseTo(aNumber, withPercentage(1)); }
private static void assertJsonRoundTrip(Duration duration) { JsonCodec<Duration> durationCodec = JsonCodec.jsonCodec(Duration.class); String json = durationCodec.toJson(duration); Duration durationCopy = durationCodec.fromJson(json); assertThat(durationCopy.getValue(MILLISECONDS)) .isCloseTo(duration.getValue(MILLISECONDS), withPercentage(1)); }
@Test public void testParseValueAsMilliseconds() { assertThat(parseValueAsUnit("50ns", MILLI(SECOND))).isCloseTo(0.00005, offset(0.00000000001)); assertThat(parseValueAsUnit("30us", MILLI(SECOND))).isCloseTo(0.03, offset(0.00000000001)); assertThat(parseValueAsUnit("10ms", MILLI(SECOND))).isEqualTo(10.0); assertThat(parseValueAsUnit("20s", MILLI(SECOND))).isEqualTo(20000.0); assertThat(parseValueAsUnit("30m", MILLI(SECOND))).isEqualTo(1800000.0); assertThat(parseValueAsUnit("4h", MILLI(SECOND))).isEqualTo(14400000.0); assertThat(parseValueAsUnit("5d", MILLI(SECOND))).isEqualTo(432000000.0); } }
@Test void oneBestSurfaceIsFavorite() { FavoriteSurface favoriteSurface = new FavoriteSurface(performance( new WonLost(15, 5), // 75% new WonLost(8, 5), // 61.5% new WonLost(5, 5), // 50% new WonLost(0, 1) )); assertThat(favoriteSurface.getSurface()).isEqualTo(HARD); assertThat(favoriteSurface).hasToString("Hard"); assertThat(favoriteSurface.getSpecialization()).isCloseTo(42, OFFSET); }
@Test void fromTwoSurfacesBetterIsFavorite() { FavoriteSurface favoriteSurface = new FavoriteSurface(performance( new WonLost(0, 0), new WonLost(5, 5), // 50% new WonLost(15, 5), // 75% new WonLost(0, 0) )); assertThat(favoriteSurface.getSurface()).isEqualTo(GRASS); assertThat(favoriteSurface).hasToString("Grass"); assertThat(favoriteSurface.getSpecialization()).isCloseTo(42, OFFSET); }
@Test void surfaceGroupIsFavorite() { FavoriteSurface favoriteSurface = new FavoriteSurface(performance( new WonLost(5, 5), // 50% new WonLost(20, 5), // 80% new WonLost(16, 5), // 76.2% new WonLost(1, 1) )); assertThat(favoriteSurface.getSurfaceGroup()).isEqualTo(SOFT); assertThat(favoriteSurface).hasToString("Soft (Cl, G)"); assertThat(favoriteSurface.getSpecialization()).isCloseTo(49, OFFSET); }
@Test void surfaceGroupForIvanLendlIsNonGrass() { FavoriteSurface favoriteSurface = new FavoriteSurface(performance( new WonLost(394, 83), // 82.6% new WonLost(329, 77), // 81.0% new WonLost(81, 27), // 75.0% new WonLost(265, 55) // 82.8% )); assertThat(favoriteSurface.getSurfaceGroup()).isEqualTo(NON_GRASS); assertThat(favoriteSurface).hasToString("Non-Grass"); assertThat(favoriteSurface.getSpecialization()).isCloseTo(20, OFFSET); }
@Test public void shouldSaveBranchWitlCompositeLocationConverter() throws Exception { Franchise franchise = new Franchise(); Restaurant restaurant = new Restaurant(); Branch branch = new Branch(new Location(37.61649, -122.38681), franchise, restaurant); session.save(branch); session.clear(); Branch loaded = session.load(Branch.class, branch.getId()); assertThat(loaded.getLocation().getLatitude()).isCloseTo(37.61649, within(0.00001)); assertThat(loaded.getLocation().getLongitude()).isCloseTo(-122.38681, within(0.00001)); }
public void test_ofForecastValue_Currency() { CashFlow test = CashFlow.ofForecastValue(PAYMENT_DATE, GBP, FORECAST_VALUE, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_ofPresentValue_CurrencyAmount() { CashFlow test = CashFlow.ofPresentValue(PAYMENT_DATE, PRESENT_AMOUNT, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_ofForecastValue_CurrencyAmount() { CashFlow test = CashFlow.ofForecastValue(PAYMENT_DATE, FUTURE_AMOUNT, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_ofPresentValue_Currency() { CashFlow test = CashFlow.ofPresentValue(PAYMENT_DATE, GBP, PRESENT_VALUE, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_convertedTo() { CashFlow base = CashFlow.ofForecastValue(PAYMENT_DATE, GBP, FORECAST_VALUE, DISCOUNT_FACTOR); CashFlow test = base.convertedTo(USD, FxRate.of(GBP, USD, 1.5)); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(USD); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE * 1.5, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(USD); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE * 1.5, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }