Skip to content

Commit

Permalink
Plumping through the EarthMasses unit. Followed the pattern of SolarM…
Browse files Browse the repository at this point in the history
…asses.
  • Loading branch information
danielrmeyer committed Dec 8, 2023
1 parent 650d489 commit b13f1b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion shared/src/main/scala/squants/mass/Mass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class Mass private (val value: Double, val unit: MassUnit)
def toTolas = to(Tolas)
def toCarats = to(Carats)
def toSolarMasses = to(SolarMasses)
def toEarthMasses = to(EarthMasses)
def toDalton = to(Dalton)

def toeV = to(ElectronVoltMass)
Expand All @@ -87,7 +88,7 @@ object Mass extends Dimension[Mass] with BaseDimension {
def primaryUnit = Grams
def siUnit = Kilograms
def units = Set(Nanograms, Micrograms, Milligrams, Grams, Kilograms, Tonnes, Ounces, Pounds, Kilopounds, Megapounds,
Stone, TroyGrains, Pennyweights, TroyOunces, TroyPounds, Tolas, Carats, SolarMasses, Dalton,
Stone, TroyGrains, Pennyweights, TroyOunces, TroyPounds, Tolas, Carats, SolarMasses, EarthMasses, Dalton,
ElectronVoltMass, MilliElectronVoltMass, KiloElectronVoltMass, MegaElectronVoltMass,
GigaElectronVoltMass, TeraElectronVoltMass, PetaElectronVoltMass, ExaElectronVoltMass)
def dimensionSymbol = "M"
Expand Down Expand Up @@ -189,6 +190,11 @@ object SolarMasses extends MassUnit {
val symbol = "M☉"
}

object EarthMasses extends MassUnit {
val conversionFactor = 5.9760000000002e+27
val symbol = "M⊕"
}

object Dalton extends MassUnit {
// Value with reference to NIST (https://physics.nist.gov/cgi-bin/cuu/Value?u)
val conversionFactor = 1.66053906660e-27 * MetricSystem.Kilo
Expand Down Expand Up @@ -258,6 +264,7 @@ object MassConversions {
lazy val tola = Tolas(1)
lazy val carat = Carats(1)
lazy val solarMass = SolarMasses(1)
lazy val earthMass = EarthMasses(1)
lazy val dalton = Dalton(1)

lazy val eV = ElectronVoltMass(1)
Expand Down Expand Up @@ -295,6 +302,7 @@ object MassConversions {
def ct = Carats(n)
def carats = Carats(n)
def solarMasses = SolarMasses(n)
def earthMasses = EarthMasses(n)
def dalton = Dalton(n)

def eV = ElectronVoltMass(n)
Expand Down
8 changes: 8 additions & 0 deletions shared/src/test/scala/squants/mass/MassSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
Tolas(10.22).toTolas should be(10.22)
Carats(10.22).toCarats should be(10.22)
SolarMasses(10.22).toSolarMasses should be(10.22)
EarthMasses(10.22).toEarthMasses should be(10.22)
Dalton(10.22).toDalton should be(10.22)

ElectronVoltMass(1).toeV should be(1)
Expand Down Expand Up @@ -74,6 +75,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
Mass("10.22 tola").get should be(Tolas(10.22))
Mass("10.22 ct").get should be(Carats(10.22))
Mass("10.22 M☉").get should be(SolarMasses(10.22))
Mass("10.22 M⊕").get should be(EarthMasses(10.22))
Mass("10.22 Da").get should be(Dalton(10.22))
Mass("10.22 eV/c²").get should be(ElectronVoltMass(10.22))
Mass("10.22 meV/c²").get should be(MilliElectronVoltMass(10.22))
Expand Down Expand Up @@ -103,6 +105,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
x.toTroyPounds should be (1 / TroyPounds.conversionFactor)
x.toCarats should be (1 / Carats.conversionFactor)
x.toSolarMasses should be (1 / SolarMasses.conversionFactor)
x.toEarthMasses should be (1 / EarthMasses.conversionFactor)
x.toDalton should be (1 / Dalton.conversionFactor)
x.toeV should be (1 / ElectronVoltMass.conversionFactor)

Expand All @@ -119,6 +122,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
TroyOunces(1).toGrams should be(31.1034768)
Pennyweights(1).toGrams should be(1.55517384 +- 0.000000001)
SolarMasses(1).toKilograms should be(1.98855e30 +- 0.00025)
EarthMasses(1).toKilograms should be (5.9760000000002e+24 +- 0.00025)
Dalton(1).toKilograms should be(1.66053906660e-27)

x.toeV should be(1 / ElectronVoltMass.conversionFactor)
Expand Down Expand Up @@ -150,6 +154,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
Tolas(1).toString(Tolas) should be("1.0 tola")
Carats(1).toString(Carats) should be("1.0 ct")
SolarMasses(1).toString(SolarMasses) should be("1.0 M☉")
EarthMasses(1).toString(EarthMasses) should be ("1.0 M⊕")
Dalton(1).toString(Dalton) should be("1.0 Da")

ElectronVoltMass(1).toString(ElectronVoltMass) should be("1.0 eV/c²")
Expand Down Expand Up @@ -220,6 +225,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
tola should be(Tolas(1))
carat should be(Carats(1))
solarMass should be(SolarMasses(1))
earthMass should be(EarthMasses(1))
dalton should be(Dalton(1))

eV should be(ElectronVoltMass(1))
Expand Down Expand Up @@ -260,6 +266,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
d.ct should be(Carats(d))
d.carats should be(Carats(d))
d.solarMasses should be(SolarMasses(d))
d.earthMasses should be(EarthMasses(d))
d.dalton should be(Dalton(d))

d.eV should be(ElectronVoltMass(d))
Expand Down Expand Up @@ -301,6 +308,7 @@ class MassSpec extends AnyFlatSpec with Matchers {
"10.45 tola".toMass.get should be(Tolas(10.45))
"10.45 ct".toMass.get should be(Carats(10.45))
"10.45 M☉".toMass.get should be(SolarMasses(10.45))
"10.45 M⊕".toMass.get should be(EarthMasses(10.45))
"10.45 Da".toMass.get should be(Dalton(10.45))
"10.22 eV/c²".toMass.get should be(ElectronVoltMass(10.22))
"10.22 meV/c²".toMass.get should be(MilliElectronVoltMass(10.22))
Expand Down

0 comments on commit b13f1b6

Please sign in to comment.