Skip to content

Commit

Permalink
Merge pull request #8 from martinlindhe/breaking
Browse files Browse the repository at this point in the history
Breaking changes for 0.2
  • Loading branch information
martinlindhe authored Jan 12, 2017
2 parents db58427 + 27761a0 commit 8415e91
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 69 deletions.
100 changes: 50 additions & 50 deletions time.go → duration.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package unit

// Time represents a SI unit of time (in seconds, s)
type Time Unit
// Duration represents a SI unit of time (in seconds, s)
type Duration Unit

// ...
const (
// SI
Yoctosecond = Second * 1e-24
Zeptosecond = Second * 1e-21
Attosecond = Second * 1e-18
Femtosecond = Second * 1e-15
Picosecond = Second * 1e-12
Nanosecond = Second * 1e-9
Microsecond = Second * 1e-6
Millisecond = Second * 1e-3
Centisecond = Second * 1e-2
Decisecond = Second * 1e-1
Second Time = 1e0
Decasecond = Second * 1e1
Hectosecond = Second * 1e2
Kilosecond = Second * 1e3
Megasecond = Second * 1e6
Gigasecond = Second * 1e9
Terasecond = Second * 1e12
Petasecond = Second * 1e15
Exasecond = Second * 1e18
Zettasecond = Second * 1e21
Yottasecond = Second * 1e24
Yoctosecond = Second * 1e-24
Zeptosecond = Second * 1e-21
Attosecond = Second * 1e-18
Femtosecond = Second * 1e-15
Picosecond = Second * 1e-12
Nanosecond = Second * 1e-9
Microsecond = Second * 1e-6
Millisecond = Second * 1e-3
Centisecond = Second * 1e-2
Decisecond = Second * 1e-1
Second Duration = 1e0
Decasecond = Second * 1e1
Hectosecond = Second * 1e2
Kilosecond = Second * 1e3
Megasecond = Second * 1e6
Gigasecond = Second * 1e9
Terasecond = Second * 1e12
Petasecond = Second * 1e15
Exasecond = Second * 1e18
Zettasecond = Second * 1e21
Yottasecond = Second * 1e24

// non-SI
Minute = Second * 60
Expand All @@ -38,136 +38,136 @@ const (
)

// Yoctoseconds returns the time in ys
func (t Time) Yoctoseconds() float64 {
func (t Duration) Yoctoseconds() float64 {
return float64(t / Yoctosecond)
}

// Zeptoseconds returns the time in zs
func (t Time) Zeptoseconds() float64 {
func (t Duration) Zeptoseconds() float64 {
return float64(t / Zeptosecond)
}

// Attoseconds returns the time in as
func (t Time) Attoseconds() float64 {
func (t Duration) Attoseconds() float64 {
return float64(t / Attosecond)
}

// Femtoseconds returns the time in fs
func (t Time) Femtoseconds() float64 {
func (t Duration) Femtoseconds() float64 {
return float64(t / Femtosecond)
}

// Picoseconds returns the time in ps
func (t Time) Picoseconds() float64 {
func (t Duration) Picoseconds() float64 {
return float64(t / Picosecond)
}

// Nanoseconds returns the time in ns
func (t Time) Nanoseconds() float64 {
func (t Duration) Nanoseconds() float64 {
return float64(t / Nanosecond)
}

// Microseconds returns the time in µs
func (t Time) Microseconds() float64 {
func (t Duration) Microseconds() float64 {
return float64(t / Microsecond)
}

// Milliseconds returns the time in ms
func (t Time) Milliseconds() float64 {
func (t Duration) Milliseconds() float64 {
return float64(t / Millisecond)
}

// Centiseconds returns the time in cs
func (t Time) Centiseconds() float64 {
func (t Duration) Centiseconds() float64 {
return float64(t / Centisecond)
}

// Deciseconds returns the time in ds
func (t Time) Deciseconds() float64 {
func (t Duration) Deciseconds() float64 {
return float64(t / Decisecond)
}

// Seconds returns the time in s
func (t Time) Seconds() float64 {
func (t Duration) Seconds() float64 {
return float64(t / Second)
}

// Decaseconds returns the time in das
func (t Time) Decaseconds() float64 {
func (t Duration) Decaseconds() float64 {
return float64(t / Decasecond)
}

// Hectoseconds returns the time in hs
func (t Time) Hectoseconds() float64 {
func (t Duration) Hectoseconds() float64 {
return float64(t / Hectosecond)
}

// Kiloseconds returns the time in ks
func (t Time) Kiloseconds() float64 {
func (t Duration) Kiloseconds() float64 {
return float64(t / Kilosecond)
}

// Megaseconds returns the time in Ms
func (t Time) Megaseconds() float64 {
func (t Duration) Megaseconds() float64 {
return float64(t / Megasecond)
}

// Gigaseconds returns the time in Gs
func (t Time) Gigaseconds() float64 {
func (t Duration) Gigaseconds() float64 {
return float64(t / Gigasecond)
}

// Teraseconds returns the time in Ts
func (t Time) Teraseconds() float64 {
func (t Duration) Teraseconds() float64 {
return float64(t / Terasecond)
}

// Petaseconds returns the time in Ps
func (t Time) Petaseconds() float64 {
func (t Duration) Petaseconds() float64 {
return float64(t / Petasecond)
}

// Exaseconds returns the time in volt
func (t Time) Exaseconds() float64 {
func (t Duration) Exaseconds() float64 {
return float64(t / Exasecond)
}

// Zettaseconds returns the time in Zs
func (t Time) Zettaseconds() float64 {
func (t Duration) Zettaseconds() float64 {
return float64(t / Zettasecond)
}

// Yottaseconds returns the time in Ys
func (t Time) Yottaseconds() float64 {
func (t Duration) Yottaseconds() float64 {
return float64(t / Yottasecond)
}

// Minutes returns the time in m
func (t Time) Minutes() float64 {
func (t Duration) Minutes() float64 {
return float64(t / Minute)
}

// Hours returns the time in h
func (t Time) Hours() float64 {
func (t Duration) Hours() float64 {
return float64(t / Hour)
}

// Days returns the time in d
func (t Time) Days() float64 {
func (t Duration) Days() float64 {
return float64(t / Day)
}

// Weeks returns the time in w
func (t Time) Weeks() float64 {
func (t Duration) Weeks() float64 {
return float64(t / Week)
}

// ThirtyDayMonths returns the time in M
func (t Time) ThirtyDayMonths() float64 {
func (t Duration) ThirtyDayMonths() float64 {
return float64(t / ThirtyDayMonth)
}

// JulianYears returns the time in Y
func (t Time) JulianYears() float64 {
func (t Duration) JulianYears() float64 {
return float64(t / JulianYear)
}
2 changes: 1 addition & 1 deletion time_test.go → duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestTime(t *testing.T) {
func TestDuration(t *testing.T) {

// SI
assert.Equal(t, 1e3, (1 * Zeptosecond).Yoctoseconds())
Expand Down
8 changes: 4 additions & 4 deletions mass.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const (
Milligram = Gram * 1e-3
Centigram = Gram * 1e-2
Decigram = Gram * 1e-1
Gram Mass = 1e0
Gram = Kilogram * 1e-3
Decagram = Gram * 1e1
Hectogram = Gram * 1e2
Kilogram = Gram * 1e3
Kilogram Mass = 1e0
Megagram = Gram * 1e6
Gigagram = Gram * 1e9
Teragram = Gram * 1e12
Expand Down Expand Up @@ -110,7 +110,7 @@ func (m Mass) Decigrams() float64 {

// Grams returns the mass in g
func (m Mass) Grams() float64 {
return float64(m)
return float64(m / Gram)
}

// Decagrams returns the mass in dag
Expand All @@ -125,7 +125,7 @@ func (m Mass) Hectograms() float64 {

// Kilograms returns the mass in kg
func (m Mass) Kilograms() float64 {
return float64(m / Kilogram)
return float64(m)
}

// Megagrams returns the mass in Mg
Expand Down
28 changes: 14 additions & 14 deletions mass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
func TestMass(t *testing.T) {

// SI
assert.Equal(t, 1e3, (1 * Zeptogram).Yoctograms())
assert.Equal(t, 1000.0000000000001, (1 * Attogram).Zeptograms()) // round error, expected 1e3
assert.Equal(t, 1e3+0.0000000000001, (1 * Zeptogram).Yoctograms())
assert.Equal(t, 1e3+0.0000000000002, (1 * Attogram).Zeptograms())
assert.Equal(t, 1e3, (1 * Femtogram).Attograms())
assert.Equal(t, 999.9999999999999, (1 * Picogram).Femtograms()) // round error, expected 1e3
assert.Equal(t, 1000.0000000000001, (1 * Nanogram).Picograms()) // round error, expected 1e3
assert.Equal(t, 999.9999999999999, (1 * Microgram).Nanograms()) // round error, expected 1e3
assert.Equal(t, 1000.0000000000001, (1 * Milligram).Micrograms()) // round error, expected 1e3
assert.Equal(t, 1e3, (1 * Picogram).Femtograms())
assert.Equal(t, 1e3+0.0000000000001, (1 * Nanogram).Picograms())
assert.Equal(t, 1e3-0.0000000000001, (1 * Microgram).Nanograms())
assert.Equal(t, 1e3-0.0000000000001, (1 * Milligram).Micrograms())

assert.Equal(t, 1e3, (1 * Gram).Milligrams())
assert.Equal(t, 1e3+0.0000000000001, (1 * Gram).Milligrams())
assert.Equal(t, 1e2, (1 * Gram).Centigrams())
assert.Equal(t, 1e1, (1 * Gram).Decigrams())
assert.Equal(t, 1e0, (1 * Gram).Grams())
Expand All @@ -43,21 +43,21 @@ func TestMass(t *testing.T) {
assert.Equal(t, 1e-3, (1 * Petatonne).Exatonnes())

// avoirdupois
assert.Equal(t, 0.015432358352941431, (1 * Milligram).TroyGrains())
assert.Equal(t, 0.002285714285714286, (1 * TroyGrain).AvoirdupoisOunces())
assert.Equal(t, 0.036571428571428574, (1 * TroyGrain).AvoirdupoisDrams())
assert.Equal(t, 0.00014285714285714287, (1 * TroyGrain).AvoirdupoisPounds())
assert.Equal(t, 0.015432358352941428, (1 * Milligram).TroyGrains())
assert.Equal(t, 0.0022857142857142855, (1 * TroyGrain).AvoirdupoisOunces())
assert.Equal(t, 0.03657142857142857, (1 * TroyGrain).AvoirdupoisDrams())
assert.Equal(t, 0.00014285714285714284, (1 * TroyGrain).AvoirdupoisPounds())

assert.Equal(t, 0.07142857142857142, (1 * AvoirdupoisPound).UsStones())
assert.Equal(t, 0.05877551020408164, (1 * TroyPound).UkStones())
assert.Equal(t, 0.058775510204081644, (1 * TroyPound).UkStones())

// https://en.wikipedia.org/wiki/Quarter_(unit)#Weight
assert.Equal(t, 0.08818490487395103, (1 * Kilogram).UsQuarters())
assert.Equal(t, 0.08818490487395102, (1 * Kilogram).UsQuarters())
assert.Equal(t, 0.07873652220888486, (1 * Kilogram).UkQuarters())

// https://en.wikipedia.org/wiki/Hundredweight
assert.Equal(t, 50.802345439999996, (1 * LongHundredweight).Kilograms())
assert.Equal(t, 45.359237, (1 * ShortHundredweight).Kilograms())
assert.Equal(t, 45.35923700000001, (1 * ShortHundredweight).Kilograms())
assert.Equal(t, 1.0000000000000002, (112 * AvoirdupoisPound).LongHundredweights()) // round error, expected 1e0
assert.Equal(t, 1e0, (100 * AvoirdupoisPound).ShortHundredweights())

Expand Down

0 comments on commit 8415e91

Please sign in to comment.