From b13f1b632fa2bbadadf5972b2f6ff82cc3c0d013 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 8 Dec 2023 12:48:40 -0800 Subject: [PATCH] Plumping through the EarthMasses unit. Followed the pattern of SolarMasses. --- shared/src/main/scala/squants/mass/Mass.scala | 10 +++++++++- shared/src/test/scala/squants/mass/MassSpec.scala | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/squants/mass/Mass.scala b/shared/src/main/scala/squants/mass/Mass.scala index 4fe30371..fcfb5f9c 100644 --- a/shared/src/main/scala/squants/mass/Mass.scala +++ b/shared/src/main/scala/squants/mass/Mass.scala @@ -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) @@ -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" @@ -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 @@ -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) @@ -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) diff --git a/shared/src/test/scala/squants/mass/MassSpec.scala b/shared/src/test/scala/squants/mass/MassSpec.scala index 0dbf07b7..05d48f97 100644 --- a/shared/src/test/scala/squants/mass/MassSpec.scala +++ b/shared/src/test/scala/squants/mass/MassSpec.scala @@ -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) @@ -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)) @@ -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) @@ -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) @@ -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²") @@ -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)) @@ -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)) @@ -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))