-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Revision history for haskell-fluids-test | ||
|
||
## 0.1.0.0 -- YYYY-mm-dd | ||
|
||
* First version. Released on an unsuspecting world. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |