-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix MatchError bug with sealed trait -> open trait refactor
- Loading branch information
Jeff May
committed
Oct 21, 2022
1 parent
42f8f1f
commit bd1a3c8
Showing
2 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.rallyhealth.vapors.v1 | ||
|
||
package data | ||
|
||
import munit.FunSuite | ||
import example.FactTypes | ||
|
||
import java.time.LocalDate | ||
|
||
class FactSpec extends FunSuite { | ||
|
||
test("Fact extractor matches CustomFact") { | ||
val f = CustomFact(FactTypes.Age, 23) | ||
f match { | ||
case Fact(tpe, value) => | ||
assert(tpe == f.typeInfo && value == f.value) | ||
} | ||
} | ||
|
||
test("DerivedFact extractor matches CustomDerivedFact") { | ||
val yearsAgo23 = FactTypes.DateOfBirth(LocalDate.now().minusYears(23).withDayOfYear(1)) | ||
val f = CustomDerivedFact(FactTypes.Age, 23, Evidence(yearsAgo23)) | ||
f match { | ||
case DerivedFact(tpe, value, evidence) => | ||
assert(tpe == f.typeInfo && value == f.value && evidence == f.evidence) | ||
case _ => | ||
fail(s"Expected $f to match a DerivedFact") | ||
} | ||
} | ||
} | ||
|
||
final case class CustomFact[T]( | ||
typeInfo: FactType[T], | ||
value: T, | ||
) extends Fact { | ||
override type Value = T | ||
} | ||
|
||
final case class CustomDerivedFact[T]( | ||
typeInfo: FactType[T], | ||
value: T, | ||
evidence: Evidence, | ||
) extends DerivedFact { | ||
override type Value = T | ||
} |