Semigroup Result instance?

Offen
#96 2 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

  • #101 von @np — ohne Merge geschlossen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
25/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Bereich
testing

Rechercherichtung

Read the proposed Semigroup and Monoid instances in the issue body and the linked pull request #101 for prior discussion. Decide whether combining Result values this way fits the library’s API and supports the shown QuickCheck use case; the issue does not name implementation files or tests, so locate the existing Result definitions and instances before judging completion.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

type: enhancement

How would we feel about the following?

instance semigroupResult :: Semigroup Result where
  Success <> r = r
  Failed str <> _ = Failed str

instance monoidResult :: Monoid Result where
  mempty = Success

This is a use case I have in mind

  log "fromRotationMatrix avoids instability issues when the quaternion has one very small component"
  quickCheck \(VerySmallNum e) a b c ->
    let
      testWith p' =
        let
          p = Rotation.fromQuaternion p'
          q = unsafePartial (Rotation.fromRotationMatrix (Rotation.toRotationMatrix p))
        in
          rApproxEq p q
          <?> show { p, q }
    in
      fold
       [ testWith (Quaternion e a b c)
       , testWith (Quaternion a e b c)
       , testWith (Quaternion a b e c)
       , testWith (Quaternion a b c e)
       ]

Of course I could rewrite this test to call quickCheck four times instead, but I think the instance makes sense, and I think it would be nice to allow writing tests this way. Additionally, if generating random values for a given type is expensive, being able to combine Result values in this way could let you cut down the number of random values you need to generate, since you don't need to call quickCheck as many times.

Vorherrschende Sprache
PureScript
Sterne
108
Forks
42
Ø Merge
2 T. 23 Std.
Gemergte PRs (30 T.)
1

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus purescript/purescript-quickcheck

Alle Issues in purescript/purescript-quickcheck

Ähnliche Issues

Weitere Issues zu Testing & QA

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.