Skip to content

Commit

Permalink
Closes typelevel#324, value field of Information is now Long
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Kuroedov committed Apr 11, 2019
1 parent 3aa9816 commit f7c543d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
11 changes: 9 additions & 2 deletions shared/src/main/scala/squants/information/Information.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ import squants.time.TimeIntegral
* @since 0.6.0
* @param value value in [[squants.information.Bytes]]
*/
final class Information private(val value: Double, val unit: InformationUnit)
final class Information private(val amount: Long, val unit: InformationUnit)
extends Quantity[Information]
with TimeIntegral[DataRate] {

def dimension = Information

def value = amount.toDouble

// overridden to remove the forcing of doubles for this unit that makes
// no sense, now that this dimension is represented by a Long
override def toString(): String = s"$amount ${unit.symbol}"
override def toString(uom: UnitOfMeasure[Information]): String = in(uom).toString()

protected def timeDerived = BytesPerSecond(toBytes)
protected[squants] def time = Seconds(1)

Expand Down Expand Up @@ -72,7 +79,7 @@ trait InformationUnit extends UnitOfMeasure[Information] with UnitConverter {
* Factory singleton for information
*/
object Information extends Dimension[Information] with BaseDimension {
private[information] def apply[A](n: A, unit: InformationUnit)(implicit num: Numeric[A]) = new Information(num.toDouble(n), unit)
private[information] def apply[A](n: A, unit: InformationUnit)(implicit num: Numeric[A]) = new Information(num.toLong(n), unit)
def apply(value: Any) = parse(value)
def name = "Information"
def primaryUnit = Bytes
Expand Down
74 changes: 37 additions & 37 deletions shared/src/test/scala/squants/information/InformationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,43 +146,43 @@ class InformationSpec extends FlatSpec with Matchers {
}

it should "return properly formatted strings for all supported Units of Measure" in {
Bytes(1).toString(Bytes) should be("1.0 B")
Kilobytes(1).toString(Kilobytes) should be("1.0 KB")
Megabytes(1).toString(Megabytes) should be("1.0 MB")
Gigabytes(1).toString(Gigabytes) should be("1.0 GB")
Terabytes(1).toString(Terabytes) should be("1.0 TB")
Petabytes(1).toString(Petabytes) should be("1.0 PB")
Exabytes(1).toString(Exabytes) should be("1.0 EB")
Zettabytes(1).toString(Zettabytes) should be("1.0 ZB")
Yottabytes(1).toString(Yottabytes) should be("1.0 YB")

Kibibytes(1).toString(Kibibytes) should be("1.0 KiB")
Mebibytes(1).toString(Mebibytes) should be("1.0 MiB")
Gibibytes(1).toString(Gibibytes) should be("1.0 GiB")
Tebibytes(1).toString(Tebibytes) should be("1.0 TiB")
Pebibytes(1).toString(Pebibytes) should be("1.0 PiB")
Exbibytes(1).toString(Exbibytes) should be("1.0 EiB")
Zebibytes(1).toString(Zebibytes) should be("1.0 ZiB")
Yobibytes(1).toString(Yobibytes) should be("1.0 YiB")

Bits(1).toString(Bits) should be("1.0 bit")
Kilobits(1).toString(Kilobits) should be("1.0 Kbit")
Megabits(1).toString(Megabits) should be("1.0 Mbit")
Gigabits(1).toString(Gigabits) should be("1.0 Gbit")
Terabits(1).toString(Terabits) should be("1.0 Tbit")
Petabits(1).toString(Petabits) should be("1.0 Pbit")
Exabits(1).toString(Exabits) should be("1.0 Ebit")
Zettabits(1).toString(Zettabits) should be("1.0 Zbit")
Yottabits(1).toString(Yottabits) should be("1.0 Ybit")

Kibibits(1).toString(Kibibits) should be("1.0 Kibit")
Mebibits(1).toString(Mebibits) should be("1.0 Mibit")
Gibibits(1).toString(Gibibits) should be("1.0 Gibit")
Tebibits(1).toString(Tebibits) should be("1.0 Tibit")
Pebibits(1).toString(Pebibits) should be("1.0 Pibit")
Exbibits(1).toString(Exbibits) should be("1.0 Eibit")
Zebibits(1).toString(Zebibits) should be("1.0 Zibit")
Yobibits(1).toString(Yobibits) should be("1.0 Yibit")
Bytes(1).toString(Bytes) should be("1 B")
Kilobytes(1).toString(Kilobytes) should be("1 KB")
Megabytes(1).toString(Megabytes) should be("1 MB")
Gigabytes(1).toString(Gigabytes) should be("1 GB")
Terabytes(1).toString(Terabytes) should be("1 TB")
Petabytes(1).toString(Petabytes) should be("1 PB")
Exabytes(1).toString(Exabytes) should be("1 EB")
Zettabytes(1).toString(Zettabytes) should be("1 ZB")
Yottabytes(1).toString(Yottabytes) should be("1 YB")

Kibibytes(1).toString(Kibibytes) should be("1 KiB")
Mebibytes(1).toString(Mebibytes) should be("1 MiB")
Gibibytes(1).toString(Gibibytes) should be("1 GiB")
Tebibytes(1).toString(Tebibytes) should be("1 TiB")
Pebibytes(1).toString(Pebibytes) should be("1 PiB")
Exbibytes(1).toString(Exbibytes) should be("1 EiB")
Zebibytes(1).toString(Zebibytes) should be("1 ZiB")
Yobibytes(1).toString(Yobibytes) should be("1 YiB")

Bits(1).toString(Bits) should be("1 bit")
Kilobits(1).toString(Kilobits) should be("1 Kbit")
Megabits(1).toString(Megabits) should be("1 Mbit")
Gigabits(1).toString(Gigabits) should be("1 Gbit")
Terabits(1).toString(Terabits) should be("1 Tbit")
Petabits(1).toString(Petabits) should be("1 Pbit")
Exabits(1).toString(Exabits) should be("1 Ebit")
Zettabits(1).toString(Zettabits) should be("1 Zbit")
Yottabits(1).toString(Yottabits) should be("1 Ybit")

Kibibits(1).toString(Kibibits) should be("1 Kibit")
Mebibits(1).toString(Mebibits) should be("1 Mibit")
Gibibits(1).toString(Gibibits) should be("1 Gibit")
Tebibits(1).toString(Tebibits) should be("1 Tibit")
Pebibits(1).toString(Pebibits) should be("1 Pibit")
Exbibits(1).toString(Exbibits) should be("1 Eibit")
Zebibits(1).toString(Zebibits) should be("1 Zibit")
Yobibits(1).toString(Yobibits) should be("1 Yibit")
}

it should "return Time when divided by DataRate" in {
Expand Down

0 comments on commit f7c543d

Please sign in to comment.