Skip to content

Add integration tests which assert losslessness for "small" values #51

Description

@kevincianfarini

We should be able to convert between the various quantities and back without losing any precision. For example:

@Test
fun small_length_to_velocity_and_reverse_is_lossless() {
    val distance = 100.kilometers
    val duration = 1.hours
    val velocity = distance / duration
    assertEquals(duration, distance / velocity)
    assertEquals(distance, velocity * duration)
}

Right now this test fails with the following message, and it's because we're losing precision.

java.lang.AssertionError: expected:<1h> but was:<1h 0m 0.000000100s>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:120)

We should have integration tests that exercise the following without losing precision:

Acceleration, Mass, and Force

  • Acceleration * Mass -> Force -> Force / Mass -> Acceleration
  • Acceleration * Mass -> Force -> Force / Acceleration -> Mass

Acceleration, Duration, and Velocity

  • Acceleration * Duration -> Velocity -> Velocity / Duration -> Acceleration
  • Acceleration * Duration -> Velocity -> Velocity / Acceleration -> Duration

Area and Length

  • Area / Length -> Length -> Length * Length -> Area

Energy, Length, and Force

  • Energy / Length -> Force -> Force * Length -> Energy
  • Energy / Force -> Length -> Length * Force -> Energy

Energy, Duration, and Power

  • Energy / Duration -> Power -> Power * Duration -> Energy
  • Energy / Power -> Duration -> Power * Duration -> Energy

Length, Duration, and Velocity

  • Length / Duration -> Velocity -> Length / Velocity -> Duration
  • Length / Duration -> Velocity -> Velocity * Duration -> Length

Length, Area, and Volume

  • Length * Area -> Volume -> Volume / Length -> Area
  • Length * Area -> Volume -> Volume / Area -> Length

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions