Skip to content

Commit

Permalink
Add LightYear (#10)
Browse files Browse the repository at this point in the history
* Add LightYears

* Add test for light-year
  • Loading branch information
Charles Eckman authored and martinlindhe committed Apr 16, 2018
1 parent 87f2d59 commit 158876c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions length.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
// space
LunarDistance = Kilometer * 384400
AstronomicalUnit = Meter * 149597870700
LightYear = Meter * 9460730472580800
)

// Yoctometers returns the length in ym
Expand Down Expand Up @@ -229,3 +230,8 @@ func (l Length) LunarDistances() float64 {
func (l Length) AstronomicalUnits() float64 {
return float64(l / AstronomicalUnit)
}

// LightYears returns the length in ly
func (l Length) LightYears() float64 {
return float64(l / LightYear)
}
1 change: 1 addition & 0 deletions length_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ func TestLength(t *testing.T) {
// space
assert.Equal(t, 389.17240036420395, (1 * AstronomicalUnit).LunarDistances())
assert.Equal(t, 0.0025695552897999903, (1 * LunarDistance).AstronomicalUnits())
assert.Equal(t, 63241.07708426628, (1 * LightYear).AstronomicalUnits())
}

0 comments on commit 158876c

Please sign in to comment.