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

msakai / toysolver / 513

24 Nov 2024 08:49AM UTC coverage: 68.675% (-1.0%) from 69.681%
513

push

github

web-flow
Merge 496ed4263 into 46e1509c4

5 of 121 new or added lines in 7 files covered. (4.13%)

105 existing lines in 14 files now uncovered.

9745 of 14190 relevant lines covered (68.68%)

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" .= J.toJSONList
×
NEW
40
      [ J.object
×
NEW
41
          [ "type" .= J.String "operator"
×
NEW
42
          , "name" .= J.String "*"
×
NEW
43
          , "operands" .=
×
NEW
44
               J.toJSONList (jConst c : [jLit lit | lit <- lits])
×
45
          ]
NEW
46
      | (c, lits) <- s
×
47
      ]
48
  ]
49

50
jPBConstraint :: PBFile.Constraint -> J.Value
NEW
51
jPBConstraint (lhs, op, rhs) =
×
NEW
52
  J.object
×
NEW
53
  [ "type" .= J.String "operator"
×
NEW
54
  , "name" .= J.String (case op of{ PBFile.Ge -> ">="; PBFile.Eq -> "=" })
×
NEW
55
  , "operands" .= J.toJSONList [jPBSum lhs, jConst rhs]
×
56
  ]
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

© 2025 Coveralls, Inc