Skip to content

Commit

Permalink
refactor(ldfi2): move makeFaults from tests to ldfi module
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Feb 16, 2021
1 parent e547ed6 commit 87411ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
16 changes: 13 additions & 3 deletions src/ldfi2/src/Ldfi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

module Ldfi where

import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import qualified GHC.Natural as Nat
import Text.Read (readMaybe)

import Ldfi.FailureSpec
import Ldfi.Prop
Expand Down Expand Up @@ -38,9 +40,6 @@ lineage ts =
, j <- drop len vs
]

data Fault = Crash Node Time | Omission Edge Time
deriving (Eq, Ord, Read, Show)

affects :: Fault -> Event -> Bool
affects (Omission (f, t) a) (Event f' t' a') = f == f' && t == t' && a == a'
affects (Crash n a) (Event _ n' a') = n == n' && a <= a'
Expand Down Expand Up @@ -107,3 +106,14 @@ run :: Monad m => Storage m -> Solver m -> TestId -> FailureSpec -> m Solution
run Storage{load} Solver{solve} testId failureSpec = do
traces <- load testId
solve (ldfi failureSpec traces)

data Fault = Crash Node Time | Omission Edge Time
deriving (Eq, Ord, Read, Show)

makeFaults :: Solution -> [Fault]
makeFaults NoSolution = []
makeFaults (Solution assign) =
[ f
| (key, True) <- Map.toAscList assign
, Just (FaultVar f) <- pure $ readMaybe key
]
11 changes: 0 additions & 11 deletions src/ldfi2/test/LdfiTest.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module LdfiTest where

import qualified Data.Map as Map
import Test.HUnit hiding (Node)
import qualified Test.QuickCheck as QC
import Text.Read (readMaybe)

import Ldfi
import Ldfi.FailureSpec
Expand Down Expand Up @@ -83,15 +81,6 @@ unit_cache_lineage =
(var "A" "B" 0 :&& (var "A" "C" 1 :|| And [var "A" "R" 1, var "R" "S1" 2, var "R" "S2" 3]))
where

-- This should move out of the tests..
makeFaults :: Solution -> [Fault]
makeFaults NoSolution = []
makeFaults (Solution assign) =
[ f
| (key, True) <- Map.toAscList assign
, Just (FaultVar f) <- pure $ readMaybe key
]

dummyTestId :: TestId
dummyTestId = error "This testId will never be used."

Expand Down

0 comments on commit 87411ae

Please sign in to comment.