-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conversion to units relating to rotational dynamics units and add…
… unit tests
- Loading branch information
1 parent
bf67f58
commit 373ae33
Showing
10 changed files
with
333 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
shared/src/test/scala/squants/mass/MomentOfInertiaSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package squants.mass | ||
|
||
import org.scalatest.{FlatSpec, Matchers} | ||
import squants.CustomMatchers | ||
import squants.motion.{AngularAccelerationConversions, NewtonMeters, RadiansPerSecondSquared} | ||
import squants.space.{Feet, Meters} | ||
|
||
/** | ||
* | ||
* @author paxelord | ||
* @since 1.2 | ||
**/ | ||
class MomentOfInertiaSpec extends FlatSpec with Matchers with CustomMatchers { | ||
|
||
behavior of "MomentOfInertia and its Units of Measure" | ||
|
||
val unitValueSi = KilogramsMetersSquared(1) | ||
|
||
it should "create values using UOM factories" in { | ||
KilogramsMetersSquared(10.22).toKilogramsMetersSquared should be(10.22) | ||
PoundsSquareFeet(10.22).toPoundsSquareFeet should be(10.22) | ||
} | ||
|
||
it should "create values from properly formatted Strings" in { | ||
MomentOfInertia("10.22 kg‧m²").get should be(KilogramsMetersSquared(10.22)) | ||
MomentOfInertia("10.22 lb‧ft²").get should be(PoundsSquareFeet(10.22)) | ||
} | ||
|
||
it should "properly convert to all supported Units of Measure" in { | ||
implicit val tolerance = 1e-10 | ||
val a = KilogramsMetersSquared(1) | ||
|
||
val kilogramsToPounds = 1D / Pounds.conversionFactor | ||
val metersToFeet = 1D / Feet.conversionFactor | ||
a.toPoundsSquareFeet should beApproximately(kilogramsToPounds * metersToFeet * metersToFeet) | ||
|
||
val b = PoundsSquareFeet(1) | ||
val poundsToKilograms = Pounds.conversionFactor | ||
val feetToMeters = Feet.conversionFactor | ||
b.toKilogramsMetersSquared should beApproximately(poundsToKilograms * feetToMeters * feetToMeters) | ||
} | ||
|
||
it should "return properly formatted strings for all supported Units of Measure" in { | ||
PoundsSquareFeet(1).toString(PoundsSquareFeet) should be("1.0 lb‧ft²") | ||
unitValueSi.toString(KilogramsMetersSquared) should be("1.0 kg‧m²") | ||
} | ||
|
||
it should "return Torque when multiplied by AngularAcceleration" in { | ||
unitValueSi * RadiansPerSecondSquared(1) should be(NewtonMeters(1)) | ||
} | ||
|
||
it should "return mass when atCenter is called" in { | ||
unitValueSi atCenter Meters(1) should be(Kilograms(1)) | ||
} | ||
|
||
it should "provide aliases for single unit values" in { | ||
import MomentOfInertiaConversions._ | ||
|
||
poundSquareFeet should be(PoundsSquareFeet(1)) | ||
kilogramMetersSquared should be(KilogramsMetersSquared(1)) | ||
} | ||
|
||
it should "provide implicit conversion from Double" in { | ||
import MomentOfInertiaConversions._ | ||
|
||
val d = 10.22 | ||
d.kilogramMetersSquared should be(KilogramsMetersSquared(d)) | ||
d.poundSquareFeet should be(PoundsSquareFeet(d)) | ||
} | ||
|
||
it should "provide Numeric support" in { | ||
import MomentOfInertiaConversions._ | ||
|
||
val momentOfInertiaList = List(KilogramsMetersSquared(100), KilogramsMetersSquared(10)) | ||
momentOfInertiaList.sum should be(KilogramsMetersSquared(110)) | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
shared/src/test/scala/squants/motion/AngularAccelerationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package squants.motion | ||
|
||
import org.scalatest.{FlatSpec, Matchers} | ||
import squants.QuantityParseException | ||
import squants.space.{Meters, Radians} | ||
import squants.time.Seconds | ||
|
||
/** | ||
* | ||
* @author paxelord | ||
* @since 1.2 | ||
*/ | ||
class AngularAccelerationSpec extends FlatSpec with Matchers{ | ||
|
||
behavior of "AngularAcceleration and its Units of Measure" | ||
|
||
it should "create values using UOM factories" in { | ||
RadiansPerSecondSquared(1).toRadiansPerSecondSquared should be(1) | ||
DegreesPerSecondSquared(1).toDegreesPerSecondSquared should be(1) | ||
GradsPerSecondSquared(1).toGradsPerSecondSquared should be(1) | ||
TurnsPerSecondSquared(1).toTurnsPerSecondSquared should be(1) | ||
} | ||
|
||
it should "create values from properly formatted Strings" in { | ||
AngularAcceleration("10.22 rad/s²").get should be(RadiansPerSecondSquared(10.22)) | ||
AngularAcceleration("10.22 °/s²").get should be(DegreesPerSecondSquared(10.22)) | ||
AngularAcceleration("10.22 grad/s²").get should be(GradsPerSecondSquared(10.22)) | ||
AngularAcceleration("10.22 turns/s²").get should be(TurnsPerSecondSquared(10.22)) | ||
AngularAcceleration("10.22 zz").failed.get should be(QuantityParseException("Unable to parse AngularAcceleration", "10.22 zz")) | ||
AngularAcceleration("zz rad/s²").failed.get should be(QuantityParseException("Unable to parse AngularAcceleration", "zz rad/s²")) | ||
} | ||
|
||
it should "properly convert to all supported Units of Measure" in { | ||
val x = RadiansPerSecondSquared(1) | ||
x.toRadiansPerSecondSquared should be(1) | ||
x.toDegreesPerSecondSquared should be(Radians(1).toDegrees) | ||
x.toGradsPerSecondSquared should be(Radians(1).toGradians) | ||
x.toTurnsPerSecondSquared should be(Radians(1).toTurns) | ||
} | ||
|
||
it should "return properly formatted strings for all supported Units of Measure" in { | ||
RadiansPerSecondSquared(1).toString(RadiansPerSecondSquared) should be("1.0 rad/s²") | ||
DegreesPerSecondSquared(1).toString(DegreesPerSecondSquared) should be("1.0 °/s²") | ||
GradsPerSecondSquared(1).toString(GradsPerSecondSquared) should be("1.0 grad/s²") | ||
TurnsPerSecondSquared(1).toString(TurnsPerSecondSquared) should be("1.0 turns/s²") | ||
} | ||
|
||
it should "return AnglularVelocity when multiplied by Time" in { | ||
RadiansPerSecondSquared(1) * Seconds(1) should be(RadiansPerSecond(1)) | ||
} | ||
|
||
it should "return Acceleration of particle onRadius of AngularAcceleration" in { | ||
RadiansPerSecondSquared(1) onRadius Meters(1) should be(MetersPerSecondSquared(1)) | ||
} | ||
|
||
behavior of "AngularAccelerationConversions" | ||
|
||
it should "provide aliases for single unit values" in { | ||
import AngularAccelerationConversions._ | ||
|
||
radianPerSecondSquared should be(RadiansPerSecondSquared(1)) | ||
degreePerSecondSquared should be(DegreesPerSecondSquared(1)) | ||
gradPerSecondSquared should be(GradsPerSecondSquared(1)) | ||
turnPerSecondSquared should be(TurnsPerSecondSquared(1)) | ||
} | ||
|
||
it should "provide implicit conversion from Double" in { | ||
import AngularAccelerationConversions._ | ||
|
||
val d = 10.22d | ||
d.radiansPerSecondSquared should be(RadiansPerSecondSquared(d)) | ||
d.degreesPerSecondSquared should be(DegreesPerSecondSquared(d)) | ||
d.gradsPerSecondSquared should be(GradsPerSecondSquared(d)) | ||
d.turnsPerSecondSquared should be(TurnsPerSecondSquared(d)) | ||
} | ||
|
||
it should "provide Numeric support" in { | ||
import AngularAccelerationConversions.AngularAccelerationNumeric | ||
|
||
val aas = List(RadiansPerSecondSquared(100), RadiansPerSecondSquared(10)) | ||
aas.sum should be(RadiansPerSecondSquared(110)) | ||
} | ||
} |
Oops, something went wrong.