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

Fix case when numeric inference kicks out before minimal tautology inference #894

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -133,26 +133,26 @@ private[refined] trait NumericInference {
wb: WitnessAs[B, C],
nc: Numeric[C]
): Less[A] ==> Less[B] =
Inference(nc.lt(wa.snd, wb.snd), s"lessInference(${wa.snd}, ${wb.snd})")
Inference(nc.lteq(wa.snd, wb.snd), s"lessInference(${wa.snd}, ${wb.snd})")

implicit def lessInferenceNat[A <: Nat, B <: Nat](implicit
ta: ToInt[A],
tb: ToInt[B]
): Less[A] ==> Less[B] =
Inference(ta() < tb(), s"lessInferenceNat(${ta()}, ${tb()})")
Inference(ta() <= tb(), s"lessInferenceNat(${ta()}, ${tb()})")

implicit def greaterInference[C, A, B](implicit
wa: WitnessAs[A, C],
wb: WitnessAs[B, C],
nc: Numeric[C]
): Greater[A] ==> Greater[B] =
Inference(nc.gt(wa.snd, wb.snd), s"greaterInference(${wa.snd}, ${wb.snd})")
Inference(nc.gteq(wa.snd, wb.snd), s"greaterInference(${wa.snd}, ${wb.snd})")

implicit def greaterInferenceNat[A <: Nat, B <: Nat](implicit
ta: ToInt[A],
tb: ToInt[B]
): Greater[A] ==> Greater[B] =
Inference(ta() > tb(), s"greaterInferenceNat(${ta()}, ${tb()})")
Inference(ta() >= tb(), s"greaterInferenceNat(${ta()}, ${tb()})")

implicit def greaterEqualInference[A]: Greater[A] ==> GreaterEqual[A] =
Inference.alwaysValid("greaterEqualInference")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,26 @@ private[refined] trait NumericInference {
wb: WitnessAs[B, C],
nc: Numeric[C]
): Less[A] ==> Less[B] =
Inference(nc.lt(wa.snd, wb.snd), s"lessInference(${wa.snd}, ${wb.snd})")
Inference(nc.lteq(wa.snd, wb.snd), s"lessInference(${wa.snd}, ${wb.snd})")

implicit def lessInferenceNat[A <: Nat, B <: Nat](implicit
ta: ToInt[A],
tb: ToInt[B]
): Less[A] ==> Less[B] =
Inference(ta() < tb(), s"lessInferenceNat(${ta()}, ${tb()})")
Inference(ta() <= tb(), s"lessInferenceNat(${ta()}, ${tb()})")

implicit def greaterInference[C, A, B](implicit
wa: WitnessAs[A, C],
wb: WitnessAs[B, C],
nc: Numeric[C]
): Greater[A] ==> Greater[B] =
Inference(nc.gt(wa.snd, wb.snd), s"greaterInference(${wa.snd}, ${wb.snd})")
Inference(nc.gteq(wa.snd, wb.snd), s"greaterInference(${wa.snd}, ${wb.snd})")

implicit def greaterInferenceNat[A <: Nat, B <: Nat](implicit
ta: ToInt[A],
tb: ToInt[B]
): Greater[A] ==> Greater[B] =
Inference(ta() > tb(), s"greaterInferenceNat(${ta()}, ${tb()})")
Inference(ta() >= tb(), s"greaterInferenceNat(${ta()}, ${tb()})")

implicit def greaterEqualInference[A]: Greater[A] ==> GreaterEqual[A] =
Inference.alwaysValid("greaterEqualInference")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package eu.timepit.refined

import eu.timepit.refined.api.Inference
import eu.timepit.refined.boolean._
import eu.timepit.refined.boolean.And
import eu.timepit.refined.numeric._
import org.scalacheck.Prop._
import org.scalacheck.Properties

class NumericInferenceSpec extends Properties("NumericInference") {

property("Less[5] ==> Less[5]") = secure {
Inference[Less[W.`5`.T], Less[W.`5`.T]].isValid
}

property("Less[5] ==> Less[10]") = secure {
Inference[Less[W.`5`.T], Less[W.`10`.T]].isValid
}
Expand Down Expand Up @@ -36,6 +40,10 @@ class NumericInferenceSpec extends Properties("NumericInference") {
Inference[LessEqual[W.`7.5`.T], LessEqual[W.`7.2`.T]].notValid
}

property("Greater[5.0] ==> Greater[5.0]") = secure {
Inference[Greater[W.`5.0`.T], Greater[W.`5.0`.T]].isValid
}

property("Greater[10] ==> Greater[5]") = secure {
Inference[Greater[W.`10`.T], Greater[W.`5`.T]].isValid
}
Expand Down Expand Up @@ -75,4 +83,8 @@ class NumericInferenceSpec extends Properties("NumericInference") {
property("Interval.Closed[5, 10] ==> LessEqual[11]") = secure {
Inference[Interval.Closed[W.`5`.T, W.`10`.T], LessEqual[W.`11`.T]].isValid
}

property("Positive And Less[10] ==> Positive") = secure {
Inference[Positive And Less[W.`10`.T], Positive].isValid
}
}