solutions

# Distance properties

Implement the Distance class from our reading providing different properties for each distance unit. A distance can be created using either meters or feet. The Distance can then convert to kilometers, miles, feet or meters.

### Test Cases

test meters to kilometers -

def test_meters_to_kilometers():
d = Distance(meters=8000)

assert d.distance_in_meters == 8000
assert d.distance_in_kilometers == 8

test meters to feet -

def test_meters_to_feet():
d = Distance(meters=8000)

assert d.distance_in_meters == 8000
assert d.distance_in_feet == 26240

test feet to meter -

import pytest

def test_feet_to_meter():
d = Distance(feet=25000)

assert d.distance_in_feet == 25000
assert d.distance_in_meters == pytest.approx(7621.95, rel=1e-2)

test meters to miles -

def test_meters_to_miles():
d = Distance(meters=8000)

assert d.distance_in_meters == 8000
assert d.distance_in_miles == 5

test feet to miles -

import pytest

def test_feet_to_miles():
d = Distance(feet=25000)

assert d.distance_in_feet == 25000
assert d.distance_in_miles == pytest.approx(4.76, rel=1e-2)

test feet to kilometers -

import pytest

def test_feet_to_kilometers():
d = Distance(feet=25000)

assert d.distance_in_feet == 25000
assert d.distance_in_kilometers == pytest.approx(7.62, rel=1e-2)