Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and lint sample tasks #15

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions flex-task/src/FlexTask/DefaultConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,20 @@ Apply 'getFormData' to your finished form to obtain the data for the generator.
module TaskData (getTask) where


import Data.Text (Text)
import FlexTask.FormUtil (getFormData)
import FlexTask.Generic.Form
import FlexTask.YesodConfig (Rendered)
import GHC.Generics (Generic)
import Data.String.Interpolate (i)
import Test.QuickCheck.Gen

import qualified Data.Text as T

import Global




genNumbers = vectorOf 3 $ elements ([1..6] :: [Int])


getTask :: Gen (String, String, IO ([String],String))
getTask = do
numbers <- genNumbers
numbers <- vectorOf 3 $ elements [1..6 :: Int]
let
descData = (numbers !! 0, numbers !! 1, numbers !! 2)
checkData = (product numbers, sum numbers)
Expand Down Expand Up @@ -300,18 +293,13 @@ It only takes your parser as an argument.
module Parse (parseSubmission) where


import Data.Text (Text)
import FlexTask.Generic.Parse (parseInput, useParser)
import GHC.Generics (Generic)
import Text.Parsec (ParseError, parse)

import qualified Data.Text as T
import Text.Parsec (ParseError)

import Global




parseSubmission :: String -> Either ParseError Solution
parseSubmission = useParser parseInput

Expand Down
9 changes: 5 additions & 4 deletions tasks/composeFormula.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Data.String.Interpolate (i)
import FlexTask.FormUtil (getFormData)
import FlexTask.Generic.Form
import FlexTask.YesodConfig (Rendered)
import Tasks.ComposeFormula.Config (ComposeFormulaInst, defaultComposeFormulaConfig)
import Tasks.ComposeFormula.Config (defaultComposeFormulaConfig)
import Tasks.ComposeFormula.Quiz (generateComposeFormulaInst)
import Test.QuickCheck.Gen (Gen)

Expand Down Expand Up @@ -48,12 +48,13 @@ checkers = [i|
module Check where


import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.IO.Class (MonadIO)
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (
GenericOutput
)
import Data.Ratio
import Data.Functor (($>))
import Formula.Parsing.Delayed (delayed)
import LogicTasks.Syntax.ComposeFormula (partialGrade, completeGrade)
import Tasks.ComposeFormula.Config (ComposeFormulaInst(..))
Expand Down Expand Up @@ -82,7 +83,7 @@ checkSemantics
-> FilePath
-> Solution
-> Rated m
checkSemantics inst path try = completeGrade path inst (delayed $ toListString try) *> pure 1.0
checkSemantics inst path try = completeGrade path inst (delayed $ toListString try) $> 1.0

|]

Expand All @@ -102,7 +103,7 @@ import qualified LogicTasks.Syntax.ComposeFormula as LT


description :: (OutputCapable m, MonadIO m) => FilePath -> ComposeFormulaInst -> LangM m
description path inst = LT.description (path <> "/") inst
description path = LT.description (path <> "/")

=============================================

