From cef2dc79a7a6d079db70b33d2f7602f107c24f94 Mon Sep 17 00:00:00 2001 From: Taylor Date: Thu, 16 Jan 2025 13:14:14 -0600 Subject: [PATCH] cabal co-exists beside Makefile --- HushGP.cabal | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ app/.ghci | 3 ++ app/Main.hs | 5 +++ test/.ghci | 3 ++ test/Main.hs | 26 +++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 HushGP.cabal create mode 100644 app/.ghci create mode 100644 app/Main.hs create mode 100644 test/.ghci create mode 100644 test/Main.hs diff --git a/HushGP.cabal b/HushGP.cabal new file mode 100644 index 0000000..717043a --- /dev/null +++ b/HushGP.cabal @@ -0,0 +1,105 @@ +cabal-version: 3.4 +-- The cabal-version field refers to the version of the .cabal specification, +-- and can be different from the cabal-install (the tool) version and the +-- Cabal (the library) version you are using. As such, the Cabal (the library) +-- version used must be equal or greater than the version stated in this field. +-- Starting from the specification version 2.2, the cabal-version field must be +-- the first thing in the cabal file. + +-- The name of the package. +name: HushGP + +-- The package version. +-- PVP summary: +-+------- breaking API changes +-- | | +----- non-breaking API additions +-- | | | +--- code changes with no API change +version: 0.1.0.0 + +-- A short (one-line) description of the package. +synopsis: A PushGP implementation in Haskell. + +-- The package author(s). +author: Taylor + +-- An email address to which users can send suggestions, bug reports, and patches. +maintainer: behindthebrain@zoho.eu + +category: Data +build-type: Simple + +common warnings + ghc-options: -Wall + +library + -- Import common warning flags. + import: warnings + + -- Modules exported by the library. + exposed-modules: Push, GP + + -- Modules included in this library but not exported. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- Other library packages from which modules are imported. + build-depends: + base ^>=4.18.2.1, containers + + -- Directories containing source files. + hs-source-dirs: src + + -- Base language which the package is written in. + default-language: GHC2021 + +executable HushGP + -- Import common warning flags. + import: warnings + + -- .hs or .lhs file containing the Main module. + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- Other library packages from which modules are imported. + build-depends: + base ^>=4.18.2.1, + HushGP + + -- Directories containing source files. + hs-source-dirs: app + + -- Base language which the package is written in. + default-language: GHC2021 + +test-suite HushGP-test + -- Import common warning flags. + import: warnings + + -- Base language which the package is written in. + default-language: GHC2021 + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- The interface type and version of the test suite. + type: exitcode-stdio-1.0 + + -- Directories containing source files. + hs-source-dirs: test + + -- The entrypoint to the test suite. + main-is: Main.hs + + -- Test dependencies. + build-depends: + base ^>=4.18.2.1, + HushGP diff --git a/app/.ghci b/app/.ghci new file mode 100644 index 0000000..478f0d4 --- /dev/null +++ b/app/.ghci @@ -0,0 +1,3 @@ +:set stop :list +:set prompt "\ESC[1;34m%s \ESC[0;35mλ>\ESC[m " +:load Main ../src/GP ../src/Push diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..56457c9 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,5 @@ +import GP +import Push + +main :: IO () +main = do pure () diff --git a/test/.ghci b/test/.ghci new file mode 100644 index 0000000..478f0d4 --- /dev/null +++ b/test/.ghci @@ -0,0 +1,3 @@ +:set stop :list +:set prompt "\ESC[1;34m%s \ESC[0;35mλ>\ESC[m " +:load Main ../src/GP ../src/Push diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..d101105 --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,26 @@ +import Control.Exception (assert) +import GP +import Push + +intTestFunc :: String -> [Int] -> [Gene] -> State -> IO () +intTestFunc name goal genome startState = + let state = loadProgram genome startState + in assert (goal == int (interpretExec state)) putStrLn (name ++ " passed test.") + +main :: IO () +main = do + intTestFunc "instructionIntAdd" [8] [GeneInt 6, GeneInt 2, StateFunc instructionIntAdd] emptyState + intTestFunc "instructionIntSub" [4] [GeneInt 6, GeneInt 2, StateFunc instructionIntSub] emptyState + intTestFunc "instructionIntMul" [12] [GeneInt 6, GeneInt 2, StateFunc instructionIntMul] emptyState + intTestFunc "instructionIntDiv" [3] [GeneInt 6, GeneInt 2, StateFunc instructionIntDiv] emptyState + intTestFunc "instructionExecIf" [6, 5] [GeneBool True, StateFunc instructionExecIf, Block [GeneInt 5, GeneInt 6], Block [GeneInt 7, GeneInt 8]] emptyState + intTestFunc "instructionExecDup" [8] [StateFunc instructionExecDup, GeneInt 4, StateFunc instructionIntAdd] emptyState + intTestFunc "instructionExecDoRange" [12] [GeneInt 2, Block [GeneInt 4, GeneInt 1, StateFunc instructionExecDoRange], StateFunc instructionIntAdd] emptyState + intTestFunc "instructionExecDoCount" [8] [GeneInt 2, Block [GeneInt 4, StateFunc instructionExecDoCount], StateFunc instructionIntAdd] emptyState + intTestFunc "instructionIntAdd" [69, 69, 69, 69, 2] [GeneInt 2, Block [GeneInt 4, StateFunc instructionExecDoTimes], GeneInt 69] emptyState + intTestFunc "instructionExecDoTimes" [70, 70] [GeneBool False, GeneBool True, GeneBool True, StateFunc instructionExecWhile, GeneInt 70] emptyState + intTestFunc "instructionExecWhile" [70, 70, 70] [GeneBool False, GeneBool True, GeneBool True, StateFunc instructionExecDoWhile, GeneInt 70] emptyState + intTestFunc "instructionExecDoWhile" [71] [GeneBool True, StateFunc instructionExecWhen, GeneInt 71] emptyState + + let loadedState = loadProgram [GeneBool False, StateFunc instructionExecWhen, GeneInt 71] emptyState + assert (emptyState == interpretExec loadedState) putStrLn "instructionExecWhen passed test."