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

All dimensions were made to have implicit field equal to this. #326

Merged
merged 6 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions shared/src/main/scala/squants/Dimension.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ trait Dimension[A <: Quantity[A]] {
case None ⇒ Failure(QuantityParseException(s"Unable to identify $name unit ${symbol}", s"(${Platform.crossFormat(num.toDouble(value))},${symbol})"))
}
}

implicit val dimensionImplicit: Dimension[A] = this
}

case class QuantityParseException(message: String, expression: String) extends Exception(s"$message:$expression")
Expand Down
4 changes: 4 additions & 0 deletions shared/src/test/scala/squants/QuantitySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,8 @@ class QuantitySpec extends FlatSpec with Matchers with CustomMatchers with TryVa
timeInMinutes.hashCode() shouldBe timeInSeconds.hashCode()

}

it should "provide implicit instance for Dimension" in {
implicitly[Dimension[Thingee]] shouldBe Thingee
}
}
6 changes: 5 additions & 1 deletion shared/src/test/scala/squants/time/FrequencySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import squants.mass.Kilograms
import squants.motion._
import squants.photo.{ LumenSeconds, Lumens, Lux, LuxSeconds }
import squants.space.{ CubicMeters, Meters, Radians }
import squants.{ Each, MetricSystem, QuantityParseException }
import squants.{ Dimension, Each, MetricSystem, QuantityParseException }

/**
* @author garyKeorkunian
Expand Down Expand Up @@ -102,4 +102,8 @@ class FrequencySpec extends FlatSpec with Matchers {
d.terahertz should be(Terahertz(d))
d.rpm should be(RevolutionsPerMinute(d))
}

it should "provide implicit instance for Dimension" in {
implicitly[Dimension[Frequency]] shouldBe Frequency
}
}
6 changes: 5 additions & 1 deletion shared/src/test/scala/squants/time/TimeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package squants.time

import org.scalatest.{ FlatSpec, Matchers }
import squants.QuantityParseException
import squants.{ Dimension, QuantityParseException }
import squants.motion.{ MetersPerSecond, MetersPerSecondCubed, MetersPerSecondSquared }
import squants.space.Meters

Expand Down Expand Up @@ -222,4 +222,8 @@ class TimeSpec extends FlatSpec with Matchers {

doSomethingWithDuration(Seconds(10))
}

it should "provide implicit instance for Dimension" in {
implicitly[Dimension[Time]] shouldBe Time
}
}