Skip to content

Commit

Permalink
Merge pull request #493 from rider-yi/improve_numeric_types_spec
Browse files Browse the repository at this point in the history
Improve specs
  • Loading branch information
fthomas authored May 18, 2018
2 parents 08eeb59 + 1a12e79 commit 7e12673
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ class CharTypesSpec extends Properties("CharTypes") {
LowerCaseChar.from('a').isRight
}

property("LowerCaseChar.from('A')") = secure {
LowerCaseChar.from('A') ?= Left("Predicate failed: isLower('A').")
}

property("UpperCaseChar.from('A')") = secure {
UpperCaseChar.from('A').isRight
}

property("UpperCaseChar.from('a')") = secure {
UpperCaseChar.from('a') ?= Left("Predicate failed: isUpper('a').")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.timepit.refined.types

import eu.timepit.refined.TestUtils.wellTyped
import eu.timepit.refined.types.all._
import org.scalacheck.Prop._
import org.scalacheck.Properties
Expand All @@ -11,80 +10,127 @@ class NumericTypesSpec extends Properties("NumericTypes") {
PosInt.from(1).isRight
}

property("PosInt.from(-1)") = secure {
PosInt.from(-1) ?= Left("Predicate failed: (-1 > 0).")
}

property("PosInt.unapply(1)") = secure {
val PosInt(x) = 1
x ?= PosInt.unsafeFrom(1)
}

property("PosInt.unsafeFrom(1)") = wellTyped {
PosInt.unsafeFrom(1)
}

property("PosInt.unsafeFrom(-1)") = secure {
throws(classOf[IllegalArgumentException])(PosInt.unsafeFrom(-1))
property("PosInt.from(0)") = secure {
PosInt.from(0) ?= Left("Predicate failed: (0 > 0).")
}

property("NonNegInt.from(0)") = secure {
NonNegInt.from(0).isRight
}

property("NonNegInt.from(-1)") = secure {
NonNegInt.from(-1) ?= Left("Predicate (-1 < 0) did not fail.")
}

property("NegInt.from(-1)") = secure {
NegInt.from(-1).isRight
}

property("NegInt.from(0)") = secure {
NegInt.from(0) ?= Left("Predicate failed: (0 < 0).")
}

property("NonPosInt.from(0)") = secure {
NonPosInt.from(0).isRight
}

property("NonPosInt.from(1)") = secure {
NonPosInt.from(1) ?= Left("Predicate (1 > 0) did not fail.")
}

property("PosLong.from(1L)") = secure {
PosLong.from(1L).isRight
}

property("PosLong.from(0L)") = secure {
PosLong.from(0L) ?= Left("Predicate failed: (0 > 0).")
}

property("NonNegLong.from(0L)") = secure {
NonNegLong.from(0L).isRight
}

property("NonNegLong.from(-1L)") = secure {
NonNegLong.from(-1L) ?= Left("Predicate (-1 < 0) did not fail.")
}

property("NegLong.from(-1L)") = secure {
NegLong.from(-1L).isRight
}

property("NegLong.from(0L)") = secure {
NegLong.from(0L) ?= Left("Predicate failed: (0 < 0).")
}

property("NonPosLong.from(0L)") = secure {
NonPosLong.from(0L).isRight
}

property("NonPosLong.from(1L)") = secure {
NonPosLong.from(1L) ?= Left("Predicate (1 > 0) did not fail.")
}

property("PosFloat.from(0.1F)") = secure {
PosFloat.from(0.1F).isRight
}

property("PosFloat.from(0.0F)") = secure {
PosFloat.from(0.0F).isLeft
}

property("NonNegFloat.from(0.0F)") = secure {
NonNegFloat.from(0.0F).isRight
}

property("NonNegFloat.from(-0.1F)") = secure {
NonNegFloat.from(-0.1F).isLeft
}

property("NegFloat.from(-0.1F)") = secure {
NegFloat.from(-0.1F).isRight
}

property("NegFloat.from(0.0F)") = secure {
NegFloat.from(0.0F).isLeft
}

property("NonPosFloat.from(0.0F)") = secure {
NonPosFloat.from(0.0F).isRight
}

property("NonPosFloat.from(0.1F)") = secure {
NonPosFloat.from(0.1F).isLeft
}

property("PosDouble.from(0.1)") = secure {
PosDouble.from(0.1).isRight
}

property("PosDouble.from(0.0)") = secure {
PosDouble.from(0.0).isLeft
}

property("NonNegDouble.from(0.0)") = secure {
NonNegDouble.from(0.0).isRight
}

property("NonNegDouble.from(-0.1)") = secure {
NonNegDouble.from(-0.1).isLeft
}

property("NegDouble.from(-0.1)") = secure {
NegDouble.from(-0.1).isRight
}

property("NegDouble.from(0.0)") = secure {
NegDouble.from(0.0).isLeft
}

property("NonPosDouble.from(0.0)") = secure {
NonPosDouble.from(0.0).isRight
}

property("NonPosDouble.from(0.1)") = secure {
NonPosDouble.from(0.1).isLeft
}
}

0 comments on commit 7e12673

Please sign in to comment.