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

Improve specs #493

Merged
merged 3 commits into from
May 18, 2018
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
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
}
}