Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import kotlin.math.roundToInt
  2. import kotlin.test.assertEquals
  3.  
  4. const val PI = 3.14
  5. const val NAUTICAL_MILE_IN_METERS = 1852
  6. const val MEAN_EARTH_RADIUS = 6371100
  7.  
  8. fun main(args: Array<String>): Unit {
  9. assertEquals(NAUTICAL_MILE_IN_METERS, toMeters(1))
  10. assertEquals(10 * NAUTICAL_MILE_IN_METERS, toMeters(10))
  11.  
  12. assertEquals(0.0005399568034557236, toNauticalMiles(1))
  13. assertEquals(0.5399568034557235, toNauticalMiles(1000))
  14. assertEquals(1.0, toNauticalMiles(NAUTICAL_MILE_IN_METERS))
  15. assertEquals(1.079913606911447, toNauticalMiles(2000))
  16. assertEquals(5.399568034557236, toNauticalMiles(10000))
  17. }
  18.  
  19. fun toMeters(nauticalMiles: Int): Int = nauticalMiles * ((2 * PI * MEAN_EARTH_RADIUS) / (360 * 60)).roundToInt()
  20.  
  21. fun toNauticalMiles(meters: Int): Double = meters.toDouble() / ((2 * PI * MEAN_EARTH_RADIUS) / (360 * 60)).roundToInt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement