Skip to content

Commit

Permalink
Merge pull request #409 from quartin/time-derivative-A-division-by-A
Browse files Browse the repository at this point in the history
Adds division of TimeDerivative[A] by quantity of A
  • Loading branch information
cquiroz authored Aug 12, 2020
2 parents 38d6501 + 3f9b930 commit 6437120
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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))
}
}

0 comments on commit 6437120

Please sign in to comment.