reorganized and started working on unit tests

This commit is contained in:
William Ball 2024-11-12 11:32:05 -08:00
parent aa05f3025e
commit f9e70ca131
8 changed files with 98 additions and 48 deletions

View file

@ -1,22 +1,6 @@
cabal-version: 3.0 cabal-version: 3.0
-- 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.
-- Initial package description 'dependent-lambda' generated by
-- 'cabal init'. For further documentation, see:
-- http://haskell.org/cabal/users-guide/
--
-- The name of the package.
name: dependent-lambda name: dependent-lambda
-- The package version.
-- See the Haskell package versioning policy (PVP) for standards
-- guiding when and how versions should be incremented.
-- https://pvp.haskell.org
-- PVP summary: +-+------- breaking API changes -- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions -- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change -- | | | +--- code changes with no API change
@ -28,56 +12,54 @@ version: 0.1.0.0
-- A longer description of the package. -- A longer description of the package.
-- description: -- description:
-- The license under which the package is released.
license: GPL-3.0-or-later license: GPL-3.0-or-later
-- The file containing the license text.
license-file: LICENSE license-file: LICENSE
-- The package author(s).
author: William Ball author: William Ball
-- An email address to which users can send suggestions, bug reports, and patches.
maintainer: williampi103@gmail.com maintainer: williampi103@gmail.com
-- A copyright notice.
-- copyright:
category: Math category: Math
build-type: Simple build-type: Simple
-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README.
extra-doc-files: CHANGELOG.md extra-doc-files: CHANGELOG.md
, README.md
-- Extra source files to be distributed with the package, such as examples, or a tutorial module. -- Extra source files to be distributed with the package, such as examples, or a tutorial module.
-- extra-source-files: -- extra-source-files:
common warnings library dependent-lambda-lib
ghc-options: -Wall exposed-modules: Check
executable dependent-lambda
-- 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: Expr
Check
Parser Parser
Expr
-- LANGUAGE extensions used by modules in this package. hs-source-dirs: lib
-- other-extensions:
-- Other library packages from which modules are imported.
build-depends: base ^>=4.19.1.0 build-depends: base ^>=4.19.1.0
, megaparsec , megaparsec
, text , text
, parser-combinators , parser-combinators
, mtl , mtl
default-language: Haskell2010
-- Directories containing source files.
hs-source-dirs: app common warnings
ghc-options: -Wall
-- Base language which the package is written in.
executable dependent-lambda
import: warnings
main-is: Main.hs
build-depends: base ^>=4.19.1.0
, dependent-lambda-lib
hs-source-dirs: app
default-language: Haskell2010
test-suite tests
type: exitcode-stdio-1.0
main-is: Tests.hs
other-modules: ExprTests
, ParserTests
, CheckTests
build-depends: base ^>=4.19.1.0
, HUnit
, dependent-lambda-lib
hs-source-dirs: tests
default-language: Haskell2010 default-language: Haskell2010

View file

@ -118,7 +118,8 @@ incIndices = shiftIndices 1 0
subst :: Integer -> Expr -> Expr -> Expr subst :: Integer -> Expr -> Expr -> Expr
subst k s (Var n x) subst k s (Var n x)
| k == n = s | k == n = s
| otherwise = Var (n - 1) x | n > k = Var (n - 1) x
| otherwise = Var n x
subst _ _ Star = Star subst _ _ Star = Star
subst _ _ Square = Square subst _ _ Square = Square
subst k s (App m n) = App (subst k s m) (subst k s n) subst k s (App m n) = App (subst k s m) (subst k s n)

1
tests/CheckTests.hs Normal file
View file

@ -0,0 +1 @@
module CheckTests where

52
tests/ExprTests.hs Normal file
View file

@ -0,0 +1,52 @@
module ExprTests where
import Expr
import Test.HUnit
inner :: Expr
inner = Abs "x" (Var 0 "A") $ Var 2 "f" <.> Var 0 "x"
e1 :: Expr
e1 = Abs "A" Star inner
fFree :: Test
fFree = TestCase $ assertBool "f free" $ occursFree 0 e1
incE1 :: Test
incE1 =
TestCase $
assertEqual
"incIndices e1"
( Abs "A" Star $
Abs "x" (Var 0 "A") $
Var 3 "f" <.> Var 0 "x"
)
(incIndices e1)
after :: Expr
after = Abs "x" (Var 2 "B") $ Var 1 "f" <.> Var 0 "x"
substE1 :: Test
substE1 =
TestCase $
assertEqual
"e1[A := B]"
after
(subst 0 (Var 2 "B") inner)
betaNFe1 :: Test
betaNFe1 =
TestCase $
assertEqual
"e1 B"
after
(betaNF $ e1 <.> Var 2 "B")
tests :: Test
tests =
TestList
[ TestLabel "fFree" fFree
, TestLabel "incE1" incE1
, TestLabel "substE1" substE1
, TestLabel "betaNFe1" betaNFe1
]

1
tests/ParserTests.hs Normal file
View file

@ -0,0 +1 @@
module ParserTests where

13
tests/Tests.hs Normal file
View file

@ -0,0 +1,13 @@
module Main where
import qualified ExprTests as E
import qualified System.Exit as Exit
import Test.HUnit
tests :: Test
tests = TestList [TestLabel "ExprTests" E.tests]
main :: IO ()
main = do
result <- runTestTT tests
if failures result > 0 then Exit.exitFailure else Exit.exitSuccess