adding basic mathemtaica setup

This commit is contained in:
2021-01-04 13:15:34 -06:00
commit 4f9d04c988
6 changed files with 119 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto

19
.gitignore vendored Normal file
View File

@@ -0,0 +1,19 @@
.idea
dist
*.aux
*.fdb_latexmk
*.fls
*.tdo
*.toc
*.log
*.pdf
*.jpg
*.bbl
*.bcf
*.blg
*.run.xml
*.csv
*.out
*.nb

30
do.sh Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env sh
# Do - The Simplest Build Tool on Earth.
# Documentation and examples see https://github.com/8gears/do
# shellcheck disable=SC2039
set -Eeuo pipefail # -e "Automatic exit from bash shell script on error" -u "Treat unset variables and parameters as errors"
install() {
# shellcheck disable=SC2039
local install_loc
# shellcheck disable=SC2016
install_loc=$(wolframscript -c 'FileNameJoin[{StringReplace[$UserBaseDirectory, "\\" -> "/"], "Applications", "owenScalapinoFreeEnergy"}, OperatingSystem -> "Unix"]' | tr -d '\r\n')
echo "Installing to [$install_loc]"
mkdir -p "$install_loc"
echo $install_loc | hexdump
cp src/wl/owenScalapinoFreeEnergy.wl "$install_loc"
}
all() {
install
}
test() {
echo "I am ${FUNCNAME[0]}ing"
wolframscript -f src/wltest/RunTests.wls
}
"$@" # <- execute the task
[ "$#" -gt 0 ] || printf "Usage:\n\t./do.sh %s\n" "($(compgen -A function | grep '^[^_]' | paste -sd '|' -))"

View File

@@ -0,0 +1,12 @@
BeginPackage["owenScalapinoFreeEnergy`"];
(* Exported symbols added here with SymbolName::usage *)
fs::usage = "thing";
Begin["`Private`"];
fs[x_] := x^2;
End[]; (* `Private` *)
EndPackage[];

10
src/wltest/BasicTest.wlt Normal file
View File

@@ -0,0 +1,10 @@
BeginTestSection["BasicTest.wlt"];
VerificationTest[(* 1 *)
fs[3]
,
9
, TestID -> "Basic test."
];
EndTestSection[];

47
src/wltest/RunTests.wls Normal file
View File

@@ -0,0 +1,47 @@
(* Quick hacky driver script to get tests to run. *)
(* Stolen from: https://mathematica.stackexchange.com/questions/206278/how-to-set-a-tolerance-level-for-equality-constraints *)
approxTolerance = .001;
approxEqual[a_, b_] := Chop[N@(Abs[a - b]/Min[a, b]), approxTolerance] == 0;
PrependTo[$Path, FileNameJoin[{FileNameDrop[ExpandFileName[First[$ScriptCommandLine]],-2], "wl"}]];
testDir = FileNameDrop[ExpandFileName[First[$ScriptCommandLine]],-1];
testFiles = FileNames["*.wlt", testDir];
(*testFiles = FileNames["Example.wlt", testDir];*)
<< "owenScalapinoFreeEnergy`";
reports = TestReport /@ testFiles;
numTestsSucceeded = Total[#["TestsSucceededCount"] & /@ reports];
numTestsFailed = Total[#["TestsFailedCount"]& /@ reports];
numTests = numTestsSucceeded + numTestsFailed;
failedTestText[test_] := ToString@test["TestID"] <> "\nOutcome: " <> ToString@test["Outcome"] <> "\n" <> Switch[test["Outcome"],
"Failure",
"\tExpected:\n\t\t" <> ToString[test["ExpectedOutput"], InputForm] <> "\n\tActual:\n\t\t" <> ToString[test["ActualOutput"], InputForm],
"MessagesFailure",
"\tExpected Messages:\n\t\t" <> TextString[test["ExpectedMessages"]] <> "\n\tActual\n\t\t" <> TextString[test["ActualMessages"]],
"Success",
"All good champ",
"Error",
ToString@test,
_,
"Can't report on this error type, for some reason."
];
failedReportText[report_] := StringTrim[report["Title"], "Test Report: "] <> " failures:\n---------------\n" <> StringRiffle[failedTestText /@ Select[Values[report["TestResults"]], #["Outcome"] != "Success" &], "\n"];
If[0 < numTestsFailed,
failedReports = Select[reports, #["TestsFailedCount"] >0 &];
Print[StringRiffle[failedReportText /@ failedReports, {"************************\n\n", "\n\n", "\n\n************************"}]];
Print[""];
];
time = QuantityMagnitude[Total[(#["TimeElapsed"] & /@ reports)], "Seconds"];
Print[ToString@StringForm["Tests took `` seconds.", time]];
Print[ToString@StringForm["Succeeded: `` out of ``", numTestsSucceeded, numTests]];
Print[ToString@StringForm["Failed: `` out of ``", numTestsFailed, numTests]];
If[0 == numTestsFailed,
Print["\nPhew..."];
];