Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds division of TimeDerivative[A] by quantity of A #409

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions shared/src/main/scala/squants/time/TimeDerivative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ trait TimeDerivative[A <: Quantity[A] with TimeIntegral[_]] {
* @return
*/
def *(that: Time): A = timeIntegrated * (that / this.time)

/**
* Returns the portion of quantity change per unit of Time
*
* @param that The amount of Quantity
* @return
*/
def /(that: A): Frequency = (timeIntegrated / that) / time
}

trait SecondTimeDerivative[A <: SecondTimeIntegral[_]] { self: TimeDerivative[_] ⇒
Expand Down
16 changes: 13 additions & 3 deletions shared/src/test/scala/squants/time/TimeDerivativeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
package squants.time

import squants.CustomMatchers
import squants.motion.UsMilesPerHour
import squants.space.UsMiles
import squants.motion.{MetersPerSecond, UsMilesPerHour}
import squants.space.{Meters, UsMiles}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

Expand Down Expand Up @@ -41,6 +41,16 @@ class TimeDerivativeSpec extends AnyFlatSpec with Matchers with CustomMatchers {

it should "satisfy Derivative = Integral * Frequency" in {
implicit val tolerance = UsMilesPerHour(0.0000000000001)
UsMilesPerHour(55) should beApproximately(UsMiles(55) * 1/Hours(1))
UsMilesPerHour(55) should beApproximately(UsMiles(55) * 1 / Hours(1))
}

it should "satisfy Frequency = Derivative / Integral (Time value in hours)" in {
implicit val tolerance = Hertz(0.0000000000001)
Hertz(0.01) should beApproximately(UsMilesPerHour(72) / UsMiles(2))
}

it should "satisfy Frequency = Derivative / Integral (Time value in Seconds)" in {
implicit val tolerance = Hertz(0.0000000000001)
Hertz(55) should beApproximately(MetersPerSecond(110) / Meters(2))
}
}