diff --git a/dev/haskell-fluids-test/CHANGELOG.md b/dev/haskell-fluids-test/CHANGELOG.md new file mode 100644 index 0000000..4db2bf7 --- /dev/null +++ b/dev/haskell-fluids-test/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for haskell-fluids-test + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/dev/haskell-fluids-test/Main.hs b/dev/haskell-fluids-test/Main.hs new file mode 100644 index 0000000..5d3e94d --- /dev/null +++ b/dev/haskell-fluids-test/Main.hs @@ -0,0 +1,26 @@ +-- module Main where +-- +-- main :: IO () +-- main = putStrLn "Hello, Haskell!" +{-# LANGUAGE OverloadedStrings #-} + +module Main where + +import qualified CPython as Py +import qualified CPython.Simple as PySim + +main :: IO () +main = do + putStrLn "Testing fluids from Haskell..." + -- Initialize Python + Py.initialize + + -- Basic test + re <- PySim.call "fluids" "Reynolds" + [PySim.arg (2.5 :: Double), PySim.arg (0.1 :: Double), + PySim.arg (1000.0 :: Double), PySim.arg (0.001 :: Double)] [] + + putStrLn $ "Reynolds number calculation: " ++ show (re :: Double) + + -- Clean up + Py.finalize diff --git a/dev/haskell-fluids-test/app/Main.hs b/dev/haskell-fluids-test/app/Main.hs new file mode 100644 index 0000000..52b13c3 --- /dev/null +++ b/dev/haskell-fluids-test/app/Main.hs @@ -0,0 +1,75 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Main where + +import qualified CPython as Py +import qualified CPython.Simple as PySim +import Data.Time.Clock.System (getSystemTime, systemSeconds) +import Control.Exception (handle) +import qualified CPython.Types.Exception as PyExc +import Text.Printf (printf) +import Data.Text (Text) + +-- Helper function for timing +time :: IO a -> IO (Double, a) +time action = do + start <- getSystemTime + result <- action + end <- getSystemTime + let diff = fromIntegral (systemSeconds end - systemSeconds start) + return (diff, result) + +-- Basic fluids test +testFluids :: IO () +testFluids = do + putStrLn "Testing basic fluids functionality..." + + -- Test version + version <- (PySim.getAttribute "fluids" "__version__" :: IO Text) + putStrLn $ "✓ Fluids version: " ++ show version + + -- Test Reynolds number + re <- (PySim.call "fluids" "Reynolds" + [PySim.arg (2.5 :: Double), PySim.arg (0.1 :: Double), + PySim.arg (1000.0 :: Double), PySim.arg (0.001 :: Double)] [] :: IO Double) + putStrLn $ "✓ Reynolds number calculation: " ++ show re + + -- Test friction factor + fd <- (PySim.call "fluids" "friction_factor" + [PySim.arg (1e5 :: Double), PySim.arg (0.0001 :: Double)] [] :: IO Double) + putStrLn $ "✓ Friction factor calculation: " ++ show fd + + putStrLn "Basic tests completed successfully!\n" + + +-- Benchmark fluids functions +benchmarkFluids :: IO () +benchmarkFluids = do + putStrLn "Running benchmarks..." + + -- Benchmark friction factor + putStrLn "\nBenchmarking friction_factor:" + (t1, _) <- time $ do + sequence $ replicate 1000 $ + (PySim.call "fluids" "friction_factor" + [PySim.arg (1e5 :: Double), PySim.arg (0.0001 :: Double)] [] :: IO Double) + putStrLn $ printf "Time for 1000 friction_factor calls: %.6f seconds" t1 + putStrLn $ printf "Average time per call: %.6f seconds" (t1 / 1000) + +-- Main function to run all tests +main :: IO () +main = handle pyExceptionHandler $ do + putStrLn "Running fluids tests from Haskell..." + Py.initialize + + testFluids + benchmarkFluids + + Py.finalize + putStrLn "All tests completed!" + where + pyExceptionHandler :: PyExc.Exception -> IO () + pyExceptionHandler e = do + putStrLn $ "Python error occurred: " ++ show e + Py.finalize diff --git a/dev/haskell-fluids-test/haskell-fluids-test.cabal b/dev/haskell-fluids-test/haskell-fluids-test.cabal new file mode 100644 index 0000000..284f07d --- /dev/null +++ b/dev/haskell-fluids-test/haskell-fluids-test.cabal @@ -0,0 +1,31 @@ +cabal-version: 2.4 +name: haskell-fluids-test +version: 0.1.0.0 + +-- A short (one-line) description of the package. +-- synopsis: + +-- A longer description of the package. +-- description: + +-- A URL where users can report bugs. +-- bug-reports: + +-- The license under which the package is released. +-- license: +author: Caleb Bell +maintainer: Caleb.Andrew.Bell@gmail.com + +-- A copyright notice. +-- copyright: +-- category: +extra-source-files: CHANGELOG.md + +executable haskell-fluids-test + main-is: Main.hs + build-depends: base ^>=4.15.1.0, + cpython, + time, + text + hs-source-dirs: app + default-language: Haskell2010