-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Arb and Eq for ObservationValidation
- Loading branch information
1 parent
8263625
commit 66ec694
Showing
2 changed files
with
47 additions
and
1 deletion.
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
44 changes: 44 additions & 0 deletions
44
modules/testkit/src/main/scala/lucuma/core/model/arb/ArbObservationValidation.scala
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,44 @@ | ||
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
||
package lucuma.core.model | ||
package arb | ||
|
||
import cats.data.NonEmptyChain | ||
import lucuma.core.enums.ObservationValidationCode | ||
import lucuma.core.util.arb.ArbEnumerated | ||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Arbitrary.* | ||
import org.scalacheck.Cogen | ||
|
||
trait ArbObservationValidation { | ||
import ArbEnumerated.given | ||
|
||
given Arbitrary[NonEmptyChain[String]] = | ||
Arbitrary( | ||
for { | ||
s <- arbitrary[String] | ||
ss <- arbitrary[List[String]] | ||
} yield NonEmptyChain.of(s, ss*) | ||
) | ||
|
||
given Cogen[NonEmptyChain[String]] = | ||
Cogen[(String, List[String])].contramap { a => | ||
(a.head, a.tail.toList) | ||
} | ||
|
||
given Arbitrary[ObservationValidation] = | ||
Arbitrary { | ||
for { | ||
c <- arbitrary[ObservationValidationCode] | ||
m <- arbitrary[NonEmptyChain[String]] | ||
} yield ObservationValidation(c, m) | ||
} | ||
|
||
given Cogen[ObservationValidation] = | ||
Cogen[(ObservationValidationCode, NonEmptyChain[String])].contramap { ov => | ||
(ov.code, ov.messages) | ||
} | ||
} | ||
|
||
object ArbObservationValidation extends ArbObservationValidation |