Expand Down
14 changes: 3 additions & 11 deletions tasks/interpolation-test/slowTaskInterpolation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ checkers solution = [i|
module Check (checkSemantics, checkSyntax) where


import Control.Monad (when, unless)
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (
GenericOutput,
Expand Down Expand Up @@ -79,9 +78,9 @@ checkSemantics _ _ (a,b) = do
|]
where
neighbourTups = zip3 solution (drop 1 solution) (drop 2 solution)
fromNeighbourTups f = map (\(a,b,c) -> b) $ filter f $ neighbourTups
noNegNeighbours = fromNeighbourTups (\(a,b,c) -> a >= 0 || c >= 0)
noDiv3Neighbours = fromNeighbourTups (\(a,b,c) -> a `mod` 3 /= 0 || c `mod` 3 /= 0)
fromNeighbourTups f = map (\(_,b,_) -> b) $ filter f neighbourTups
noNegNeighbours = fromNeighbourTups (\(a,_,c) -> a >= 0 || c >= 0)
noDiv3Neighbours = fromNeighbourTups (\(a,_,c) -> a `mod` 3 /= 0 || c `mod` 3 /= 0)

=============================================

Expand All @@ -93,8 +92,6 @@ module Description (description) where
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (GenericOutput)

import Global



description :: OutputCapable m => FilePath -> [Int] -> LangM m
Expand Down Expand Up @@ -124,14 +121,9 @@ description _ input = do
module Parse (parseSubmission) where


import Data.String.Interpolate (i)
import Data.Text (Text)
import FlexTask.Generic.Parse (parseInput, useParser)
import GHC.Generics (Generic)
import Text.Parsec (ParseError)

import qualified Data.Text as T

import Global


Expand Down
7 changes: 3 additions & 4 deletions tasks/interpolation-test/slowTaskNoInterpolation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ checkers = [i|
module Check (checkSemantics, checkSyntax) where


import Control.Monad (when, unless)
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (
GenericOutput,
Expand Down Expand Up @@ -38,8 +37,8 @@ checkSemantics sol _ (a,b) = do
pure 1.0
where
neighbourTups = zip3 sol (drop 1 sol) (drop 2 sol)
fromNeighbourTups f = map (\\(a,b,c) -> b) $ filter f $ neighbourTups
noNegNeighbours = fromNeighbourTups (\\(a,b,c) -> a >= 0 || c >= 0)
noDiv3Neighbours = fromNeighbourTups (\\(a,b,c) -> a `mod` 3 /= 0 || c `mod` 3 /= 0)
fromNeighbourTups f = map (\\(_,b,_) -> b) $ filter f neighbourTups
noNegNeighbours = fromNeighbourTups (\\(a,_,c) -> a >= 0 || c >= 0)
noDiv3Neighbours = fromNeighbourTups (\\(a,_,c) -> a `mod` 3 /= 0 || c `mod` 3 /= 0)

|]
6 changes: 0 additions & 6 deletions tasks/interpolation-test/treeInterpolation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ checkers solution = [i|
module Check (checkSemantics, checkSyntax) where


import Control.Monad (when, unless)
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (
GenericOutput
Expand Down Expand Up @@ -130,14 +129,9 @@ description _ input = do
module Parse (parseSubmission) where


import Data.String.Interpolate (i)
import Data.Text (Text)
import FlexTask.Generic.Parse (parseInput, useParser)
import GHC.Generics (Generic)
import Text.Parsec (ParseError)

import qualified Data.Text as T

import Global


Expand Down
1 change: 0 additions & 1 deletion tasks/interpolation-test/treeNoInterpolation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ checkers = [i|
module Check (checkSemantics, checkSyntax) where


import Control.Monad (when, unless)
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (
GenericOutput
Expand Down
43 changes: 14 additions & 29 deletions tasks/proplogic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Data.List.Split (chunksOf)
import Data.Maybe (fromJust)
import Data.Text (Text)
import Data.String.Interpolate (i)
import FlexTask.FormUtil (($$>), addCss, getFormData, newFlexId, newFlexName)
import FlexTask.FormUtil (($$>), addCss, getFormData)
import FlexTask.Generic.Form (
Alignment(..),
FieldInfo,
Expand Down Expand Up @@ -69,13 +69,13 @@ getParticipants = vectorOf 4 arbitrary `suchThat` or

getTask :: Gen (String, String, IO ([String],String))
getTask = do
values@[a,b,c,d] <- getParticipants
[a,b,c,d] <- getParticipants
names <- getNames
(formula, legend, hints) <- formulaAndHints a b c d names
let
zipped = [(a, A), (b, B), (c, C), (d, D)]
coming = [ n | (True,n) <- zipped ]
pure (show ((legend,hints),coming), checkers formula startingTable False True, getFormData (form names))
pure (show ((legend,hints),coming), checkers formula False True, getFormData (form names))
where
form :: (Text,Text,Text,Text) -> Rendered
form n = tableForm ["A","B","C","D"] 16 7 $$> formify (Nothing :: Maybe FormType) (nonTableFields n)
Expand Down Expand Up @@ -123,7 +123,7 @@ formulaAndHints a b c d (aN,bN,cN,dN) = do
auch :: String
auch = " auch"

neg b x = if b then Neg (Atomic x) else Atomic x
neg expr x = if expr then Neg (Atomic x) else Atomic x
part1 = Assoc Impl
(Brackets $ Assoc And (neg b 'B') (neg d 'D'))
(neg (not c) 'C')
Expand Down Expand Up @@ -198,30 +198,28 @@ deriving instance Data (PropFormula Char)

startingTable :: [[Maybe Binary]]
startingTable = map (Just . Binary . toEnum . digitToInt) <$>
transpose (pad . (`showBin` "") <$> [0..15])
transpose (pad . (`showBin` "") <$> [0..15 :: Int])
where pad s = replicate (4 - length s) '0' ++ s



checkers :: PropFormula Char -> [[Maybe Binary]] -> Bool -> Bool -> String
checkers fSol startingTable tableRequired showSolution = [i|
checkers :: PropFormula Char -> Bool -> Bool -> String
checkers fSol tableRequired showSolution = [i|

{-\# language ApplicativeDo \#-}
{-\# language OverloadedStrings \#-}

module Check (checkSemantics, checkSyntax) where


import Control.Monad (when, unless)
import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (
GenericOutput(..)
)
import Data.Foldable (toList)
import Data.Functor (($>))
import Data.List (isInfixOf, transpose)
import Data.Maybe (catMaybes, fromJust, isJust)
import Data.Map ((!), fromList)
import Data.List (isInfixOf)
import Data.Maybe (catMaybes, fromJust)
import Data.Map (fromList)
import Data.Ratio (Ratio, (%))
import Data.Tuple (swap)

Expand Down Expand Up @@ -272,7 +270,7 @@ instance ToSAT (PropFormula Char) where


checkSyntax :: OutputCapable m => a -> FilePath -> Submission -> LangM m
checkSyntax _ _ (Table xs,f,n) = do
checkSyntax _ _ (Table xs,_,n) = do
assertion (all (`notElem` map (Just . Atomic) "ABCD") nonStaticHeaders) $ translate $
german "Tabellenspalten existieren nur einmal?."
assertion (not (null n)) $ translate $
Expand All @@ -291,18 +289,18 @@ checkSemantics (_,nSol) _ (Table xs,f,n) = do
let subFormulas = all (`isSubFormula` f) $ catMaybes nonStaticHeaders
#{checkType} subFormulas $ translate $
german "Tabellenspalten sind Teilformeln der Gesamtformel?"
let correctValues = all correctColumn [(f,b)| (Just f,b) <- drop 4 xs]
let correctValues = all correctColumn [(sf,b)| (Just sf,b) <- drop 4 xs]
#{checkType} correctValues $ translate $
german "Tabellenspalten enthalten korrekte Warheitswerte?"
yesNo (T.all (`elem` f) "ABCD") $ translate $
german "Formel enthält alle vorkommenden Literale?"
let correctFormula = isSemanticEqual (#{gshow fSol}) f
let correctFormula = isSemanticEqual #{gshow fSol} f
yesNo correctFormula $ translate $
german "Die aussagenlogische Formel ist korrekt?"
let correctNames = n == nSol
yesNo correctNames $ translate $
german "Die Liste der Teilnehmer ist korrekt?"
let correct = filter (==True) [correctStart, correctFormula, correctNames, correctValues]
let correct = filter id [correctStart, correctFormula, correctNames, correctValues]
let points = fromIntegral (length correct) % 4
res <- printSolutionAndAssert IndefiniteArticle maybeAnswer points
pure res
Expand All @@ -329,12 +327,10 @@ module Description (description) where

import Control.OutputCapable.Blocks
import Control.OutputCapable.Blocks.Generic.Type (GenericOutput)
import Data.String.Interpolate (i)

import Global



description :: OutputCapable m => FilePath -> ((String,[String]),a) -> LangM m
description _ ((legend,hints),_) = do
paragraph $ translate $ german
Expand All @@ -358,9 +354,6 @@ description _ ((legend,hints),_) = do
module Parse (parseSubmission) where


import Data.Char (showLitChar)
import Data.String.Interpolate (i)
import Data.Text (Text)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import FlexTask.Generic.Parse (
Expand All @@ -372,19 +365,11 @@ import FlexTask.Generic.Parse (
import Text.Parsec (
(<|>),
ParseError,
choice,
many1,
parse,
string,
try
)
import Text.Parsec.Char (char, oneOf)
import Text.Parsec.String (Parser)

import Trees.Types (PropFormula(..))
import Trees.Parsing ()

import qualified Data.Text as T
import qualified Formula.Parsing as FP

import Global
Expand Down
Loading