• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

msakai / toysolver / 519

24 Nov 2024 04:19PM UTC coverage: 68.689% (-1.1%) from 69.746%
519

push

github

web-flow
Merge f8abb9f5d into 38bf6d362

0 of 183 new or added lines in 10 files covered. (0.0%)

114 existing lines in 13 files now uncovered.

9793 of 14257 relevant lines covered (68.69%)

0.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ToySolver/SAT/Internal/JSON.hs
1
{-# OPTIONS_GHC -Wall #-}
2
{-# OPTIONS_HADDOCK show-extensions #-}
3
{-# LANGUAGE OverloadedStrings #-}
4
module ToySolver.SAT.Internal.JSON where
5

6
import qualified Data.Aeson as J
7
import Data.Aeson ((.=))
8
import Data.String
9
import qualified Data.Vector as V
10

11
import qualified Data.PseudoBoolean as PBFile
12
import qualified ToySolver.SAT.Types as SAT
13

14
jVar :: SAT.Var -> J.Value
NEW
15
jVar v = J.object
×
NEW
16
  [ "type" .= J.String "variable"
×
NEW
17
  , "name" .= (fromString ("x" <> show v) :: J.Value)
×
18
  ]
19

20
jNot :: J.Value -> J.Value
NEW
21
jNot x = J.object
×
NEW
22
  [ "type" .= J.String "operator"
×
NEW
23
  , "name" .= J.String "not"
×
NEW
24
  , "operands" .= J.Array (V.singleton x)
×
25
  ]
26

27
jLit :: SAT.Lit -> J.Value
NEW
28
jLit l
×
NEW
29
  | l > 0 = jVar l
×
NEW
30
  | otherwise = jNot $ jVar (- l)
×
31

32
jConst :: J.ToJSON a => a -> J.Value
NEW
33
jConst x = J.object ["type" .= J.String "constant", "value" .= x]
×
34

35
jPBSum :: SAT.PBSum -> J.Value
NEW
36
jPBSum s = J.object
×
NEW
37
  [ "type" .= J.String "operator"
×
NEW
38
  , "name" .= J.String "+"
×
NEW
39
  , "operands" .=
×
NEW
40
      [ J.object
×
NEW
41
          [ "type" .= J.String "operator"
×
NEW
42
          , "name" .= J.String "*"
×
NEW
43
          , "operands" .= (jConst c : [jLit lit | lit <- lits])
×
44
          ]
NEW
45
      | (c, lits) <- s
×
46
      ]
47
  ]
48

49
jPBConstraint :: PBFile.Constraint -> J.Value
NEW
50
jPBConstraint (lhs, op, rhs) =
×
NEW
51
  J.object
×
NEW
52
  [ "type" .= J.String "operator"
×
NEW
53
  , "name" .= J.String (case op of{ PBFile.Ge -> ">="; PBFile.Eq -> "=" })
×
NEW
54
  , "operands" .= [jPBSum lhs, jConst rhs]
×
55
  ]
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc