Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
13 tasks
kevincianfarini opened this issue Jan 5, 2025 · 0 comments
Open
13 tasks
Labels
enhancement New feature or request
Milestone

Comments

@kevincianfarini
Copy link
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant