diff --git a/VERSION.txt b/VERSION.txt index 1a02ab843..1dd01bf75 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.20260529.1 +0.20260604.0 diff --git a/src/api/libopencor/seduniformtimecourse.h b/src/api/libopencor/seduniformtimecourse.h index 69050bccc..047bb1b19 100644 --- a/src/api/libopencor/seduniformtimecourse.h +++ b/src/api/libopencor/seduniformtimecourse.h @@ -68,9 +68,6 @@ class LIBOPENCOR_EXPORT SedUniformTimeCourse: public SedSimulation * Return the initial time used by this simulation. * * @return The initial time used by this simulation. - * - * @warning ---GRY--- The initial time of a simulation is currently ignored. We currently assume that the initial - * time is always the same as the output start time. */ double initialTime() const; @@ -81,9 +78,6 @@ class LIBOPENCOR_EXPORT SedUniformTimeCourse: public SedSimulation * Set the initial time to be used by this simulation. * * @param pInitialTime The initial time to be used by this simulation. - * - * @warning ---GRY--- The initial time of a simulation is currently ignored. We currently assume that the initial - * time is always the same as the output start time. */ void setInitialTime(double pInitialTime); diff --git a/src/bindings/javascript/file.cpp b/src/bindings/javascript/file.cpp index 737c9cc2e..ad84be093 100644 --- a/src/bindings/javascript/file.cpp +++ b/src/bindings/javascript/file.cpp @@ -32,45 +32,49 @@ void fileApi() .property("fileName", &libOpenCOR::File::fileName) .property("url", &libOpenCOR::File::url) .property("path", &libOpenCOR::File::path) + // clang-format off .function("contents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis) { - const auto &contents {pThis->contents()}; - auto size = contents.size(); - - if (size == 0) { - return emscripten::val::global("Uint8Array").new_(0); - } - - // Note: we avoid using emscripten::typed_memory_view() as an intermediate step since it creates a - // JavaScript's TypedArray view directly backed by wasmMemory.buffer. This is fragile and - // would break if ALLOW_MEMORY_GROWTH was to be enabled or if pthreads/SharedArrayBuffer - // support were to be added. By performing the copy entirely within a single EM_ASM() block, - // HEAPU8 is fetched and used atomically. - - return emscripten::val::take_ownership( - static_cast(EM_ASM_PTR({ - var jsArray = new Uint8Array(HEAPU8.subarray($0, $0 + $1)); - - return Emval.toHandle(jsArray); }, contents.data(), size))); - })) + const auto &contents {pThis->contents()}; + auto size = contents.size(); + + if (size == 0) { + return emscripten::val::global("Uint8Array").new_(0); + } + + // Note: we avoid using emscripten::typed_memory_view() as an intermediate step since it creates a + // JavaScript's TypedArray view directly backed by wasmMemory.buffer. This is fragile and would break + // if ALLOW_MEMORY_GROWTH was to be enabled or if pthreads/SharedArrayBuffer support were to be added. + // By performing the copy entirely within a single EM_ASM() block, HEAPU8 is fetched and used + // atomically. + + return emscripten::val::take_ownership(static_cast( + EM_ASM_PTR({ + let jsArray = new Uint8Array(HEAPU8.subarray($0, $0 + $1)); + + return Emval.toHandle(jsArray); + }, contents.data(), size))); + })) .function("setContents", emscripten::optional_override([](const libOpenCOR::FilePtr &pThis, emscripten::val pContents) { - if (pContents.isNull() || pContents.isUndefined()) { - pThis->setContents(libOpenCOR::UnsignedChars {}); + if (pContents.isNull() || pContents.isUndefined()) { + pThis->setContents(libOpenCOR::UnsignedChars {}); - return; - } + return; + } - // Note: avoid using emscripten::vecFromJSArray() since it internally uses typed_memory_view (see - // the note in the contents() binding above). + // Note: avoid using emscripten::vecFromJSArray() since it internally uses typed_memory_view (see the note + // in the contents() binding above). - auto length = pContents["length"].as(); - libOpenCOR::UnsignedChars contents(length); + auto length = pContents["length"].as(); + libOpenCOR::UnsignedChars contents(length); - if (length > 0) { - EM_ASM({ HEAPU8.set(Emval.toValue($0).subarray(0, $2), $1); }, pContents.as_handle(), contents.data(), length); - } + if (length > 0) { + EM_ASM({ + HEAPU8.set(Emval.toValue($0).subarray(0, $2), $1); + }, pContents.as_handle(), contents.data(), length); + } - pThis->setContents(std::move(contents)); - })) + pThis->setContents(std::move(contents)); + })) // clang-format on .property("hasChildFiles", &libOpenCOR::File::hasChildFiles) .property("childFileCount", &libOpenCOR::File::childFileCount) .property("childFileNames", &libOpenCOR::File::childFileNames) @@ -78,11 +82,12 @@ void fileApi() .function("childFile", &libOpenCOR::File::childFile) .function("childFileFromFileName", &libOpenCOR::File::childFileFromFileName); + // clang-format off EM_ASM({ Module["File"]["Type"] = Module["File.Type"]; delete Module["File.Type"]; - }); + }); // clang-format on // FileManager API. diff --git a/src/bindings/javascript/logger.cpp b/src/bindings/javascript/logger.cpp index 7f1ed02f0..1bf2f698b 100644 --- a/src/bindings/javascript/logger.cpp +++ b/src/bindings/javascript/logger.cpp @@ -46,14 +46,14 @@ void loggerApi() .property("typeAsString", &libOpenCOR::Issue::typeAsString) .property("description", &libOpenCOR::Issue::description); + // clang-format off EM_ASM({ Module["Issue"]["Type"] = Module["Issue.Type"]; delete Module["Issue.Type"]; - Module["Issue"].prototype.toString = function() - { + Module["Issue"].prototype.toString = function() { return this.description; }; - }); + }); // clang-format on } diff --git a/src/bindings/javascript/main.cpp b/src/bindings/javascript/main.cpp index 43eedfca6..fbe9dcbec 100644 --- a/src/bindings/javascript/main.cpp +++ b/src/bindings/javascript/main.cpp @@ -55,39 +55,59 @@ EMSCRIPTEN_BINDINGS(libOpenCOR) // those commas can get interpreted as macro argument separators by the C++ preprocessor, which causes // compilation errors. + // clang-format off EM_ASM({ let vectorNames = 'Doubles|FilePtrs|IssuePtrs|SedAbstractTaskPtrs|SedChangePtrs|SedDataDescriptionPtrs|SedDataGeneratorPtrs|SedInstanceTaskPtrs|SedModelPtrs|SedOutputPtrs|SedSimulationPtrs|SedStylePtrs|Strings'.split('|'); - vectorNames.forEach(function(name) { + vectorNames.forEach((name) => { let prototype = Module[name].prototype; Object.defineProperty(prototype, 'length', { - get: function() { return this.size(); } - }); - - prototype[Symbol.iterator] = function() - { - let i = 0; - let n = this.size(); - let iterator = {}; - - iterator.next = () => - { - let result = {}; - - if (i < n) { - result.value = this.get(i++); - result.done = false; - } else { - result.value = undefined; - result.done = true; - } - - return result; - }; - - return iterator; - }; -}); -}); + get: function() { + return this.size(); + } + }); + + prototype[Symbol.iterator] = function() { + let i = 0; + let n = this.size(); + let iterator = {}; + + iterator.next = () => { + let result = {}; + + if (i < n) { + result.value = this.get(i++); + result.done = false; + } else { + result.value = undefined; + result.done = true; + } + + return result; + }; + + return iterator; + }; + + Object.setPrototypeOf(prototype, new Proxy(Object.getPrototypeOf(prototype), { + get: (target, prop, receiver) => { + if (typeof prop === 'string' && /^[0-9]+$/.test(prop)) { + return receiver.get(parseInt(prop)); + } + + return Reflect.get(target, prop, receiver); + }, + set: (target, prop, value, receiver) => { + if (typeof prop === 'string' && /^[0-9]+$/.test(prop)) { + receiver.set(parseInt(prop), value); + + return true; + } + + return Reflect.set(target, prop, value, receiver); + } + })); + }); + }); // clang-format on } diff --git a/src/bindings/javascript/solver.cpp b/src/bindings/javascript/solver.cpp index 3b9eaf0e4..81c406def 100644 --- a/src/bindings/javascript/solver.cpp +++ b/src/bindings/javascript/solver.cpp @@ -31,16 +31,16 @@ void solverApi() .property("id", &libOpenCOR::Solver::id) .property("name", &libOpenCOR::Solver::name); + // clang-format off EM_ASM({ Module["Solver"]["Type"] = Module["Solver.Type"]; delete Module["Solver.Type"]; - Module["Solver"].prototype.toString = function() - { + Module["Solver"].prototype.toString = function() { return this.name; }; - }); + }); // clang-format on // SolverOde API. @@ -59,9 +59,10 @@ void solverApi() reinterpret_cast(pU), pN, reinterpret_cast(pData)); })); + // clang-format off EM_ASM({ Module["nlaSolve"] = Module["nlaSolve"]; - }); + }); // clang-format on emscripten::class_>("SolverNla") .smart_ptr("SolverNla"); @@ -102,6 +103,7 @@ void solverApi() .property("absoluteTolerance", &libOpenCOR::SolverCvode::absoluteTolerance, &libOpenCOR::SolverCvode::setAbsoluteTolerance) .property("interpolateSolution", &libOpenCOR::SolverCvode::interpolateSolution, &libOpenCOR::SolverCvode::setInterpolateSolution); + // clang-format off EM_ASM({ Module["SolverCvode"]["IntegrationMethod"] = Module["SolverCvode.IntegrationMethod"]; Module["SolverCvode"]["IterationType"] = Module["SolverCvode.IterationType"]; @@ -112,7 +114,7 @@ void solverApi() delete Module["SolverCvode.IterationType"]; delete Module["SolverCvode.LinearSolver"]; delete Module["SolverCvode.Preconditioner"]; - }); + }); // clang-format on // SolverForwardEuler API. @@ -145,11 +147,12 @@ void solverApi() .property("upperHalfBandwidth", &libOpenCOR::SolverKinsol::upperHalfBandwidth, &libOpenCOR::SolverKinsol::setUpperHalfBandwidth) .property("lowerHalfBandwidth", &libOpenCOR::SolverKinsol::lowerHalfBandwidth, &libOpenCOR::SolverKinsol::setLowerHalfBandwidth); + // clang-format off EM_ASM({ Module["SolverKinsol"]["LinearSolver"] = Module["SolverKinsol.LinearSolver"]; delete Module["SolverKinsol.LinearSolver"]; - }); + }); // clang-format on // SolverSecondOrderRungeKutta API. diff --git a/src/sed/sedinstancetask.cpp b/src/sed/sedinstancetask.cpp index 8cd91e03b..6b383ab0e 100644 --- a/src/sed/sedinstancetask.cpp +++ b/src/sed/sedinstancetask.cpp @@ -37,11 +37,12 @@ static emscripten::val toFloat64Array(const Doubles &data) // Note: see the note in src/bindings/javascript/file.cpp for why we avoid typed_memory_view() and use EM_ASM() // instead. - return emscripten::val::take_ownership( - static_cast(EM_ASM_PTR({ - var jsArray = new Float64Array(new Float64Array(HEAPU8.buffer, $0, $1)); + // clang-format off + return emscripten::val::take_ownership(static_cast(EM_ASM_PTR({ + let jsArray = new Float64Array(new Float64Array(HEAPU8.buffer, $0, $1)); - return Emval.toHandle(jsArray); }, data.data(), size))); + return Emval.toHandle(jsArray); + }, data.data(), size))); // clang-format on } #endif @@ -246,7 +247,7 @@ void SedInstanceTask::Impl::initialise() // initialise our variables and compute computed constants and variables. if (mSedUniformTimeCourse != nullptr) { - mVoi = mSedUniformTimeCourse->pimpl()->mOutputStartTime; + mVoi = mSedUniformTimeCourse->pimpl()->mInitialTime; #ifdef __EMSCRIPTEN__ mRuntime->initialiseArraysForDifferentialModel(mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); @@ -302,6 +303,56 @@ void SedInstanceTask::Impl::initialise() } } +void SedInstanceTask::Impl::run(double pVoiStart, double pVoiEnd, double pVoiInterval, bool pTrackResults) +{ + // Track our initial results. + + size_t index {0}; + + if (pTrackResults) { + trackResults(index); + } + + // Compute the differential model. + + auto *odeSolverPimpl {mOdeSolver->pimpl()}; + size_t voiCounter {0}; + +#ifndef __EMSCRIPTEN__ + const auto computeVariablesForDifferentialModel = mRuntime->computeVariablesForDifferentialModel(); +#endif + + while (!fuzzyCompare(mVoi, pVoiEnd)) { + if (!odeSolverPimpl->solve(mVoi, std::min(pVoiStart + static_cast(++voiCounter) * pVoiInterval, pVoiEnd))) { + addIssues(mOdeSolver, mOdeSolver->name()); + + return; + } + +#ifdef __EMSCRIPTEN__ + mRuntime->computeVariablesForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); +#else + computeVariablesForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); +#endif + + //---GRY--- WE NEED TO CHECK FOR POSSIBLE NLA ISSUES, BUT FOR CODE COVERAGE WE NEED A MODEL THAT WOULD TRIGGER + // NLA ISSUES HERE, WHICH WE DON'T HAVE YET HENCE WE DISABLE THE FOLLOWING CODE WHEN DOING CODE + // COVERAGE. + +#ifndef CODE_COVERAGE_ENABLED + if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) { + addIssues(mNlaSolver, mNlaSolver->name()); + + return; + } +#endif + + if (pTrackResults) { + trackResults(++index); + } + } +} + double SedInstanceTask::Impl::run() { // Start our timer. @@ -340,50 +391,22 @@ double SedInstanceTask::Impl::run() mResults.algebraicVariables[i].resize(resultsSize, NAN); } - // Track our initial results. - - size_t index {0}; - - trackResults(index); - - // Compute the differential model. + // Run our simulation from the initial time to the output start time, without tracking our results. - auto *odeSolverPimpl {mOdeSolver->pimpl()}; - const auto voiStart {mVoi}; - const auto voiEnd {sedUniformTimeCoursePimpl->mOutputEndTime}; - const auto voiInterval {(voiEnd - mVoi) / sedUniformTimeCoursePimpl->mNumberOfSteps}; - size_t voiCounter {0}; + const auto voiInterval {(sedUniformTimeCoursePimpl->mOutputEndTime - sedUniformTimeCoursePimpl->mOutputStartTime) / sedUniformTimeCoursePimpl->mNumberOfSteps}; -#ifndef __EMSCRIPTEN__ - const auto computeVariablesForDifferentialModel = mRuntime->computeVariablesForDifferentialModel(); -#endif - - while (!fuzzyCompare(mVoi, voiEnd)) { - if (!odeSolverPimpl->solve(mVoi, std::min(voiStart + static_cast(++voiCounter) * voiInterval, voiEnd))) { - addIssues(mOdeSolver, mOdeSolver->name()); - - return 0.0; - } - -#ifdef __EMSCRIPTEN__ - mRuntime->computeVariablesForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); -#else - computeVariablesForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); -#endif + run(sedUniformTimeCoursePimpl->mInitialTime, sedUniformTimeCoursePimpl->mOutputStartTime, voiInterval, false); - //---GRY--- WE NEED TO CHECK FOR POSSIBLE NLA ISSUES, BUT FOR CODE COVERAGE WE NEED A MODEL THAT WOULD - // TRIGGER NLA ISSUES HERE, WHICH WE DON'T HAVE YET HENCE WE DISABLE THE FOLLOWING CODE WHEN DOING - // CODE COVERAGE. + if (hasIssues()) { + return 0.0; + } -#ifndef CODE_COVERAGE_ENABLED - if ((mNlaSolver != nullptr) && mNlaSolver->hasIssues()) { - addIssues(mNlaSolver, mNlaSolver->name()); + // Run our simulation from the output start time to the output end time, tracking our results. - return 0.0; - } -#endif + run(sedUniformTimeCoursePimpl->mOutputStartTime, sedUniformTimeCoursePimpl->mOutputEndTime, voiInterval, true); - trackResults(++index); + if (hasIssues()) { + return 0.0; } } else { // Track our results. diff --git a/src/sed/sedinstancetask_p.h b/src/sed/sedinstancetask_p.h index 0447fed6a..5398065d0 100644 --- a/src/sed/sedinstancetask_p.h +++ b/src/sed/sedinstancetask_p.h @@ -91,6 +91,7 @@ class SedInstanceTask::Impl: public Logger::Impl void applyChanges(); void initialise(); + void run(double pVoiStart, double pVoiEnd, double pVoiInterval, bool pTrackResults); double run(); const Doubles &voi() const; diff --git a/src/support/cellml/cellmlfileruntime.cpp b/src/support/cellml/cellmlfileruntime.cpp index 8ee469891..b5ae6229f 100644 --- a/src/support/cellml/cellmlfileruntime.cpp +++ b/src/support/cellml/cellmlfileruntime.cpp @@ -72,7 +72,7 @@ intptr_t instantiateWebAssemblyModule(const UnsignedChars &pWasmModule, bool pDi // NLA solve function. - nlaSolve: function(nlaSolverAddress, objectiveFunctionIndex, u, n, data) { + nlaSolve: (nlaSolverAddress, objectiveFunctionIndex, u, n, data) => { Module.nlaSolve(Number(nlaSolverAddress), wasmInstanceFunctionsId, Number(objectiveFunctionIndex), Number(u), Number(n), Number(data)); }, @@ -466,10 +466,12 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl CellmlFileRuntime::Impl::~Impl() { if (mWasmInstanceFunctionsId != 0) { + // clang-format off EM_ASM({ if (Module.wasmInstanceFunctions !== undefined) { Module.wasmInstanceFunctions.delete($0); - } }, mWasmInstanceFunctionsId); + } + }, mWasmInstanceFunctionsId); // clang-format on } } diff --git a/tests/api/file/basictests.cpp b/tests/api/file/basictests.cpp index 1142d6e95..147965312 100644 --- a/tests/api/file/basictests.cpp +++ b/tests/api/file/basictests.cpp @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include "utils.h" + #include "tests/utils.h" #include @@ -44,12 +46,13 @@ libOpenCOR::ExpectedIssues expectedUnknownFileIssues() TEST(BasicFileTest, localFile) { - auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto filePath {libOpenCOR::resourcePath("file.txt")}; + auto file {libOpenCOR::File::create(filePath)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); - EXPECT_EQ(file->fileName(), libOpenCOR::LOCAL_FILE); + EXPECT_EQ(file->fileName(), filePath); EXPECT_EQ(file->url(), ""); - EXPECT_EQ(file->path(), libOpenCOR::LOCAL_FILE); + EXPECT_EQ(file->path(), filePath); EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, expectedNonExistingFileIssues()); } @@ -60,7 +63,7 @@ TEST(BasicSedTest, existingRelativeLocalFile) std::filesystem::current_path(libOpenCOR::resourcePath()); - auto file {libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE)}; + auto file {libOpenCOR::File::create("cellml_2.cellml")}; EXPECT_FALSE(file->contents().empty()); EXPECT_EQ_ISSUES(file, expectedNoIssues()); @@ -94,16 +97,17 @@ TEST(BasicFileTest, nonExistingRelativeLocalFile) TEST(BasicFileTest, urlBasedLocalFile) { + auto filePath {libOpenCOR::resourcePath("file.txt")}; #ifdef BUILDING_ON_WINDOWS - auto file {libOpenCOR::File::create("file:///P:/some/path/file.txt")}; + auto file {libOpenCOR::File::create(std::string("file:///") + libOpenCOR::forwardSlashPath(filePath))}; #else - auto file {libOpenCOR::File::create("file:///some/path/file.txt")}; + auto file {libOpenCOR::File::create(std::string("file://") + filePath)}; #endif EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); - EXPECT_EQ(file->fileName(), libOpenCOR::LOCAL_FILE); + EXPECT_EQ(file->fileName(), filePath); EXPECT_EQ(file->url(), ""); - EXPECT_EQ(file->path(), libOpenCOR::LOCAL_FILE); + EXPECT_EQ(file->path(), filePath); EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, expectedNonExistingFileIssues()); } @@ -121,27 +125,28 @@ TEST(BasicFileTest, remoteFile) TEST(BasicFileTest, encodedRemoteFile) { - auto file {libOpenCOR::File::create(libOpenCOR::ENCODED_REMOTE_FILE)}; + auto file {libOpenCOR::File::create("https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml")}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); EXPECT_NE(file->fileName(), ""); - EXPECT_EQ(file->url(), libOpenCOR::NON_ENCODED_REMOTE_FILE); - EXPECT_EQ(file->path(), libOpenCOR::NON_ENCODED_REMOTE_FILE); + EXPECT_EQ(file->url(), "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml"); + EXPECT_EQ(file->path(), "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml"); EXPECT_FALSE(file->contents().empty()); } TEST(BasicFileTest, localVirtualFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE), false)}; + auto filePath {libOpenCOR::resourcePath("unknown_file.txt")}; + auto file {libOpenCOR::File::create(filePath, false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); - EXPECT_EQ(file->fileName(), libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + EXPECT_EQ(file->fileName(), filePath); EXPECT_EQ(file->url(), ""); - EXPECT_EQ(file->path(), libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + EXPECT_EQ(file->path(), filePath); EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, expectedNoIssues()); - auto someUnknownContents {libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS)}; + auto someUnknownContents {libOpenCOR::charArrayToUnsignedChars(libOpenCOR::textFileContents(filePath).c_str())}; file->setContents(someUnknownContents); @@ -152,7 +157,7 @@ TEST(BasicFileTest, localVirtualFile) TEST(BasicFileTest, remoteVirtualFile) { - auto file {libOpenCOR::File::create(libOpenCOR::UNKNOWN_REMOTE_FILE, false)}; + auto file {libOpenCOR::File::create("https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt", false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); #ifdef BUILDING_USING_MSVC @@ -160,12 +165,13 @@ TEST(BasicFileTest, remoteVirtualFile) #else EXPECT_EQ(file->fileName(), "/some/path/file"); #endif - EXPECT_EQ(file->url(), libOpenCOR::UNKNOWN_REMOTE_FILE); - EXPECT_EQ(file->path(), libOpenCOR::UNKNOWN_REMOTE_FILE); + EXPECT_EQ(file->url(), "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt"); + EXPECT_EQ(file->path(), "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt"); EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, expectedNoIssues()); - auto someUnknownContents {libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS)}; + auto filePath {libOpenCOR::resourcePath("unknown_file.txt")}; + auto someUnknownContents {libOpenCOR::charArrayToUnsignedChars(libOpenCOR::textFileContents(filePath).c_str())}; file->setContents(someUnknownContents); @@ -177,21 +183,22 @@ TEST(BasicFileTest, remoteVirtualFile) TEST(BasicFileTest, fileManager) { auto &fileManager {libOpenCOR::FileManager::instance()}; + auto filePath {libOpenCOR::resourcePath("file.txt")}; EXPECT_FALSE(fileManager.hasFiles()); EXPECT_EQ(fileManager.fileCount(), 0); EXPECT_TRUE(fileManager.files().empty()); EXPECT_EQ(fileManager.file(0), nullptr); - EXPECT_EQ(fileManager.file(libOpenCOR::LOCAL_FILE), nullptr); + EXPECT_EQ(fileManager.file(filePath), nullptr); - auto localFile {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto localFile {libOpenCOR::File::create(filePath)}; auto &sameFileManager {libOpenCOR::FileManager::instance()}; EXPECT_TRUE(sameFileManager.hasFiles()); EXPECT_EQ(sameFileManager.fileCount(), 1); EXPECT_EQ(sameFileManager.files().size(), 1); EXPECT_EQ(fileManager.file(0), localFile); - EXPECT_EQ(sameFileManager.file(libOpenCOR::LOCAL_FILE), localFile); + EXPECT_EQ(sameFileManager.file(filePath), localFile); auto remoteFile {libOpenCOR::File::create(libOpenCOR::REMOTE_FILE)}; @@ -207,7 +214,7 @@ TEST(BasicFileTest, fileManager) EXPECT_EQ(sameFileManager.fileCount(), 1); EXPECT_EQ(sameFileManager.files().size(), 1); EXPECT_EQ(fileManager.file(1), nullptr); - EXPECT_EQ(sameFileManager.file(libOpenCOR::LOCAL_FILE), nullptr); + EXPECT_EQ(sameFileManager.file(filePath), nullptr); sameFileManager.manage(localFile); @@ -215,7 +222,7 @@ TEST(BasicFileTest, fileManager) EXPECT_EQ(sameFileManager.fileCount(), 2); EXPECT_EQ(sameFileManager.files().size(), 2); EXPECT_EQ(fileManager.file(1), localFile); - EXPECT_EQ(sameFileManager.file(libOpenCOR::LOCAL_FILE), localFile); + EXPECT_EQ(sameFileManager.file(filePath), localFile); fileManager.reset(); @@ -225,5 +232,5 @@ TEST(BasicFileTest, fileManager) EXPECT_EQ(fileManager.file(0), nullptr); EXPECT_EQ(fileManager.file(1), nullptr); EXPECT_EQ(fileManager.file(libOpenCOR::REMOTE_FILE), nullptr); - EXPECT_EQ(fileManager.file(libOpenCOR::UNKNOWN_FILE), nullptr); + EXPECT_EQ(fileManager.file(libOpenCOR::resourcePath("unknown_file.txt")), nullptr); } diff --git a/tests/api/file/childtests.cpp b/tests/api/file/childtests.cpp index e1953b688..b3d9ee805 100644 --- a/tests/api/file/childtests.cpp +++ b/tests/api/file/childtests.cpp @@ -43,7 +43,7 @@ void doTestDataset(const std::string &pNumber, const std::vector &p } EXPECT_EQ(file->childFile(++index), nullptr); - EXPECT_EQ(file->childFile(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)), nullptr); + EXPECT_EQ(file->childFile(libOpenCOR::resourcePath("unknown_file.txt")), nullptr); EXPECT_EQ(libOpenCOR::toString(simulationFile->contents()), libOpenCOR::textFileContents(libOpenCOR::resourcePath("api/file/dataset_" + pNumber + ".json"))); } @@ -52,14 +52,15 @@ void doTestDataset(const std::string &pNumber, const std::vector &p TEST(ChildFileTest, noChildFiles) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE))}; + auto filePath {libOpenCOR::resourcePath("unknown_file.txt")}; + auto file {libOpenCOR::File::create(filePath)}; EXPECT_FALSE(file->hasChildFiles()); EXPECT_EQ(file->childFileCount(), 0); EXPECT_EQ(file->childFileNames().size(), 0); EXPECT_EQ(file->childFiles().size(), 0); EXPECT_EQ(file->childFile(0), nullptr); - EXPECT_EQ(file->childFile(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)), nullptr); + EXPECT_EQ(file->childFile(filePath), nullptr); } TEST(ChildFileTest, dataset135) diff --git a/tests/api/file/coveragetests.cpp b/tests/api/file/coveragetests.cpp index c4a915fc5..5e00b5a69 100644 --- a/tests/api/file/coveragetests.cpp +++ b/tests/api/file/coveragetests.cpp @@ -20,7 +20,7 @@ limitations under the License. TEST(CoverageFileTest, emptyFile) { - auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("file.txt")); file->setContents({}); @@ -29,7 +29,7 @@ TEST(CoverageFileTest, emptyFile) TEST(CoverageFileTest, fileWithNullCharacter) { - auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("file.txt")); file->setContents({0}); @@ -38,27 +38,28 @@ TEST(CoverageFileTest, fileWithNullCharacter) TEST(CoverageFileTest, sedmlFileWithNoParent) { - auto file = libOpenCOR::File::create(libOpenCOR::SEDML_2_FILE); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.sedml")); - file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SEDML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::textFileContents(file->path()).c_str())); } TEST(CoverageFileTest, irretrievableVirtualFile) { - auto file = libOpenCOR::File::create(libOpenCOR::IRRETRIEVABLE_FILE, false); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("irretrievable_file.txt"), false); EXPECT_FALSE(file->hasIssues()); } TEST(CoverageFileTest, irretrievableRemoteFile) { - libOpenCOR::File::create(libOpenCOR::IRRETRIEVABLE_REMOTE_FILE); + libOpenCOR::File::create("https://some.domain.com/irretrievable_file.txt"); } TEST(CoverageFileTest, sameLocalFile) { - auto file1 = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - auto file2 = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); + auto filePath {libOpenCOR::resourcePath("file.txt")}; + auto file1 = libOpenCOR::File::create(filePath); + auto file2 = libOpenCOR::File::create(filePath); EXPECT_EQ(file1, file2); } @@ -81,7 +82,7 @@ TEST(CoverageFileTest, doNotRetrieveContents) TEST(CoverageFileTest, unmanageFileWithChildren) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.omex")); auto &fileManager = libOpenCOR::FileManager::instance(); EXPECT_EQ(fileManager.fileCount(), 3); diff --git a/tests/api/file/typetests.cpp b/tests/api/file/typetests.cpp index 54a3a8361..e971d4e95 100644 --- a/tests/api/file/typetests.cpp +++ b/tests/api/file/typetests.cpp @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include "utils.h" #include "tests/utils.h" #include @@ -38,7 +39,7 @@ libOpenCOR::ExpectedIssues expectedIrretrievableFileIssues() TEST(TypeFileTest, irretrievableFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::IRRETRIEVABLE_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("irretrievable_file.txt"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::IRRETRIEVABLE_FILE); EXPECT_EQ_ISSUES(file, expectedIrretrievableFileIssues()); @@ -46,7 +47,7 @@ TEST(TypeFileTest, irretrievableFile) TEST(TypeFileTest, unknownFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("unknown_file.txt"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ_ISSUES(file, expectedUnknownFileIssues()); @@ -54,7 +55,7 @@ TEST(TypeFileTest, unknownFile) TEST(TypeFileTest, sbmlFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SBML_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("sbml.sbml"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ_ISSUES(file, expectedUnknownFileIssues()); @@ -62,61 +63,62 @@ TEST(TypeFileTest, sbmlFile) TEST(TypeFileTest, errorSedmlFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_SEDML_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("error.sedml"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, cellml1xFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_1_X_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_1_x.cellml"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); } TEST(TypeFileTest, sedml1xFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_1_X_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_1_x.sedml"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, combine1xArchive) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_1_X_ARCHIVE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_1_x.omex"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::COMBINE_ARCHIVE); } TEST(TypeFileTest, cellml2File) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); } TEST(TypeFileTest, sedml2File) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.sedml"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, combine2Archive) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.omex"))}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::COMBINE_ARCHIVE); } TEST(TypeFileTest, unknownVirtualFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE), false)}; + auto filePath {libOpenCOR::resourcePath("unknown_file.txt")}; + auto file {libOpenCOR::File::create(filePath, false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); - file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::UNKNOWN_CONTENTS)); + file->setContents(libOpenCOR::fileContents(filePath)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ_ISSUES(file, expectedUnknownFileIssues()); @@ -124,36 +126,39 @@ TEST(TypeFileTest, unknownVirtualFile) TEST(TypeFileTest, cellmlVirtualFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE), false)}; + auto filePath {libOpenCOR::resourcePath("cellml_2.cellml")}; + auto file {libOpenCOR::File::create(filePath, false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); - file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::CELLML_CONTENTS)); + file->setContents(libOpenCOR::fileContents(filePath)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); } TEST(TypeFileTest, sedmlVirtualFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE), false)}; + auto filePath {libOpenCOR::resourcePath("cellml_2.sedml")}; + auto file {libOpenCOR::File::create(filePath, false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); - file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SEDML_CONTENTS)); + file->setContents(libOpenCOR::fileContents(filePath)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } TEST(TypeFileTest, combineVirtualArchive) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE), false)}; + auto filePath {libOpenCOR::resourcePath("cellml_2.omex")}; + auto file {libOpenCOR::File::create(filePath, false)}; EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ(file->contents(), libOpenCOR::UnsignedChars()); - file->setContents(libOpenCOR::base64Decode(libOpenCOR::BASE64_COMBINE_ARCHIVE_CONTENTS)); + file->setContents(libOpenCOR::fileContents(filePath)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::COMBINE_ARCHIVE); } diff --git a/tests/api/logger/coveragetests.cpp b/tests/api/logger/coveragetests.cpp index 9a617a52b..501bbc2ff 100644 --- a/tests/api/logger/coveragetests.cpp +++ b/tests/api/logger/coveragetests.cpp @@ -20,28 +20,28 @@ limitations under the License. TEST(CoverageLoggerTest, hasIssues) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_FALSE(file->hasIssues()); } TEST(CoverageLoggerTest, issueCount) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_EQ(file->issueCount(), 0); } TEST(CoverageLoggerTest, issues) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_TRUE(file->issues().empty()); } TEST(CoverageLoggerTest, issue) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_CELLML_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("error.cellml")); EXPECT_NE(file->issue(0), nullptr); EXPECT_EQ(file->issue(file->issueCount()), nullptr); @@ -49,28 +49,28 @@ TEST(CoverageLoggerTest, issue) TEST(CoverageLoggerTest, hasErrors) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_FALSE(file->hasErrors()); } TEST(CoverageLoggerTest, errorCount) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_EQ(file->errorCount(), 0); } TEST(CoverageLoggerTest, errors) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_TRUE(file->errors().empty()); } TEST(CoverageLoggerTest, error) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_CELLML_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("error.cellml")); EXPECT_NE(file->error(0), nullptr); EXPECT_EQ(file->error(file->errorCount()), nullptr); @@ -78,28 +78,28 @@ TEST(CoverageLoggerTest, error) TEST(CoverageLoggerTest, hasWarnings) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_FALSE(file->hasWarnings()); } TEST(CoverageLoggerTest, warningCount) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_EQ(file->warningCount(), 0); } TEST(CoverageLoggerTest, warnings) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); EXPECT_TRUE(file->warnings().empty()); } TEST(CoverageLoggerTest, warning) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.sedml")); auto document = libOpenCOR::SedDocument::create(file); EXPECT_NE(document->warning(0), nullptr); diff --git a/tests/api/sed/basictests.cpp b/tests/api/sed/basictests.cpp index 844187b5a..6bbd9d87e 100644 --- a/tests/api/sed/basictests.cpp +++ b/tests/api/sed/basictests.cpp @@ -31,7 +31,7 @@ TEST(BasicSedTest, unknownFile) {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using an unknown file."}, }}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("unknown_file.txt"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); @@ -39,7 +39,7 @@ TEST(BasicSedTest, unknownFile) TEST(BasicSedTest, cellmlFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); @@ -47,12 +47,12 @@ TEST(BasicSedTest, cellmlFile) TEST(BasicSedTest, sedmlFile) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.sedml"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_TRUE(document->hasIssues()); - auto neededFile {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto neededFile {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; document = libOpenCOR::SedDocument::create(file); @@ -66,7 +66,7 @@ TEST(BasicSedTest, sedmlFileWithAbsoluteCellmlFile) EXPECT_TRUE(document->hasIssues()); - auto neededFile {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto neededFile {libOpenCOR::File::create(libOpenCOR::resourcePath("file.txt"))}; document = libOpenCOR::SedDocument::create(file); @@ -89,7 +89,7 @@ TEST(BasicSedTest, sedmlFileWithRemoteCellmlFile) TEST(BasicSedTest, combineArchive) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.omex"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); @@ -167,7 +167,7 @@ TEST(BasicSedTest, irretrievableFile) {libOpenCOR::Issue::Type::ERROR, "A simulation experiment description cannot be created using an irretrievable file."}, }}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::IRRETRIEVABLE_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("irretrievable_file.txt"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); diff --git a/tests/api/sed/coveragetests.cpp b/tests/api/sed/coveragetests.cpp index dc776c5cf..01bd5c98c 100644 --- a/tests/api/sed/coveragetests.cpp +++ b/tests/api/sed/coveragetests.cpp @@ -42,7 +42,7 @@ TEST(CoverageSedTest, models) EXPECT_EQ(document->models().size(), 0); EXPECT_FALSE(document->addModel(nullptr)); - auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("file.txt"))}; auto model {libOpenCOR::SedModel::create(document, file)}; EXPECT_EQ(model->file(), file); @@ -274,7 +274,7 @@ TEST(CoverageSedTest, tasks) EXPECT_EQ(document->tasks().size(), 0); EXPECT_FALSE(document->addTask(nullptr)); - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto model {libOpenCOR::SedModel::create(document, file)}; auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; auto task {libOpenCOR::SedTask::create(document, model, simulation)}; @@ -362,7 +362,7 @@ TEST(CoverageSedTest, nlaSolver) TEST(CoverageSedTest, sedBase) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; auto simulation {libOpenCOR::SedOneStep::create(document)}; @@ -371,7 +371,7 @@ TEST(CoverageSedTest, sedBase) TEST(CoverageSedTest, sedOneStep) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; auto simulation {libOpenCOR::SedOneStep::create(document)}; @@ -391,7 +391,7 @@ TEST(CoverageSedTest, sedUniformTimeCourse) static const auto OUTPUT_END_TIME {7.89}; static const auto NUMBER_OF_STEPS {10}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; auto simulation {libOpenCOR::SedUniformTimeCourse::create(document)}; @@ -507,13 +507,15 @@ TEST(CoverageSedTest, sedInstanceAndSedInstanceTaskNonDifferentialModel) TEST(CoverageSedTest, sedDocument) { - auto file {libOpenCOR::File::create(libOpenCOR::HTTP_REMOTE_CELLML_FILE)}; + // Note: the three following URLs use http rather than https to help with coverage testing. + + auto file {libOpenCOR::File::create("http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml")}; libOpenCOR::SedDocument::create(file); - file = libOpenCOR::File::create(libOpenCOR::HTTP_REMOTE_SEDML_FILE); + file = libOpenCOR::File::create("http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml"); libOpenCOR::SedDocument::create(file); - file = libOpenCOR::File::create(libOpenCOR::HTTP_REMOTE_COMBINE_ARCHIVE); + file = libOpenCOR::File::create("http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex"); libOpenCOR::SedDocument::create(file); } @@ -521,7 +523,7 @@ TEST(CoverageSedTest, solver) { // Get the duplicate() method of different solvers to be covered. - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; document->simulations()[0]->setOdeSolver(libOpenCOR::SolverForwardEuler::create()); @@ -738,3 +740,10 @@ TEST(CoverageSedTest, legacySedmlFileUnknownProperty) EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); } + +TEST(CoverageSedTest, sedmlFileWithBareFilename) +{ + auto file {libOpenCOR::File::create("cellml_2.sedml")}; + + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::textFileContents(libOpenCOR::resourcePath("cellml_2.sedml")).c_str())); +} diff --git a/tests/api/sed/instancetests.cpp b/tests/api/sed/instancetests.cpp index 11cfb6874..2db61a667 100644 --- a/tests/api/sed/instancetests.cpp +++ b/tests/api/sed/instancetests.cpp @@ -37,7 +37,7 @@ TEST(InstanceSedTest, invalidCellmlFile) {libOpenCOR::Issue::Type::ERROR, "Task | Model | CellML | Analyser: equation 'x+y+z' in component 'my_component' is not an equality statement (i.e. LHS = RHS)."}, }}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::ERROR_CELLML_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("error.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; auto instance {document->instantiate()}; @@ -114,7 +114,7 @@ TEST(InstanceSedTest, odeModel) #endif }}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {std::dynamic_pointer_cast(document->simulations()[0])}; @@ -149,7 +149,7 @@ TEST(InstanceSedTest, odeModelWithNoOdeSolver) {libOpenCOR::Issue::Type::ERROR, "Task | Simulation: simulation 'simulation1' is to be used with model 'model1' which requires an ODE solver but none is provided."}, }}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; document->simulations()[0]->setOdeSolver(nullptr); @@ -252,7 +252,7 @@ TEST(InstanceSedTest, daeModelWithNoOdeOrNlaSolver) TEST(InstanceSedTest, combineArchive) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.omex"))}; auto document {libOpenCOR::SedDocument::create(file)}; auto instance {document->instantiate()}; @@ -312,8 +312,8 @@ TEST(InstanceSedTest, daeModelFromSedmlFile) TEST(InstanceSedTest, daeModelFromCombineArchive) { - auto combineArchive {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae/model.omex"))}; - auto document {libOpenCOR::SedDocument::create(combineArchive)}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae/model.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); @@ -359,8 +359,8 @@ TEST(InstanceSedTest, daeModelFromLegacySedmlFile) TEST(InstanceSedTest, daeModelFromLegacyCombineArchive) { - auto combineArchive {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae/model_legacy.omex"))}; - auto document {libOpenCOR::SedDocument::create(combineArchive)}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/dae/model_legacy.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_FALSE(document->hasIssues()); @@ -379,3 +379,54 @@ TEST(InstanceSedTest, daeModelFromLegacyCombineArchive) EXPECT_FALSE(instance->hasIssues()); } + +TEST(InstanceSedTest, simulationWithInitialTime) +{ + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/simulation_with_initial_time.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; + + EXPECT_FALSE(instance->hasIssues()); + + instance->run(); + + EXPECT_FALSE(instance->hasIssues()); + + static const auto VOI_SIZE {50001}; + static const auto VOI_START {0.0}; + static const auto VOI_END {50.0}; + + const auto &instanceTask {instance->tasks()[0]}; + const auto &voi {instanceTask->voi()}; + + EXPECT_EQ(voi.size(), VOI_SIZE); + EXPECT_EQ(voi[0], VOI_START); + EXPECT_EQ(voi[voi.size() - 1], VOI_END); + + static const auto INITIAL_VALUE {1.0}; + + const auto &x {instanceTask->state(0)}; + const auto &y {instanceTask->state(1)}; + const auto &z {instanceTask->state(2)}; + + EXPECT_EQ(x.size(), VOI_SIZE); + EXPECT_EQ(y.size(), VOI_SIZE); + EXPECT_EQ(z.size(), VOI_SIZE); + + EXPECT_NE(x[0], INITIAL_VALUE); + EXPECT_NE(y[0], INITIAL_VALUE); + EXPECT_NE(z[0], INITIAL_VALUE); +} + +TEST(InstanceSedTest, simulationWithInitialTimeFailing) +{ + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/simulation_with_initial_time_failing.omex"))}; + auto document {libOpenCOR::SedDocument::create(file)}; + auto instance {document->instantiate()}; + + EXPECT_FALSE(instance->hasIssues()); + + instance->run(); + + EXPECT_TRUE(instance->hasIssues()); +} diff --git a/tests/api/sed/serialisetests.cpp b/tests/api/sed/serialisetests.cpp index 733057727..9be9fec8f 100644 --- a/tests/api/sed/serialisetests.cpp +++ b/tests/api/sed/serialisetests.cpp @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include "utils.h" + #include "tests/utils.h" #include @@ -105,7 +107,7 @@ std::string kinsolExpectedSerialisation(const std::map TEST(SerialiseSedTest, localCellmlFileWithBasePath) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(libOpenCOR::RESOURCE_LOCATION), cvodeExpectedSerialisation("cellml_2.cellml")); @@ -113,22 +115,23 @@ TEST(SerialiseSedTest, localCellmlFileWithBasePath) TEST(SerialiseSedTest, localCellmlFileWithoutBasePath) { - auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto filePath {libOpenCOR::resourcePath("cellml_2.cellml")}; + auto file {libOpenCOR::File::create(filePath)}; - file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::CELLML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::textFileContents(filePath).c_str())); auto document {libOpenCOR::SedDocument::create(file)}; -#ifdef BUILDING_USING_MSVC - EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation("file:///P:/some/path/file.txt")); +#ifdef BUILDING_ON_WINDOWS + EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation(std::string("file:///").append(libOpenCOR::forwardSlashPath(filePath)))); #else - EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation("file:///some/path/file.txt")); + EXPECT_EQ(document->serialise(), cvodeExpectedSerialisation(std::string("file://").append(filePath))); #endif } TEST(SerialiseSedTest, relativeLocalCellmlFileWithBasePath) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ(document->serialise(std::string(libOpenCOR::RESOURCE_LOCATION).append("/../..")), cvodeExpectedSerialisation("tests/res/cellml_2.cellml")); @@ -136,9 +139,9 @@ TEST(SerialiseSedTest, relativeLocalCellmlFileWithBasePath) TEST(SerialiseSedTest, relativeLocalCellmlFileWithoutBasePath) { - auto file {libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE)}; + auto file {libOpenCOR::File::create("cellml_2.cellml")}; - file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::CELLML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::textFileContents(libOpenCOR::resourcePath("cellml_2.cellml")).c_str())); auto document {libOpenCOR::SedDocument::create(file)}; @@ -250,17 +253,17 @@ namespace { std::string sedChangeExpectedSerialisation(const std::string &pComponent, const std::string &pVariable, const std::string &pNewValue) { +#ifdef BUILDING_ON_WINDOWS + auto source {std::string("file:///") + libOpenCOR::forwardSlashPath(libOpenCOR::resourcePath("file.txt"))}; +#else + auto source {std::string("file://") + libOpenCOR::resourcePath("file.txt")}; +#endif + return std::string(R"( newValue(), "123.456789"); auto document {libOpenCOR::SedDocument::create()}; - auto file {libOpenCOR::File::create(libOpenCOR::LOCAL_FILE)}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("file.txt"))}; auto model {libOpenCOR::SedModel::create(document, file)}; EXPECT_TRUE(model->addChange(changeAttribute)); @@ -328,7 +331,7 @@ TEST(SerialiseSedTest, fixedStepOdeSolver) )"}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; @@ -339,7 +342,7 @@ TEST(SerialiseSedTest, fixedStepOdeSolver) TEST(SerialiseSedTest, cvodeSolverWithAdamsMoultonInterationMethod) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -351,7 +354,7 @@ TEST(SerialiseSedTest, cvodeSolverWithAdamsMoultonInterationMethod) TEST(SerialiseSedTest, cvodeSolverWithFunctionalIterationType) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -363,7 +366,7 @@ TEST(SerialiseSedTest, cvodeSolverWithFunctionalIterationType) TEST(SerialiseSedTest, cvodeSolverWithBandedLinearSolver) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -375,7 +378,7 @@ TEST(SerialiseSedTest, cvodeSolverWithBandedLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithDiagonalLinearSolver) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -387,7 +390,7 @@ TEST(SerialiseSedTest, cvodeSolverWithDiagonalLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithGmresLinearSolver) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -399,7 +402,7 @@ TEST(SerialiseSedTest, cvodeSolverWithGmresLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithBicgstabLinearSolver) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -411,7 +414,7 @@ TEST(SerialiseSedTest, cvodeSolverWithBicgstabLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithTfqmrLinearSolver) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -423,7 +426,7 @@ TEST(SerialiseSedTest, cvodeSolverWithTfqmrLinearSolver) TEST(SerialiseSedTest, cvodeSolverWithNoPreconditioner) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -435,7 +438,7 @@ TEST(SerialiseSedTest, cvodeSolverWithNoPreconditioner) TEST(SerialiseSedTest, cvodeSolverWithNoInterpolateSolution) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; const auto &simulation {document->simulations()[0]}; const auto &solver {std::dynamic_pointer_cast(simulation->odeSolver())}; @@ -509,7 +512,7 @@ TEST(SerialiseSedTest, oneStepSimulation) )"}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto document {libOpenCOR::SedDocument::create(file)}; document->removeSimulation(document->simulations()[0]); @@ -556,7 +559,7 @@ TEST(SerialiseSedTest, sedmlFile) )"}; - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.sedml"))}; auto document {libOpenCOR::SedDocument::create(file)}; EXPECT_EQ_ISSUES(document, EXPECTED_ISSUES); diff --git a/tests/bindings/javascript/file.basic.test.js b/tests/bindings/javascript/file.basic.test.js index 8e7177433..a845d63c4 100644 --- a/tests/bindings/javascript/file.basic.test.js +++ b/tests/bindings/javascript/file.basic.test.js @@ -34,19 +34,20 @@ test.describe('File basic tests', () => { }); test('Local file', () => { - const file = new loc.File(utils.LOCAL_FILE); + const fileName = utils.resourcePath('unknown_file.txt'); + const file = new loc.File(fileName); assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value); - assert.strictEqual(file.fileName, utils.LOCAL_FILE); + assert.strictEqual(file.fileName, fileName); assert.strictEqual(file.url, ''); - assert.strictEqual(file.path, utils.LOCAL_FILE); + assert.strictEqual(file.path, fileName); assert.deepStrictEqual(file.contents(), Uint8Array.from([])); assertIssues(loc, file, expectedNoIssues); - file.setContents(utils.UNKNOWN_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value); - assert.deepStrictEqual(file.contents(), utils.UNKNOWN_CONTENTS); + assert.deepStrictEqual(file.contents(), utils.fileContents(file.path)); assertIssues(loc, file, expectedUnknownFileIssues); }); @@ -60,47 +61,60 @@ test.describe('File basic tests', () => { assert.deepStrictEqual(file.contents(), Uint8Array.from([])); assertIssues(loc, file, expectedNoIssues); - file.setContents(utils.UNKNOWN_CONTENTS); + const fileContents = utils.fileContents(utils.resourcePath('unknown_file.txt')); + + file.setContents(fileContents); assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value); - assert.deepStrictEqual(file.contents(), utils.UNKNOWN_CONTENTS); + assert.deepStrictEqual(file.contents(), fileContents); assertIssues(loc, file, expectedUnknownFileIssues); }); test('Encoded remote file', () => { - const file = new loc.File(utils.ENCODED_REMOTE_FILE); + const file = new loc.File( + 'https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml' + ); assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value); assert.strictEqual(file.fileName, '/some/path/file'); - assert.strictEqual(file.url, utils.NON_ENCODED_REMOTE_FILE); - assert.strictEqual(file.path, utils.NON_ENCODED_REMOTE_FILE); + assert.strictEqual( + file.url, + 'https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml' + ); + assert.strictEqual( + file.path, + 'https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml' + ); assert.deepStrictEqual(file.contents(), Uint8Array.from([])); assertIssues(loc, file, expectedNoIssues); - file.setContents(utils.UNKNOWN_CONTENTS); + const fileContents = utils.fileContents(utils.resourcePath('unknown_file.txt')); + + file.setContents(fileContents); assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value); - assert.deepStrictEqual(file.contents(), utils.UNKNOWN_CONTENTS); + assert.deepStrictEqual(file.contents(), fileContents); assertIssues(loc, file, expectedUnknownFileIssues); }); test('File manager', () => { const fileManager = loc.FileManager.instance(); + const fileName = utils.resourcePath('file.txt'); assert.strictEqual(fileManager.hasFiles, false); assert.strictEqual(fileManager.fileCount, 0); assert.strictEqual(fileManager.files.length, 0); assert.strictEqual(fileManager.file(0), null); - assert.strictEqual(fileManager.fileFromFileNameOrUrl(utils.LOCAL_FILE), null); + assert.strictEqual(fileManager.fileFromFileNameOrUrl(fileName), null); - const localFile = new loc.File(utils.LOCAL_FILE); + const localFile = new loc.File(fileName); const sameFileManager = loc.FileManager.instance(); assert.strictEqual(sameFileManager.hasFiles, true); assert.strictEqual(sameFileManager.fileCount, 1); assert.strictEqual(sameFileManager.files.length, 1); assert.deepStrictEqual(fileManager.file(0), localFile); - assert.deepStrictEqual(sameFileManager.fileFromFileNameOrUrl(utils.LOCAL_FILE), localFile); + assert.deepStrictEqual(sameFileManager.fileFromFileNameOrUrl(fileName), localFile); const remoteFile = new loc.File(utils.REMOTE_FILE); @@ -116,7 +130,7 @@ test.describe('File basic tests', () => { assert.strictEqual(sameFileManager.fileCount, 1); assert.strictEqual(sameFileManager.files.length, 1); assert.deepStrictEqual(fileManager.file(1), null); - assert.deepStrictEqual(sameFileManager.fileFromFileNameOrUrl(utils.LOCAL_FILE), null); + assert.deepStrictEqual(sameFileManager.fileFromFileNameOrUrl(fileName), null); sameFileManager.manage(localFile); @@ -124,7 +138,7 @@ test.describe('File basic tests', () => { assert.strictEqual(sameFileManager.fileCount, 2); assert.strictEqual(sameFileManager.files.length, 2); assert.deepStrictEqual(fileManager.file(1), localFile); - assert.deepStrictEqual(sameFileManager.fileFromFileNameOrUrl(utils.LOCAL_FILE), localFile); + assert.deepStrictEqual(sameFileManager.fileFromFileNameOrUrl(fileName), localFile); fileManager.reset(); @@ -134,6 +148,6 @@ test.describe('File basic tests', () => { assert.deepStrictEqual(fileManager.file(0), null); assert.deepStrictEqual(fileManager.file(1), null); assert.deepStrictEqual(fileManager.fileFromFileNameOrUrl(utils.REMOTE_FILE), null); - assert.deepStrictEqual(fileManager.fileFromFileNameOrUrl(utils.UNKNOWN_FILE), null); + assert.deepStrictEqual(fileManager.fileFromFileNameOrUrl(utils.resourcePath('unknown_file.txt')), null); }); }); diff --git a/tests/bindings/javascript/file.child.test.js b/tests/bindings/javascript/file.child.test.js index ed53e9d31..ff5347b3a 100644 --- a/tests/bindings/javascript/file.child.test.js +++ b/tests/bindings/javascript/file.child.test.js @@ -27,10 +27,10 @@ test.describe('File type tests', () => { loc.FileManager.instance().reset(); }); - function doTestDataset(omexContents, jsonContents, specificChildFileNames) { - const file = new loc.File(utils.COMBINE_ARCHIVE); + function doTestDataset(number, specificChildFileNames) { + const file = new loc.File(utils.resourcePath('cellml_2.omex')); - file.setContents(omexContents); + file.setContents(utils.fileContents(utils.resourcePath(`api/file/dataset_${number}.omex`))); assert.strictEqual(file.hasChildFiles, true); assert.strictEqual(file.childFileCount, specificChildFileNames.length + 1); @@ -49,35 +49,34 @@ test.describe('File type tests', () => { } assert.strictEqual(file.childFile(++index), null); - assert.strictEqual(file.childFileFromFileName(utils.UNKNOWN_FILE), null); + assert.strictEqual(file.childFileFromFileName(utils.resourcePath('unknown_file.txt')), null); - assert.deepStrictEqual(simulationFile.contents(), jsonContents); + assert.deepStrictEqual( + simulationFile.contents(), + utils.fileContents(utils.resourcePath(`api/file/dataset_${number}.json`)) + ); } test('No child files', () => { - const file = new loc.File(utils.UNKNOWN_FILE); + const filePath = utils.resourcePath('unknown_file.txt'); + const file = new loc.File(filePath); assert.strictEqual(file.hasChildFiles, false); assert.strictEqual(file.childFileCount, 0); assert.strictEqual(file.childFileNames.length, 0); assert.strictEqual(file.childFiles.length, 0); assert.strictEqual(file.childFile(0), null); - assert.strictEqual(file.childFileFromFileName(utils.UNKNOWN_FILE), null); + assert.strictEqual(file.childFileFromFileName(filePath), null); }); test('Dataset 135', () => { - doTestDataset( - utils.fileContents(utils.resourcePath('api/file/dataset_135.omex')), - utils.fileContents(utils.resourcePath('api/file/dataset_135.json')), - ['HumanSAN_Fabbri_Fantini_Wilders_Severi_2017.cellml'] - ); + doTestDataset(135, ['HumanSAN_Fabbri_Fantini_Wilders_Severi_2017.cellml']); }); test('Dataset 157', () => { - doTestDataset( - utils.fileContents(utils.resourcePath('api/file/dataset_157.omex')), - utils.fileContents(utils.resourcePath('api/file/dataset_157.json')), - ['fabbri_et_al_based_composite_SAN_model.cellml', 'fabbri_et_al_based_composite_SAN_model.sedml'] - ); + doTestDataset(157, [ + 'fabbri_et_al_based_composite_SAN_model.cellml', + 'fabbri_et_al_based_composite_SAN_model.sedml' + ]); }); }); diff --git a/tests/bindings/javascript/file.coverage.test.js b/tests/bindings/javascript/file.coverage.test.js index f650e4b74..7c7f6722d 100644 --- a/tests/bindings/javascript/file.coverage.test.js +++ b/tests/bindings/javascript/file.coverage.test.js @@ -28,7 +28,7 @@ test.describe('File coverage tests', () => { }); test('Empty file', () => { - const file = new loc.File(utils.UNKNOWN_FILE); + const file = new loc.File(utils.resourcePath('unknown_file.txt')); file.setContents(null); @@ -36,7 +36,7 @@ test.describe('File coverage tests', () => { }); test('File with null character', () => { - const file = new loc.File(utils.UNKNOWN_FILE); + const file = new loc.File(utils.resourcePath('unknown_file.txt')); file.setContents(Uint8Array.from([0])); @@ -44,14 +44,15 @@ test.describe('File coverage tests', () => { }); test('SED-ML file with no parent', () => { - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); - file.setContents(utils.SEDML_CONTENTS); + file.setContents(utils.fileContents(file.path)); }); test('Same local file', () => { - const file1 = new loc.File(utils.LOCAL_FILE); - const file2 = new loc.File(utils.LOCAL_FILE); + const filePath = utils.resourcePath('file.txt'); + const file1 = new loc.File(filePath); + const file2 = new loc.File(filePath); assert.deepStrictEqual(file1, file2); }); @@ -64,10 +65,10 @@ test.describe('File coverage tests', () => { }); test('Unmanage file with children', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('cellml_2.omex')); const fileManager = loc.FileManager.instance(); - file.setContents(utils.COMBINE_ARCHIVE_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(fileManager.fileCount, 3); diff --git a/tests/bindings/javascript/file.i18n.test.js b/tests/bindings/javascript/file.i18n.test.js index fc72dda56..00f3ca327 100644 --- a/tests/bindings/javascript/file.i18n.test.js +++ b/tests/bindings/javascript/file.i18n.test.js @@ -28,13 +28,13 @@ test.describe('File i18n tests', () => { }); test('Arabic files', () => { - const cellmlFile = new loc.File('file.cellml'); - const sedmlFile = new loc.File('file.sedml'); - const omexFile = new loc.File('file.omex'); + const cellmlFile = new loc.File(utils.resourcePath('i18n/ملف/file.cellml')); + const sedmlFile = new loc.File(utils.resourcePath('i18n/ملف/file.sedml')); + const omexFile = new loc.File(utils.resourcePath('i18n/ملف/file.omex')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/ملف/file.cellml'))); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/ملف/file.sedml'))); - omexFile.setContents(utils.fileContents(utils.resourcePath('i18n/ملف/file.omex'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); + omexFile.setContents(utils.fileContents(omexFile.path)); assert.strictEqual(cellmlFile.type.value, loc.File.Type.CELLML_FILE.value); assert.strictEqual(sedmlFile.type.value, loc.File.Type.SEDML_FILE.value); @@ -42,13 +42,13 @@ test.describe('File i18n tests', () => { }); test('Chinese files', () => { - const cellmlFile = new loc.File('file.cellml'); - const sedmlFile = new loc.File('file.sedml'); - const omexFile = new loc.File('file.omex'); + const cellmlFile = new loc.File(utils.resourcePath('i18n/文件夹/file.cellml')); + const sedmlFile = new loc.File(utils.resourcePath('i18n/文件夹/file.sedml')); + const omexFile = new loc.File(utils.resourcePath('i18n/文件夹/file.omex')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/文件夹/file.cellml'))); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/文件夹/file.sedml'))); - omexFile.setContents(utils.fileContents(utils.resourcePath('i18n/文件夹/file.omex'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); + omexFile.setContents(utils.fileContents(omexFile.path)); assert.strictEqual(cellmlFile.type.value, loc.File.Type.CELLML_FILE.value); assert.strictEqual(sedmlFile.type.value, loc.File.Type.SEDML_FILE.value); @@ -56,13 +56,13 @@ test.describe('File i18n tests', () => { }); test('Hindi files', () => { - const cellmlFile = new loc.File('file.cellml'); - const sedmlFile = new loc.File('file.sedml'); - const omexFile = new loc.File('file.omex'); + const cellmlFile = new loc.File(utils.resourcePath('i18n/फोल्डर/file.cellml')); + const sedmlFile = new loc.File(utils.resourcePath('i18n/फोल्डर/file.sedml')); + const omexFile = new loc.File(utils.resourcePath('i18n/फोल्डर/file.omex')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/फोल्डर/file.cellml'))); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/फोल्डर/file.sedml'))); - omexFile.setContents(utils.fileContents(utils.resourcePath('i18n/फोल्डर/file.omex'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); + omexFile.setContents(utils.fileContents(omexFile.path)); assert.strictEqual(cellmlFile.type.value, loc.File.Type.CELLML_FILE.value); assert.strictEqual(sedmlFile.type.value, loc.File.Type.SEDML_FILE.value); @@ -70,13 +70,13 @@ test.describe('File i18n tests', () => { }); test('Japanese files', () => { - const cellmlFile = new loc.File('file.cellml'); - const sedmlFile = new loc.File('file.sedml'); - const omexFile = new loc.File('file.omex'); + const cellmlFile = new loc.File(utils.resourcePath('i18n/フォルダ/file.cellml')); + const sedmlFile = new loc.File(utils.resourcePath('i18n/フォルダ/file.sedml')); + const omexFile = new loc.File(utils.resourcePath('i18n/フォルダ/file.omex')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/フォルダ/file.cellml'))); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/フォルダ/file.sedml'))); - omexFile.setContents(utils.fileContents(utils.resourcePath('i18n/フォルダ/file.omex'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); + omexFile.setContents(utils.fileContents(omexFile.path)); assert.strictEqual(cellmlFile.type.value, loc.File.Type.CELLML_FILE.value); assert.strictEqual(sedmlFile.type.value, loc.File.Type.SEDML_FILE.value); @@ -84,13 +84,13 @@ test.describe('File i18n tests', () => { }); test('Russian files', () => { - const cellmlFile = new loc.File('file.cellml'); - const sedmlFile = new loc.File('file.sedml'); - const omexFile = new loc.File('file.omex'); + const cellmlFile = new loc.File(utils.resourcePath('i18n/папка/file.cellml')); + const sedmlFile = new loc.File(utils.resourcePath('i18n/папка/file.sedml')); + const omexFile = new loc.File(utils.resourcePath('i18n/папка/file.omex')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/папка/file.cellml'))); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('i18n/папка/file.sedml'))); - omexFile.setContents(utils.fileContents(utils.resourcePath('i18n/папка/file.omex'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); + omexFile.setContents(utils.fileContents(omexFile.path)); assert.strictEqual(cellmlFile.type.value, loc.File.Type.CELLML_FILE.value); assert.strictEqual(sedmlFile.type.value, loc.File.Type.SEDML_FILE.value); diff --git a/tests/bindings/javascript/file.type.test.js b/tests/bindings/javascript/file.type.test.js index 08c9c3bba..e530acc87 100644 --- a/tests/bindings/javascript/file.type.test.js +++ b/tests/bindings/javascript/file.type.test.js @@ -29,9 +29,9 @@ test.describe('File type tests', () => { }); test('Unknown file', () => { - const file = new loc.File(utils.UNKNOWN_FILE); + const file = new loc.File(utils.resourcePath('unknown_file.txt')); - file.setContents(utils.fileContents(utils.resourcePath(utils.UNKNOWN_FILE))); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.type.value, loc.File.Type.UNKNOWN_FILE.value); assertIssues(loc, file, [ @@ -40,25 +40,25 @@ test.describe('File type tests', () => { }); test('CellML file', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.fileContents(utils.resourcePath(utils.CELLML_FILE))); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.type.value, loc.File.Type.CELLML_FILE.value); }); test('SED-ML file', () => { - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); - file.setContents(utils.fileContents(utils.resourcePath(utils.SEDML_FILE))); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.type.value, loc.File.Type.SEDML_FILE.value); }); test('COMBINE archive', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('cellml_2.omex')); - file.setContents(utils.fileContents(utils.resourcePath(utils.COMBINE_ARCHIVE))); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.type.value, loc.File.Type.COMBINE_ARCHIVE.value); }); diff --git a/tests/bindings/javascript/logger.coverage.test.js b/tests/bindings/javascript/logger.coverage.test.js index e431e921e..7e48ea073 100644 --- a/tests/bindings/javascript/logger.coverage.test.js +++ b/tests/bindings/javascript/logger.coverage.test.js @@ -28,99 +28,99 @@ test.describe('Issue coverage tests', () => { }); test('hasIssues', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.hasIssues, false); }); test('issueCount', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.issueCount, 0); }); test('issues', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.issues.length, 0); }); test('issue()', () => { - const file = new loc.File(utils.ERROR_CELLML_FILE); + const file = new loc.File(utils.resourcePath('error.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('error.cellml'))); + file.setContents(utils.fileContents(file.path)); assert.notStrictEqual(file.issue(0), null); assert.strictEqual(file.issue(file.issueCount), null); }); test('hasErrors', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.hasErrors, false); }); test('errorCount', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.errorCount, 0); }); test('errors', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.errors.length, 0); }); test('error()', () => { - const file = new loc.File(utils.ERROR_CELLML_FILE); + const file = new loc.File(utils.resourcePath('error.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('error.cellml'))); + file.setContents(utils.fileContents(file.path)); assert.notStrictEqual(file.error(0), null); assert.strictEqual(file.error(file.errorCount), null); }); test('hasWarnings', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.hasWarnings, false); }); test('warningCount', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.warningCount, 0); }); test('warnings', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); assert.strictEqual(file.warnings.length, 0); }); test('warning()', () => { - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); - file.setContents(utils.SEDML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -129,9 +129,9 @@ test.describe('Issue coverage tests', () => { }); test('toString()', () => { - const file = new loc.File(utils.ERROR_CELLML_FILE); + const file = new loc.File(utils.resourcePath('error.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('error.cellml'))); + file.setContents(utils.fileContents(file.path)); const issue = file.issue(0); diff --git a/tests/bindings/javascript/ode.model.js b/tests/bindings/javascript/ode.model.js index 79d725d12..a1da697ce 100644 --- a/tests/bindings/javascript/ode.model.js +++ b/tests/bindings/javascript/ode.model.js @@ -29,7 +29,7 @@ export function run( algebraicValues, algebraicPrecisions ) { - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; simulation.outputEndTime = 50.0; simulation.numberOfSteps = 50000; @@ -38,7 +38,7 @@ export function run( instance.run(); - const instanceTask = instance.tasks.get(0); + const instanceTask = instance.tasks[0]; assertValues( instanceTask, diff --git a/tests/bindings/javascript/res/index.html b/tests/bindings/javascript/res/index.html index 22454274d..d0bd53fdf 100644 --- a/tests/bindings/javascript/res/index.html +++ b/tests/bindings/javascript/res/index.html @@ -153,29 +153,29 @@ diff --git a/tests/bindings/javascript/res/res/libopencor.js b/tests/bindings/javascript/res/res/libopencor.js index 5d927b89e..c26f347c6 100644 --- a/tests/bindings/javascript/res/res/libopencor.js +++ b/tests/bindings/javascript/res/res/libopencor.js @@ -255,7 +255,7 @@ $(() => { return; } - simulation = document.simulations.get(0); + simulation = document.simulations[0]; if (simulation?.hasIssues) { showIssues(simulation.issues); @@ -271,7 +271,7 @@ $(() => { return; } - instanceTask = instance.tasks.get(0); + instanceTask = instance.tasks[0]; if (instanceTask?.hasIssues) { showIssues(instanceTask.issues); diff --git a/tests/bindings/javascript/sed.basic.test.js b/tests/bindings/javascript/sed.basic.test.js index 8404bbaa1..69818b174 100644 --- a/tests/bindings/javascript/sed.basic.test.js +++ b/tests/bindings/javascript/sed.basic.test.js @@ -35,9 +35,9 @@ test.describe('Sed basic tests', () => { }); test('Unknown file', () => { - const file = new loc.File(utils.UNKNOWN_FILE); + const file = new loc.File(utils.resourcePath('unknown_file.txt')); - file.setContents(utils.UNKNOWN_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -47,9 +47,9 @@ test.describe('Sed basic tests', () => { }); test('CellML file', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -57,15 +57,15 @@ test.describe('Sed basic tests', () => { }); test('SED-ML file', () => { - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); - file.setContents(utils.SEDML_CONTENTS); + file.setContents(utils.fileContents(file.path)); let document = new loc.SedDocument(file); assert.strictEqual(document.hasIssues, true); - new loc.File(utils.CELLML_FILE); + new loc.File(utils.resourcePath('cellml_2.cellml')); document = new loc.SedDocument(file); @@ -73,15 +73,15 @@ test.describe('Sed basic tests', () => { }); test('SED-ML file with absolute CellML file', () => { - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/absolute_cellml_file.sedml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/absolute_cellml_file.sedml'))); + file.setContents(utils.fileContents(file.path)); let document = new loc.SedDocument(file); assert.strictEqual(document.hasIssues, true); - new loc.File(utils.LOCAL_FILE); + new loc.File(utils.resourcePath('file.txt')); document = new loc.SedDocument(file); @@ -89,9 +89,9 @@ test.describe('Sed basic tests', () => { }); test('SED-ML file with remote CellML file', () => { - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/remote_cellml_file.sedml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/remote_cellml_file.sedml'))); + file.setContents(utils.fileContents(file.path)); let document = new loc.SedDocument(file); @@ -105,9 +105,9 @@ test.describe('Sed basic tests', () => { }); test('COMBINE archive', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('cellml_2.omex')); - file.setContents(utils.COMBINE_ARCHIVE_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -115,9 +115,9 @@ test.describe('Sed basic tests', () => { }); test('COMBINE archive with no manifest file', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/sed/no_manifest_file.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/no_manifest_file.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -130,9 +130,9 @@ test.describe('Sed basic tests', () => { }); test('COMBINE archive with no master file', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/sed/no_master_file.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/no_master_file.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -145,9 +145,9 @@ test.describe('Sed basic tests', () => { }); test('COMBINE archive with unknown direct CellML file', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/sed/unknown_direct_cellml_file.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/unknown_direct_cellml_file.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -160,9 +160,9 @@ test.describe('Sed basic tests', () => { }); test('COMBINE archive with unknown indirect CellML file', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/sed/unknown_indirect_cellml_file.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/unknown_indirect_cellml_file.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -173,9 +173,9 @@ test.describe('Sed basic tests', () => { }); test('COMBINE archive with unknown SED-ML file', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/sed/unknown_sedml_file.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/unknown_sedml_file.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); diff --git a/tests/bindings/javascript/sed.coverage.test.js b/tests/bindings/javascript/sed.coverage.test.js index 44693b791..e9ebd565c 100644 --- a/tests/bindings/javascript/sed.coverage.test.js +++ b/tests/bindings/javascript/sed.coverage.test.js @@ -56,7 +56,7 @@ test.describe('Sed coverage tests', () => { assert.strictEqual(document.models.length, 0); assert.strictEqual(document.addModel(null), false); - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); const model = new loc.SedModel(document, file); assert.deepStrictEqual(model.file, file); @@ -66,7 +66,7 @@ test.describe('Sed coverage tests', () => { assert.strictEqual(document.hasModels, true); assert.strictEqual(document.modelCount, 1); assert.strictEqual(document.models.length, 1); - assert.deepStrictEqual(document.models.get(0), model); + assert.deepStrictEqual(document.models[0], model); assert.deepStrictEqual(document.model(0), model); assert.deepStrictEqual(document.model(1), null); @@ -96,7 +96,7 @@ test.describe('Sed coverage tests', () => { assert.strictEqual(model.hasChanges, true); assert.strictEqual(model.changeCount, 1); assert.strictEqual(model.changes.length, 1); - assert.deepStrictEqual(model.changes.get(0), changeAttribute); + assert.deepStrictEqual(model.changes[0], changeAttribute); assert.deepStrictEqual(model.change(0), changeAttribute); assert.deepStrictEqual(model.change(1), null); @@ -114,7 +114,7 @@ test.describe('Sed coverage tests', () => { }); test('Changes', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File('file.omex'); file.setContents(utils.fileContents(utils.resourcePath('api/sed/sed_changes.omex'))); @@ -202,10 +202,10 @@ test.describe('Sed coverage tests', () => { assert.strictEqual(document.hasSimulations, true); assert.strictEqual(document.simulationCount, 4); assert.strictEqual(document.simulations.length, 4); - assert.deepStrictEqual(document.simulations.get(0), uniform_time_course); - assert.deepStrictEqual(document.simulations.get(1), one_step); - assert.deepStrictEqual(document.simulations.get(2), steady_state); - assert.deepStrictEqual(document.simulations.get(3), analysis); + assert.deepStrictEqual(document.simulations[0], uniform_time_course); + assert.deepStrictEqual(document.simulations[1], one_step); + assert.deepStrictEqual(document.simulations[2], steady_state); + assert.deepStrictEqual(document.simulations[3], analysis); assert.deepStrictEqual(document.simulation(0), uniform_time_course); assert.deepStrictEqual(document.simulation(1), one_step); assert.deepStrictEqual(document.simulation(2), steady_state); @@ -243,7 +243,7 @@ test.describe('Sed coverage tests', () => { assert.strictEqual(document.tasks.length, 0); assert.strictEqual(document.addTask(null), false); - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); const model = new loc.SedModel(document, file); const simulation = new loc.SedUniformTimeCourse(document); const task = new loc.SedTask(document, model, simulation); @@ -256,7 +256,7 @@ test.describe('Sed coverage tests', () => { assert.strictEqual(document.hasTasks, true); assert.strictEqual(document.taskCount, 1); assert.strictEqual(document.tasks.length, 1); - assert.deepStrictEqual(document.tasks.get(0), task); + assert.deepStrictEqual(document.tasks[0], task); assert.deepStrictEqual(document.task(0), task); assert.deepStrictEqual(document.task(1), null); @@ -326,7 +326,7 @@ test.describe('Sed coverage tests', () => { }); test('SedOneStep', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); const document = new loc.SedDocument(file); const simulation = new loc.SedOneStep(document); @@ -338,7 +338,7 @@ test.describe('Sed coverage tests', () => { }); test('SedUniformTimeCourse', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); const document = new loc.SedDocument(file); const simulation = new loc.SedUniformTimeCourse(document); @@ -359,18 +359,18 @@ test.describe('Sed coverage tests', () => { }); test('SedInstanceAndSedInstanceTaskDifferentialModel', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const solver = document.simulations.get(0).odeSolver; + const solver = document.simulations[0].odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; solver.upperHalfBandwidth = -1; const instance = document.instantiate(); - const instanceTask = instance.tasks.get(0); + const instanceTask = instance.tasks[0]; assert.strictEqual(instance.hasTasks, true); assert.strictEqual(instance.taskCount, 1); @@ -443,14 +443,14 @@ test.describe('Sed coverage tests', () => { }); test('SedInstanceAndSedInstanceTaskNonDifferentialModel', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); - const instanceTask = instance.tasks.get(0); + const instanceTask = instance.tasks[0]; assert.strictEqual(instanceTask.voi.length, 0); assert.deepStrictEqual(instanceTask.voiAsArray, emptyFloat64Array); @@ -471,15 +471,17 @@ test.describe('Sed coverage tests', () => { }); test('SedDocument', () => { - let file = new loc.File(utils.HTTP_REMOTE_CELLML_FILE); + // Note: the three following URLs use http rather than https to help with coverage testing. + + let file = new loc.File('http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml'); new loc.SedDocument(file); - file = new loc.File(utils.HTTP_REMOTE_SEDML_FILE); + file = new loc.File('http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml'); new loc.SedDocument(file); - file = new loc.File(utils.HTTP_REMOTE_COMBINE_ARCHIVE); + file = new loc.File('http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex'); new loc.SedDocument(file); }); @@ -487,12 +489,12 @@ test.describe('Sed coverage tests', () => { test('Solver', () => { // Get the duplicate() method of different solvers to be covered. - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; let solver = new loc.SolverForwardEuler(); simulation.odeSolver = solver; @@ -535,13 +537,13 @@ test.describe('Sed coverage tests', () => { }); test('Math', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/math.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/math.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); - const instanceTask = instance.tasks.get(0); + const instanceTask = instance.tasks[0]; assert.strictEqual(instanceTask.constantCount, 0); assert.strictEqual(instanceTask.computedConstantCount, 37); @@ -604,9 +606,9 @@ test.describe('Sed coverage tests', () => { }); test('KINSOL with Inf and/or NaN values', () => { - const file = new loc.File('kinsol_with_inf_and_or_nan_values.cellml'); + const file = new loc.File(utils.resourcePath('api/sed/kinsol_with_inf_and_or_nan_values.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/kinsol_with_inf_and_or_nan_values.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -620,15 +622,13 @@ test.describe('Sed coverage tests', () => { }); test('SED-ML file with nlaAlgorithm and NLA algorithm', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_nla_algorithm_and_nla_algorithm.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_nla_algorithm_and_nla_algorithm.sedml')); - sedmlFile.setContents( - utils.fileContents(utils.resourcePath('api/sed/dae/model_nla_algorithm_and_nla_algorithm.sedml')) - ); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -641,13 +641,13 @@ test.describe('Sed coverage tests', () => { }); test('SED-ML file with several nlaAlgorithms', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_several_nla_algorithms.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_several_nla_algorithms.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_several_nla_algorithms.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -660,13 +660,13 @@ test.describe('Sed coverage tests', () => { }); test('SED-ML file with unknown NLA algorithm', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_unknown_nla_algorithm.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_unknown_nla_algorithm.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_unknown_nla_algorithm.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -679,25 +679,25 @@ test.describe('Sed coverage tests', () => { }); test('SED-ML file branch coverage', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_branch_coverage.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_branch_coverage.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_branch_coverage.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); new loc.SedDocument(sedmlFile); }); test('SED-ML file with no NLA algorithm', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_no_nla_algorithm.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_no_nla_algorithm.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_no_nla_algorithm.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -710,15 +710,13 @@ test.describe('Sed coverage tests', () => { }); test('Legacy SED-ML file with NLA algorithm and NLA solver', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_nla_algorithm_and_nla_solver.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_nla_algorithm_and_nla_solver.sedml')); - sedmlFile.setContents( - utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_nla_algorithm_and_nla_solver.sedml')) - ); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -731,13 +729,13 @@ test.describe('Sed coverage tests', () => { }); test('Legacy SED-ML file with several NLA solvers', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_several_nla_solvers.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_several_nla_solvers.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_several_nla_solvers.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -750,37 +748,37 @@ test.describe('Sed coverage tests', () => { }); test('Legacy SED-ML file with unknown namespace', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_unknown_namespace.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_unknown_namespace.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_unknown_namespace.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); new loc.SedDocument(sedmlFile); }); test('Legacy SED-ML file with unknown element', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_unknown_element.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_unknown_element.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_unknown_element.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); new loc.SedDocument(sedmlFile); }); test('Legacy SED-ML file with unknown NLA solver', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_unknown_nla_solver.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_unknown_nla_solver.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_unknown_nla_solver.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -793,41 +791,37 @@ test.describe('Sed coverage tests', () => { }); test('Legacy SED-ML file with unknown property namespace', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_unknown_property_namespace.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_unknown_property_namespace.sedml')); - sedmlFile.setContents( - utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_unknown_property_namespace.sedml')) - ); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); new loc.SedDocument(sedmlFile); }); test('Legacy SED-ML file with unknown property element', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_unknown_property_element.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_unknown_property_element.sedml')); - sedmlFile.setContents( - utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_unknown_property_element.sedml')) - ); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); new loc.SedDocument(sedmlFile); }); test('Legacy SED-ML file with unknown property', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy_unknown_property.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy_unknown_property.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy_unknown_property.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); @@ -835,4 +829,10 @@ test.describe('Sed coverage tests', () => { [loc.Issue.Type.WARNING, "SED-ML file: the NLA solver property 'Unknown' is not recognised. It will be ignored."] ]); }); + + test('SED-ML file with bare filename', () => { + const file = new loc.File('cellml_2.sedml'); + + file.setContents(utils.fileContents(utils.resourcePath('cellml_2.sedml'))); + }); }); diff --git a/tests/bindings/javascript/sed.instance.test.js b/tests/bindings/javascript/sed.instance.test.js index 52776f003..a56950f26 100644 --- a/tests/bindings/javascript/sed.instance.test.js +++ b/tests/bindings/javascript/sed.instance.test.js @@ -38,9 +38,9 @@ test.describe('Sed instance tests', () => { }); test('Invalid CellML file', () => { - const file = new loc.File(utils.ERROR_CELLML_FILE); + const file = new loc.File(utils.resourcePath('error.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('error.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -55,9 +55,9 @@ test.describe('Sed instance tests', () => { }); test('Overconstrained CellML file', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/overconstrained.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/overconstrained.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -72,9 +72,9 @@ test.describe('Sed instance tests', () => { }); test('Underconstrained CellML file', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/underconstrained.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/underconstrained.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -89,9 +89,9 @@ test.describe('Sed instance tests', () => { }); test('Unsuitably constrained CellML file', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/unsuitably_constrained.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/unsuitably_constrained.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -110,9 +110,9 @@ test.describe('Sed instance tests', () => { }); test('Algebraic model', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/algebraic.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/algebraic.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -123,12 +123,12 @@ test.describe('Sed instance tests', () => { }); test('ODE model', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const cvode = simulation.odeSolver; cvode.maximumNumberOfSteps = 10; @@ -153,13 +153,13 @@ test.describe('Sed instance tests', () => { }); test('ODE model with no ODE solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - document.simulations.get(0).odeSolver = null; + document.simulations[0].odeSolver = null; const instance = document.instantiate(); @@ -172,12 +172,12 @@ test.describe('Sed instance tests', () => { }); test('NLA model', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const kinsol = simulation.nlaSolver; kinsol.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -200,13 +200,13 @@ test.describe('Sed instance tests', () => { }); test('NLA model with no NLA solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - document.simulations.get(0).nlaSolver = null; + document.simulations[0].nlaSolver = null; const instance = document.instantiate(); @@ -219,12 +219,12 @@ test.describe('Sed instance tests', () => { }); test('DAE model', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/dae.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/dae.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const kinsol = simulation.nlaSolver; kinsol.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -258,12 +258,12 @@ test.describe('Sed instance tests', () => { }); test('DAE model with no ODE or NLA solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/dae.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/dae.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; simulation.odeSolver = null; simulation.nlaSolver = null; @@ -283,9 +283,9 @@ test.describe('Sed instance tests', () => { }); test('COMBINE archive', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('cellml_2.omex')); - file.setContents(utils.COMBINE_ARCHIVE_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -296,9 +296,9 @@ test.describe('Sed instance tests', () => { }); test('COMBINE archive with CellML file as master file', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/sed/cellml_file_as_master_file.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/cellml_file_as_master_file.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -307,9 +307,9 @@ test.describe('Sed instance tests', () => { }); test('DAE model from CellML file', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -325,19 +325,19 @@ test.describe('Sed instance tests', () => { }); test('DAE model from SED-ML file', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); assert.strictEqual(document.hasIssues, false); - const nlaSolver = document.simulations.get(0).nlaSolver; + const nlaSolver = document.simulations[0].nlaSolver; assert.strictEqual(nlaSolver.linearSolver, loc.SolverKinsol.LinearSolver.GMRES); assert.strictEqual(nlaSolver.maximumNumberOfIterations, 123); @@ -354,15 +354,15 @@ test.describe('Sed instance tests', () => { }); test('DAE model from COMBINE archive', () => { - const combineArchive = new loc.File('model.omex'); + const file = new loc.File(utils.resourcePath('api/sed/dae/model.omex')); - combineArchive.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.omex'))); + file.setContents(utils.fileContents(file.path)); - const document = new loc.SedDocument(combineArchive); + const document = new loc.SedDocument(file); assert.strictEqual(document.hasIssues, false); - const nlaSolver = document.simulations.get(0).nlaSolver; + const nlaSolver = document.simulations[0].nlaSolver; assert.strictEqual(nlaSolver.linearSolver, loc.SolverKinsol.LinearSolver.GMRES); assert.strictEqual(nlaSolver.maximumNumberOfIterations, 123); @@ -379,19 +379,19 @@ test.describe('Sed instance tests', () => { }); test('DAE model from legacy SED-ML file', () => { - const cellmlFile = new loc.File('model.cellml'); + const cellmlFile = new loc.File(utils.resourcePath('api/sed/dae/model.cellml')); - cellmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model.cellml'))); + cellmlFile.setContents(utils.fileContents(cellmlFile.path)); - const sedmlFile = new loc.File('model_legacy.sedml'); + const sedmlFile = new loc.File(utils.resourcePath('api/sed/dae/model_legacy.sedml')); - sedmlFile.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy.sedml'))); + sedmlFile.setContents(utils.fileContents(sedmlFile.path)); const document = new loc.SedDocument(sedmlFile); assert.strictEqual(document.hasIssues, false); - const nlaSolver = document.simulations.get(0).nlaSolver; + const nlaSolver = document.simulations[0].nlaSolver; assert.strictEqual(nlaSolver.linearSolver, loc.SolverKinsol.LinearSolver.GMRES); assert.strictEqual(nlaSolver.maximumNumberOfIterations, 123); @@ -408,15 +408,15 @@ test.describe('Sed instance tests', () => { }); test('DAE model from legacy COMBINE archive', () => { - const combineArchive = new loc.File('model_legacy.omex'); + const file = new loc.File(utils.resourcePath('api/sed/dae/model_legacy.omex')); - combineArchive.setContents(utils.fileContents(utils.resourcePath('api/sed/dae/model_legacy.omex'))); + file.setContents(utils.fileContents(file.path)); - const document = new loc.SedDocument(combineArchive); + const document = new loc.SedDocument(file); assert.strictEqual(document.hasIssues, false); - const nlaSolver = document.simulations.get(0).nlaSolver; + const nlaSolver = document.simulations[0].nlaSolver; assert.strictEqual(nlaSolver.linearSolver, loc.SolverKinsol.LinearSolver.GMRES); assert.strictEqual(nlaSolver.maximumNumberOfIterations, 123); @@ -431,4 +431,51 @@ test.describe('Sed instance tests', () => { assert.strictEqual(instance.hasIssues, false); }); + + test('Simulation with initial time', () => { + const file = new loc.File(utils.resourcePath('api/sed/simulation_with_initial_time.omex')); + + file.setContents(utils.fileContents(file.path)); + + const instance = new loc.SedDocument(file).instantiate(); + + assert.strictEqual(instance.hasIssues, false); + + instance.run(); + + assert.strictEqual(instance.hasIssues, false); + + const instanceTask = instance.tasks[0]; + const voi = instanceTask.voi; + + assert.strictEqual(voi.length, 50001); + assert.strictEqual(voi[0], 0.0); + assert.strictEqual(voi[50000], 50.0); + + const x = instanceTask.state(0); + const y = instanceTask.state(1); + const z = instanceTask.state(2); + + assert.strictEqual(x.length, 50001); + assert.strictEqual(y.length, 50001); + assert.strictEqual(z.length, 50001); + + assert.notStrictEqual(x[0], 1.0); + assert.notStrictEqual(y[0], 1.0); + assert.notStrictEqual(z[0], 1.0); + }); + + test('Simulation with initial time failing', () => { + const file = new loc.File(utils.resourcePath('api/sed/simulation_with_initial_time_failing.omex')); + + file.setContents(utils.fileContents(file.path)); + + const instance = new loc.SedDocument(file).instantiate(); + + assert.strictEqual(instance.hasIssues, false); + + instance.run(); + + assert.strictEqual(instance.hasIssues, true); + }); }); diff --git a/tests/bindings/javascript/sed.serialise.test.js b/tests/bindings/javascript/sed.serialise.test.js index facb5d198..026fd0216 100644 --- a/tests/bindings/javascript/sed.serialise.test.js +++ b/tests/bindings/javascript/sed.serialise.test.js @@ -72,7 +72,7 @@ test.describe('Sed serialise tests', () => { return ` - + @@ -94,42 +94,45 @@ test.describe('Sed serialise tests', () => { } test('Local CellML file with base path', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - assert.strictEqual(document.serialise(utils.SOME_PATH), cvodeExpectedSerialisation('cellml_2.cellml')); + assert.strictEqual(document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml')); }); test('Local CellML file without base path', () => { - const file = new loc.File(utils.LOCAL_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - assert.strictEqual(document.serialise(), cvodeExpectedSerialisation('file:///some/path/file.txt')); + assert.strictEqual( + document.serialise(), + cvodeExpectedSerialisation(`file://${utils.resourcePath()}cellml_2.cellml`) + ); }); test('Relative local CellML file with base path', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); assert.strictEqual( - document.serialise(`${utils.SOME_PATH}/../..`), - cvodeExpectedSerialisation('some/path/cellml_2.cellml') + document.serialise(`${utils.resourcePath()}/../..`), + cvodeExpectedSerialisation('tests/res/cellml_2.cellml') ); }); test('Relative local CellML file without base path', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File('cellml_2.cellml'); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(utils.resourcePath('cellml_2.cellml'))); const document = new loc.SedDocument(file); @@ -139,7 +142,7 @@ test.describe('Sed serialise tests', () => { test('Remote CellML file with base path', () => { const file = new loc.File(utils.REMOTE_FILE); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(utils.resourcePath('cellml_2.cellml'))); const document = new loc.SedDocument(file); @@ -149,7 +152,7 @@ test.describe('Sed serialise tests', () => { test('Remote CellML file without base path', () => { const file = new loc.File(utils.REMOTE_FILE); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(utils.resourcePath('cellml_2.cellml'))); const document = new loc.SedDocument(file); @@ -164,7 +167,7 @@ test.describe('Sed serialise tests', () => { test('Relative remote CellML file with base path', () => { const file = new loc.File(utils.REMOTE_FILE); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(utils.resourcePath('cellml_2.cellml'))); const document = new loc.SedDocument(file); @@ -178,7 +181,7 @@ test.describe('Sed serialise tests', () => { const expectedSerialisation = ` - + @@ -213,30 +216,30 @@ test.describe('Sed serialise tests', () => { `; - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/dae.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/dae.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - assert.strictEqual(document.serialise(utils.SOME_PATH), expectedSerialisation); + assert.strictEqual(document.serialise(utils.resourcePath('api/sed')), expectedSerialisation); }); test('NLA model', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - assert.strictEqual(document.serialise(utils.SOME_PATH), kinsolExpectedSerialisation()); + assert.strictEqual(document.serialise(utils.resourcePath('api/sed')), kinsolExpectedSerialisation()); }); test('Algebraic model', () => { const expectedSerialisation = ` - + @@ -247,13 +250,13 @@ test.describe('Sed serialise tests', () => { `; - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/algebraic.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/algebraic.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - assert.strictEqual(document.serialise(utils.SOME_PATH), expectedSerialisation); + assert.strictEqual(document.serialise(utils.resourcePath('api/sed')), expectedSerialisation); }); function sedChangeExpectedSerialisation(component, variable, newValue) { @@ -282,13 +285,16 @@ test.describe('Sed serialise tests', () => { assert.strictEqual(changeAttribute.newValue, '123.456789'); const document = new loc.SedDocument(); - const file = new loc.File(utils.SEDML_FILE); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); const model = new loc.SedModel(document, file); assert.strictEqual(model.addChange(changeAttribute), true); assert.strictEqual(document.addModel(model), true); - assert.strictEqual(document.serialise(), sedChangeExpectedSerialisation('component', 'variable', '123.456789')); + assert.strictEqual( + document.serialise(utils.resourcePath()), + sedChangeExpectedSerialisation('component', 'variable', '123.456789') + ); changeAttribute.componentName = 'new_component'; changeAttribute.variableName = 'new_variable'; @@ -303,7 +309,7 @@ test.describe('Sed serialise tests', () => { assert.strictEqual(changeAttribute.newValue, '987.654321'); assert.strictEqual( - document.serialise(), + document.serialise(utils.resourcePath()), sedChangeExpectedSerialisation('new_component', 'new_variable', '987.654321') ); }); @@ -329,31 +335,31 @@ test.describe('Sed serialise tests', () => { `; - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; simulation.odeSolver = new loc.SolverForwardEuler(); - assert.strictEqual(document.serialise(utils.SOME_PATH), expectedSerialisation); + assert.strictEqual(document.serialise(utils.resourcePath()), expectedSerialisation); }); test('CVODE solver with the Adams-Moulton integration method', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.integrationMethod = loc.SolverCvode.IntegrationMethod.ADAMS_MOULTON; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000475': 'Adams-Moulton' }) @@ -361,18 +367,18 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with a functional iteration type', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.iterationType = loc.SolverCvode.IterationType.FUNCTIONAL; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000476': 'Functional' }) @@ -380,18 +386,18 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with a banded linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000477': 'Banded' }) @@ -399,18 +405,18 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with a diagonal linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.DIAGONAL; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000477': 'Diagonal' }) @@ -418,18 +424,18 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with a GMRES linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.GMRES; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000477': 'GMRES' }) @@ -437,18 +443,18 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with a BiCGStab linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BICGSTAB; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000477': 'BiCGStab' }) @@ -456,18 +462,18 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with a TFQMR linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.TFQMR; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000477': 'TFQMR' }) @@ -475,35 +481,35 @@ test.describe('Sed serialise tests', () => { }); test('CVODE solver with no preconditioner', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.preconditioner = loc.SolverCvode.Preconditioner.NO; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000478': 'No' }) ); }); test('CVODE solver with no interpolate solution', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.interpolateSolution = false; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath()), cvodeExpectedSerialisation('cellml_2.cellml', { 'KISAO:0000481': 'false' }) @@ -511,62 +517,71 @@ test.describe('Sed serialise tests', () => { }); test('KINSOL solver with a banded linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; - assert.strictEqual(document.serialise(utils.SOME_PATH), kinsolExpectedSerialisation({ 'KISAO:0000477': 'Banded' })); + assert.strictEqual( + document.serialise(utils.resourcePath('api/sed')), + kinsolExpectedSerialisation({ 'KISAO:0000477': 'Banded' }) + ); }); test('KINSOL solver with a GMRES linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.GMRES; - assert.strictEqual(document.serialise(utils.SOME_PATH), kinsolExpectedSerialisation({ 'KISAO:0000477': 'GMRES' })); + assert.strictEqual( + document.serialise(utils.resourcePath('api/sed')), + kinsolExpectedSerialisation({ 'KISAO:0000477': 'GMRES' }) + ); }); test('KINSOL solver with a BiCGStab linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BICGSTAB; assert.strictEqual( - document.serialise(utils.SOME_PATH), + document.serialise(utils.resourcePath('api/sed')), kinsolExpectedSerialisation({ 'KISAO:0000477': 'BiCGStab' }) ); }); test('KINSOL solver with a TFQMR linear solver', () => { - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/nla.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/nla.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.TFQMR; - assert.strictEqual(document.serialise(utils.SOME_PATH), kinsolExpectedSerialisation({ 'KISAO:0000477': 'TFQMR' })); + assert.strictEqual( + document.serialise(utils.resourcePath('api/sed')), + kinsolExpectedSerialisation({ 'KISAO:0000477': 'TFQMR' }) + ); }); test('One-step simulation', () => { @@ -584,19 +599,19 @@ test.describe('Sed serialise tests', () => { `; - const file = new loc.File(utils.somePath(utils.CELLML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.cellml')); - file.setContents(utils.CELLML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - document.removeSimulation(document.simulations.get(0)); + document.removeSimulation(document.simulations[0]); const simulation = new loc.SedOneStep(document); document.addSimulation(simulation); - assert.strictEqual(document.serialise(utils.SOME_PATH), expectedSerialisation); + assert.strictEqual(document.serialise(utils.resourcePath()), expectedSerialisation); }); test('SED-ML file', () => { @@ -630,9 +645,9 @@ test.describe('Sed serialise tests', () => { `; - const file = new loc.File(utils.somePath(utils.SEDML_FILE)); + const file = new loc.File(utils.resourcePath('cellml_2.sedml')); - file.setContents(utils.SEDML_CONTENTS); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -642,7 +657,7 @@ test.describe('Sed serialise tests', () => { "SED-ML file: the model 'cellml_2.cellml' could not be found in the file manager. It has been automatically added to it." ] ]); - assert.strictEqual(document.serialise(utils.SOME_PATH), expectedSerialisation); + assert.strictEqual(document.serialise(utils.resourcePath()), expectedSerialisation); }); test('SedSimulation', () => { @@ -884,9 +899,9 @@ test.describe('Sed serialise tests', () => { `; - const file = new loc.File(utils.somePath(utils.SEDML_FILE)); + const file = new loc.File(utils.resourcePath('api/sed/simulations.sedml')); - file.setContents(utils.fileContents(utils.resourcePath('api/sed/simulations.sedml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -1052,6 +1067,6 @@ test.describe('Sed serialise tests', () => { "SED-ML file | KINSOL: the linear solver ('KISAO:0000477') cannot be equal to 'Unknown'. It must be equal to 'Dense', 'Banded', 'GMRES', 'BiCGStab', or 'TFQMR'. A Dense linear solver will be used instead." ] ]); - assert.strictEqual(document.serialise(utils.SOME_PATH), expectedSerialisation); + assert.strictEqual(document.serialise(utils.resourcePath('api/sed')), expectedSerialisation); }); }); diff --git a/tests/bindings/javascript/solver.coverage.test.js b/tests/bindings/javascript/solver.coverage.test.js index a4ac83135..d26ad72f4 100644 --- a/tests/bindings/javascript/solver.coverage.test.js +++ b/tests/bindings/javascript/solver.coverage.test.js @@ -29,9 +29,9 @@ test.describe('Solver coverage tests', () => { }); test('ODE changes', () => { - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/solver/ode_sed_changes.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode_sed_changes.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); @@ -80,16 +80,16 @@ test.describe('Solver coverage tests', () => { // • y = -356/27 = -13.185185185185185 // • z = -760/27 = -28.148148148148145 - const file = new loc.File(utils.COMBINE_ARCHIVE); + const file = new loc.File(utils.resourcePath('api/solver/algebraic_sed_changes.omex')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/algebraic_sed_changes.omex'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); instance.run(); - const instanceTask = instance.tasks.get(0); + const instanceTask = instance.tasks[0]; assert.strictEqual(instanceTask.stateCount, 0); assert.strictEqual(instanceTask.rateCount, 0); @@ -97,8 +97,20 @@ test.describe('Solver coverage tests', () => { assert.strictEqual(instanceTask.computedConstantCount, 1); assert.strictEqual(instanceTask.algebraicVariableCount, 3); - assertValue(instanceTask.algebraicVariable(0).get(0), -28.14815, 5); - assertValue(instanceTask.algebraicVariable(1).get(0), -13.18519, 5); - assertValue(instanceTask.algebraicVariable(2).get(0), 33.33333, 5); + assertValue(instanceTask.algebraicVariable(0)[0], -28.14815, 5); + assertValue(instanceTask.algebraicVariable(1)[0], -13.18519, 5); + assertValue(instanceTask.algebraicVariable(2)[0], 33.33333, 5); + }); + + test('toString()', () => { + const file = new loc.File(utils.resourcePath('cellml_2.omex')); + + file.setContents(utils.fileContents(file.path)); + + const document = new loc.SedDocument(file); + const simulation = document.simulations[0]; + const solver = simulation.odeSolver; + + assert.strictEqual(solver.toString(), 'CVODE'); }); }); diff --git a/tests/bindings/javascript/solver.cvode.test.js b/tests/bindings/javascript/solver.cvode.test.js index b7d1cad37..19cbc5e7f 100644 --- a/tests/bindings/javascript/solver.cvode.test.js +++ b/tests/bindings/javascript/solver.cvode.test.js @@ -29,12 +29,12 @@ test.describe('Solver CVODE tests', () => { }); test('Maximum step value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.maximumStep = -1.234; @@ -50,12 +50,12 @@ test.describe('Solver CVODE tests', () => { }); test('Maximum number of steps value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.maximumNumberOfSteps = 0; @@ -71,12 +71,12 @@ test.describe('Solver CVODE tests', () => { }); test('Banded linear solver and upper half-bandwidth value with number too small', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; @@ -93,12 +93,12 @@ test.describe('Solver CVODE tests', () => { }); test('Banded linear solver and upper half-bandwidth value with number too big', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; @@ -115,12 +115,12 @@ test.describe('Solver CVODE tests', () => { }); test('Banded linear solver and lower half-bandwidth value with number too small', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; @@ -137,12 +137,12 @@ test.describe('Solver CVODE tests', () => { }); test('Banded linear solver and lower half-bandwidth value with number too big', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; @@ -159,12 +159,12 @@ test.describe('Solver CVODE tests', () => { }); test('Relative tolerance value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.relativeTolerance = -1.234; @@ -180,12 +180,12 @@ test.describe('Solver CVODE tests', () => { }); test('Absolute tolerance value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.absoluteTolerance = -1.234; @@ -201,9 +201,9 @@ test.describe('Solver CVODE tests', () => { }); test('Solve', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); @@ -226,12 +226,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve without interpolate solution', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.interpolateSolution = false; @@ -255,12 +255,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with Adams-Moulton integration method', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.integrationMethod = loc.SolverCvode.IntegrationMethod.ADAMS_MOULTON; @@ -284,12 +284,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with functional iteration type', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.iterationType = loc.SolverCvode.IterationType.FUNCTIONAL; @@ -313,12 +313,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with banded linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BANDED; @@ -342,12 +342,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with diagonal linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.DIAGONAL; @@ -371,12 +371,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with GMRES linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.GMRES; @@ -400,12 +400,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with Bi-CGstab linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BICGSTAB; @@ -429,12 +429,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with TFQMR linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.TFQMR; @@ -458,12 +458,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with GMRES linear solver and no preconditioner', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.GMRES; @@ -488,12 +488,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with Bi-CGstab linear solver and no preconditioner', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.BICGSTAB; @@ -518,12 +518,12 @@ test.describe('Solver CVODE tests', () => { }); test('Solve with TFQMR linear solver and no preconditioner', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.odeSolver; solver.linearSolver = loc.SolverCvode.LinearSolver.TFQMR; diff --git a/tests/bindings/javascript/solver.forwardeuler.test.js b/tests/bindings/javascript/solver.forwardeuler.test.js index 3814152ed..59687653c 100644 --- a/tests/bindings/javascript/solver.forwardeuler.test.js +++ b/tests/bindings/javascript/solver.forwardeuler.test.js @@ -29,12 +29,12 @@ test.describe('Solver Forward Euler tests', () => { }); test('Step value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverForwardEuler(); solver.step = 0.0; @@ -49,12 +49,12 @@ test.describe('Solver Forward Euler tests', () => { }); test('Solve', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverForwardEuler(); solver.step = 0.0123; diff --git a/tests/bindings/javascript/solver.fourthorderrungekutta.test.js b/tests/bindings/javascript/solver.fourthorderrungekutta.test.js index a6e3e8cc4..52f4cd340 100644 --- a/tests/bindings/javascript/solver.fourthorderrungekutta.test.js +++ b/tests/bindings/javascript/solver.fourthorderrungekutta.test.js @@ -29,12 +29,12 @@ test.describe('Solver Fourth-Order Runge-Kutta tests', () => { }); test('Step value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverFourthOrderRungeKutta(); solver.step = 0.0; @@ -52,12 +52,12 @@ test.describe('Solver Fourth-Order Runge-Kutta tests', () => { }); test('Solve', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverFourthOrderRungeKutta(); solver.step = 0.0123; diff --git a/tests/bindings/javascript/solver.heun.test.js b/tests/bindings/javascript/solver.heun.test.js index 73705c15b..d2e34a850 100644 --- a/tests/bindings/javascript/solver.heun.test.js +++ b/tests/bindings/javascript/solver.heun.test.js @@ -29,12 +29,12 @@ test.describe('Solver Heun tests', () => { }); test('Step value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverHeun(); solver.step = 0.0; @@ -49,12 +49,12 @@ test.describe('Solver Heun tests', () => { }); test('Solve', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverHeun(); solver.step = 0.0123; diff --git a/tests/bindings/javascript/solver.kinsol.test.js b/tests/bindings/javascript/solver.kinsol.test.js index a6a8cc017..8386a5ec2 100644 --- a/tests/bindings/javascript/solver.kinsol.test.js +++ b/tests/bindings/javascript/solver.kinsol.test.js @@ -29,12 +29,12 @@ test.describe('Solver KINSOL tests', () => { }); test('Maximum number of iterations value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.maximumNumberOfIterations = 0; @@ -50,12 +50,12 @@ test.describe('Solver KINSOL tests', () => { }); test('Banded linear solver and upper half-bandwidth value with number too small', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla2.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla2.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -72,12 +72,12 @@ test.describe('Solver KINSOL tests', () => { }); test('Banded linear solver and upper half-bandwidth value with number too big', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -94,12 +94,12 @@ test.describe('Solver KINSOL tests', () => { }); test('Banded linear solver and lower half-bandwidth value with number too small', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla2.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla2.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -116,12 +116,12 @@ test.describe('Solver KINSOL tests', () => { }); test('Banded linear solver and lower half-bandwidth value with number too big', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -144,8 +144,8 @@ test.describe('Solver KINSOL tests', () => { assert.strictEqual(instanceTask.computedConstantCount, 0); assert.strictEqual(instanceTask.algebraicVariableCount, 2); - assertValue(instanceTask.algebraicVariable(0).get(0), 3.0, 5); - assertValue(instanceTask.algebraicVariable(1).get(0), 7.0, 5); + assertValue(instanceTask.algebraicVariable(0)[0], 3.0, 5); + assertValue(instanceTask.algebraicVariable(1)[0], 7.0, 5); } function assertNla2Solution(instanceTask) { @@ -155,31 +155,31 @@ test.describe('Solver KINSOL tests', () => { assert.strictEqual(instanceTask.computedConstantCount, 0); assert.strictEqual(instanceTask.algebraicVariableCount, 3); - assertValue(instanceTask.algebraicVariable(0).get(0), 7.0, 5); - assertValue(instanceTask.algebraicVariable(1).get(0), -5.0, 5); - assertValue(instanceTask.algebraicVariable(2).get(0), 3.0, 5); + assertValue(instanceTask.algebraicVariable(0)[0], 7.0, 5); + assertValue(instanceTask.algebraicVariable(1)[0], -5.0, 5); + assertValue(instanceTask.algebraicVariable(2)[0], 3.0, 5); } test('Solve', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); const instance = document.instantiate(); instance.run(); - assertNla1Solution(instance.tasks.get(0)); + assertNla1Solution(instance.tasks[0]); }); test('Solve with banded linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla2.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla2.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BANDED; @@ -190,16 +190,16 @@ test.describe('Solver KINSOL tests', () => { instance.run(); - assertNla2Solution(instance.tasks.get(0)); + assertNla2Solution(instance.tasks[0]); }); test('Solve with GMRES linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.GMRES; @@ -208,16 +208,16 @@ test.describe('Solver KINSOL tests', () => { instance.run(); - assertNla1Solution(instance.tasks.get(0)); + assertNla1Solution(instance.tasks[0]); }); test('Solve with BiCGStab linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla2.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla2.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.BICGSTAB; @@ -226,16 +226,16 @@ test.describe('Solver KINSOL tests', () => { instance.run(); - assertNla2Solution(instance.tasks.get(0)); + assertNla2Solution(instance.tasks[0]); }); test('Solve with TFQMR linear solver', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/nla1.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/nla1.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = simulation.nlaSolver; solver.linearSolver = loc.SolverKinsol.LinearSolver.TFQMR; @@ -244,6 +244,6 @@ test.describe('Solver KINSOL tests', () => { instance.run(); - assertNla1Solution(instance.tasks.get(0)); + assertNla1Solution(instance.tasks[0]); }); }); diff --git a/tests/bindings/javascript/solver.secondorderrungekutta.test.js b/tests/bindings/javascript/solver.secondorderrungekutta.test.js index 1c1f58b62..52ee8f48c 100644 --- a/tests/bindings/javascript/solver.secondorderrungekutta.test.js +++ b/tests/bindings/javascript/solver.secondorderrungekutta.test.js @@ -29,12 +29,12 @@ test.describe('Solver Second-Order Runge-Kutta tests', () => { }); test('Step value with invalid number', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverSecondOrderRungeKutta(); solver.step = 0.0; @@ -52,12 +52,12 @@ test.describe('Solver Second-Order Runge-Kutta tests', () => { }); test('Solve', () => { - const file = new loc.File(utils.CELLML_FILE); + const file = new loc.File(utils.resourcePath('api/solver/ode.cellml')); - file.setContents(utils.fileContents(utils.resourcePath('api/solver/ode.cellml'))); + file.setContents(utils.fileContents(file.path)); const document = new loc.SedDocument(file); - const simulation = document.simulations.get(0); + const simulation = document.simulations[0]; const solver = new loc.SolverSecondOrderRungeKutta(); solver.step = 0.0123; diff --git a/tests/bindings/javascript/utils.in.js b/tests/bindings/javascript/utils.in.js index 8a3e1b86b..44a13e65d 100644 --- a/tests/bindings/javascript/utils.in.js +++ b/tests/bindings/javascript/utils.in.js @@ -17,36 +17,10 @@ limitations under the License. import assert from 'node:assert'; import { readFileSync } from 'node:fs'; -export const SOME_PATH = '/some/path'; - export const RESOURCE_LOCATION = '@CMAKE_SOURCE_DIR@/tests/res'; -export const UNKNOWN_FILE = 'unknown_file.txt'; -export const ERROR_CELLML_FILE = 'error.cellml'; -export const CELLML_FILE = 'cellml_2.cellml'; -export const SEDML_FILE = 'cellml_2.sedml'; -export const COMBINE_ARCHIVE = 'cellml_2.omex'; - -export const LOCAL_FILE = somePath('file.txt'); - -// Note: the three following URLs use http rather than https to help with coverage testing. -export const HTTP_REMOTE_CELLML_FILE = - 'http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml'; -export const HTTP_REMOTE_SEDML_FILE = - 'http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml'; -export const HTTP_REMOTE_COMBINE_ARCHIVE = - 'http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex'; export const REMOTE_BASE_PATH = 'https://raw.githubusercontent.com/opencor/libopencor/master/tests/res'; export const REMOTE_FILE = 'https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml'; -export const ENCODED_REMOTE_FILE = - 'https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml'; -export const NON_ENCODED_REMOTE_FILE = - 'https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml'; - -export const UNKNOWN_CONTENTS = stringToArrayBuffer('Some unknown contents...'); -export const CELLML_CONTENTS = stringToArrayBuffer(`@CELLML_CONTENTS@`); -export const SEDML_CONTENTS = stringToArrayBuffer(`@SEDML_CONTENTS@`); -export const COMBINE_ARCHIVE_CONTENTS = stringToArrayBuffer(atob('@BASE64_COMBINE_ARCHIVE_CONTENTS@')); export function assertIssues(loc, logger, expectedIssues) { const issues = logger.issues; @@ -114,27 +88,7 @@ export function assertValues( } } -export function allocateMemory(module, arrayBuffer) { - const memPtr = module._malloc(arrayBuffer.length); - - module.HEAPU8.set(arrayBuffer, memPtr); - - return memPtr; -} - -export function freeMemory(module, memPtr) { - module._free(memPtr); -} - -function stringToArrayBuffer(string) { - return Uint8Array.from(string, (c) => c.charCodeAt(0)); -} - -export function somePath(resourceRelativePath) { - return `${SOME_PATH}/${resourceRelativePath}`; -} - -export function resourcePath(resourceRelativePath) { +export function resourcePath(resourceRelativePath = '') { return `${RESOURCE_LOCATION}/${resourceRelativePath}`; } diff --git a/tests/bindings/python/test_file_basic.py b/tests/bindings/python/test_file_basic.py index c5c318b3b..e30468ce4 100644 --- a/tests/bindings/python/test_file_basic.py +++ b/tests/bindings/python/test_file_basic.py @@ -32,12 +32,13 @@ def test_local_file(): - file = loc.File(utils.LocalFile) + file_path = utils.resource_path("file.txt") + file = loc.File(file_path) assert file.type == loc.File.Type.IrretrievableFile - assert file.file_name == utils.LocalFile + assert file.file_name == file_path assert file.url == "" - assert file.path == utils.LocalFile + assert file.path == file_path assert file.contents == [] assert_issues(file, expected_non_existing_file_issues) @@ -47,7 +48,7 @@ def test_existing_relative_local_file(): os.chdir(utils.resource_path()) - file = loc.File(utils.Cellml2File) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert file.contents != [] assert_issues(file, expected_no_issues) @@ -80,15 +81,17 @@ def test_non_existing_relative_local_file(): def test_url_based_local_file(): + file_path = utils.resource_path("file.txt") + if platform.system() == "Windows": - file = loc.File("file:///P:/some/path/file.txt") + file = loc.File("file:///" + utils.forward_slash_path(file_path)) else: - file = loc.File("file:///some/path/file.txt") + file = loc.File("file://" + file_path) assert file.type == loc.File.Type.IrretrievableFile - assert file.file_name == utils.LocalFile + assert file.file_name == file_path assert file.url == "" - assert file.path == utils.LocalFile + assert file.path == file_path assert file.contents == [] assert_issues(file, expected_non_existing_file_issues) @@ -104,26 +107,35 @@ def test_remote_file(): def test_encoded_remote_file(): - file = loc.File(utils.EncodedRemoteFile) + file = loc.File( + "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml" + ) assert file.type == loc.File.Type.CellmlFile assert file.file_name != "" - assert file.url == utils.NonEncodedRemoteFile - assert file.path == utils.NonEncodedRemoteFile + assert ( + file.url + == "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml" + ) + assert ( + file.path + == "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml" + ) assert file.contents != [] def test_local_virtual_file(): - file = loc.File(utils.resource_path(utils.UnknownFile), False) + file_path = utils.resource_path("unknown_file.txt") + file = loc.File(file_path, False) assert file.type == loc.File.Type.UnknownFile - assert file.file_name == utils.resource_path(utils.UnknownFile) + assert file.file_name == file_path assert file.url == "" - assert file.path == utils.resource_path(utils.UnknownFile) + assert file.path == file_path assert file.contents == [] assert_issues(file, expected_no_issues) - some_unknown_contents_list = utils.string_to_list(utils.UnknownContents) + some_unknown_contents_list = utils.text_to_list(utils.text_file_contents(file_path)) file.contents = some_unknown_contents_list @@ -133,7 +145,10 @@ def test_local_virtual_file(): def test_remote_virtual_file(): - file = loc.File(utils.UnknownRemoteFile, False) + file = loc.File( + "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt", + False, + ) assert file.type == loc.File.Type.UnknownFile @@ -142,12 +157,20 @@ def test_remote_virtual_file(): else: assert file.file_name == "/some/path/file" - assert file.url == utils.UnknownRemoteFile - assert file.path == utils.UnknownRemoteFile + assert ( + file.url + == "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt" + ) + assert ( + file.path + == "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt" + ) assert file.contents == [] assert_issues(file, expected_no_issues) - some_unknown_contents_list = utils.string_to_list(utils.UnknownContents) + some_unknown_contents_list = utils.text_to_list( + utils.text_file_contents(utils.resource_path("unknown_file.txt")) + ) file.contents = some_unknown_contents_list @@ -158,14 +181,15 @@ def test_remote_virtual_file(): def test_file_manager(): file_manager = loc.FileManager.instance() + file_path = utils.resource_path("file.txt") assert not file_manager.has_files assert file_manager.file_count == 0 assert len(file_manager) == 0 assert file_manager.file(0) is None - assert file_manager.file(utils.LocalFile) is None + assert file_manager.file(file_path) is None - local_file = loc.File(utils.LocalFile) + local_file = loc.File(file_path) same_file_manager = loc.FileManager.instance() assert same_file_manager.has_files @@ -173,7 +197,7 @@ def test_file_manager(): assert len(file_manager) == 1 assert list(file_manager) == [local_file] assert file_manager.file(0) == local_file - assert same_file_manager.file(utils.LocalFile) == local_file + assert same_file_manager.file(file_path) == local_file remote_file = loc.File(utils.RemoteFile) @@ -189,7 +213,7 @@ def test_file_manager(): assert same_file_manager.file_count == 1 assert len(file_manager) == 1 assert file_manager.file(1) is None - assert same_file_manager.file(utils.LocalFile) is None + assert same_file_manager.file(file_path) is None same_file_manager.manage(local_file) @@ -197,7 +221,7 @@ def test_file_manager(): assert same_file_manager.file_count == 2 assert len(file_manager) == 2 assert file_manager.file(1) == local_file - assert same_file_manager.file(utils.LocalFile) == local_file + assert same_file_manager.file(file_path) == local_file file_manager.reset() @@ -207,4 +231,4 @@ def test_file_manager(): assert file_manager.file(0) is None assert file_manager.file(1) is None assert file_manager.file(utils.RemoteFile) is None - assert file_manager.file(utils.UnknownFile) is None + assert file_manager.file(utils.resource_path("unknown_file.txt")) is None diff --git a/tests/bindings/python/test_file_child.py b/tests/bindings/python/test_file_child.py index 5edf500a1..c38d53fce 100644 --- a/tests/bindings/python/test_file_child.py +++ b/tests/bindings/python/test_file_child.py @@ -39,7 +39,7 @@ def do_test_dataset(number, specific_child_file_names): assert file.child_file(specific_child_file_name) is not None assert file.child_file(index + 1) is None - assert file.child_file(utils.resource_path(utils.UnknownFile)) is None + assert file.child_file(utils.resource_path("unknown_file.txt")) is None assert utils.to_string(simulation_file.contents) == utils.text_file_contents( utils.resource_path("api/file/dataset_" + str(number) + ".json") @@ -47,14 +47,15 @@ def do_test_dataset(number, specific_child_file_names): def test_type_no_child_files(): - file = File(utils.resource_path(utils.UnknownFile)) + file_path = utils.resource_path("unknown_file.txt") + file = File(file_path) assert not file.has_child_files assert file.child_file_count == 0 assert len(file.child_file_names) == 0 assert len(file.child_files) == 0 assert file.child_file(0) is None - assert file.child_file("unknown_file") is None + assert file.child_file(file_path) is None def test_type_dataset_135(): diff --git a/tests/bindings/python/test_file_coverage.py b/tests/bindings/python/test_file_coverage.py index 54900406e..5e6ad6435 100644 --- a/tests/bindings/python/test_file_coverage.py +++ b/tests/bindings/python/test_file_coverage.py @@ -18,7 +18,7 @@ def test_empty_file(): - file = loc.File(utils.LocalFile) + file = loc.File(utils.resource_path("file.txt")) file.contents = [] @@ -26,32 +26,35 @@ def test_empty_file(): def test_file_with_null_character(): - file = loc.File(utils.LocalFile) + file = loc.File(utils.resource_path("file.txt")) - file.contents = utils.string_to_list("\0") + file.contents = utils.text_to_list("\0") assert file.type == loc.File.Type.UnknownFile def test_sedml_file_with_no_parent(): - file = loc.File(utils.Sedml2File) + file = loc.File("cellml_2.sedml") - file.contents = utils.string_to_list(utils.SedmlContents) + file.contents = utils.text_to_list( + utils.text_file_contents(utils.resource_path("cellml_2.sedml")) + ) def test_irretrievable_virtual_file(): - file = loc.File(utils.IrretrievableFile, False) + file = loc.File(utils.resource_path("irretrievable_file.txt"), False) assert not file.has_issues def test_irretrievable_remote_file(): - loc.File(utils.IrretrievableRemoteFile) + loc.File("https://some.domain.com/irretrievable_file.txt") def test_same_local_file(): - file1 = loc.File(utils.LocalFile) - file2 = loc.File(utils.LocalFile) + file_path = utils.resource_path("file.txt") + file1 = loc.File(file_path) + file2 = loc.File(file_path) assert file1.__subclasshook__ == file2.__subclasshook__ @@ -71,7 +74,7 @@ def test_do_not_retrieve_contents(): def test_unmanage_file_with_children(): - file = loc.File(utils.resource_path(utils.Combine2Archive)) + file = loc.File(utils.resource_path("cellml_2.omex")) file_manager = loc.FileManager.instance() assert file_manager.file_count == 3 diff --git a/tests/bindings/python/test_file_i18n.py b/tests/bindings/python/test_file_i18n.py index 34ea2125c..531173d95 100644 --- a/tests/bindings/python/test_file_i18n.py +++ b/tests/bindings/python/test_file_i18n.py @@ -13,7 +13,6 @@ # limitations under the License. import libopencor as loc -import platform import utils diff --git a/tests/bindings/python/test_file_type.py b/tests/bindings/python/test_file_type.py index ca14bc602..0b68e9df6 100644 --- a/tests/bindings/python/test_file_type.py +++ b/tests/bindings/python/test_file_type.py @@ -30,108 +30,116 @@ def test_type_irretrievable_file(): [loc.Issue.Type.Error, "The file does not exist."], ] - file = loc.File(utils.resource_path(utils.IrretrievableFile)) + file = loc.File(utils.resource_path("irretrievable_file.txt")) assert file.type == loc.File.Type.IrretrievableFile assert_issues(file, expected_non_existing_file_issues) def test_type_unknown_file(): - file = loc.File(utils.resource_path(utils.UnknownFile)) + file = loc.File(utils.resource_path("unknown_file.txt")) assert file.type == loc.File.Type.UnknownFile assert_issues(file, expected_unknown_file_issues) def test_type_sbml_file(): - file = loc.File(utils.resource_path(utils.SbmlFile)) + file = loc.File(utils.resource_path("sbml.sbml")) assert file.type == loc.File.Type.UnknownFile assert_issues(file, expected_unknown_file_issues) def test_type_error_sedml_file(): - file = loc.File(utils.resource_path(utils.ErrorSedmlFile)) + file = loc.File(utils.resource_path("error.sedml")) assert file.type == loc.File.Type.SedmlFile def test_type_cellml_1_x_file(): - file = loc.File(utils.resource_path(utils.Cellml1xFile)) + file = loc.File(utils.resource_path("cellml_1_x.cellml")) assert file.type == loc.File.Type.CellmlFile def test_type_sedml_1_x_file(): - file = loc.File(utils.resource_path(utils.Sedml1xFile)) + file = loc.File(utils.resource_path("cellml_1_x.sedml")) assert file.type == loc.File.Type.SedmlFile def test_type_combine_1_x_archive(): - file = loc.File(utils.resource_path(utils.Combine1xArchive)) + file = loc.File(utils.resource_path("cellml_1_x.omex")) assert file.type == loc.File.Type.CombineArchive def test_type_cellml_2_file(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert file.type == loc.File.Type.CellmlFile def test_type_sedml_2_file(): - file = loc.File(utils.resource_path(utils.Sedml2File)) + file = loc.File(utils.resource_path("cellml_2.sedml")) assert file.type == loc.File.Type.SedmlFile def test_type_combine_2_archive(): - file = loc.File(utils.resource_path(utils.Combine2Archive)) + file = loc.File(utils.resource_path("cellml_2.omex")) assert file.type == loc.File.Type.CombineArchive def test_type_unknown_virtual_file(): - file = loc.File(utils.resource_path(utils.UnknownFile), False) + file = loc.File(utils.resource_path("unknown_file.txt"), False) assert file.type == loc.File.Type.UnknownFile assert file.contents == [] - file.contents = utils.string_to_list(utils.UnknownContents) + file.contents = utils.text_to_list( + utils.text_file_contents(utils.resource_path("unknown_file.txt")) + ) assert file.type == loc.File.Type.UnknownFile assert_issues(file, expected_unknown_file_issues) def test_type_cellml_virtual_file(): - file = loc.File(utils.resource_path(utils.Cellml2File), False) + file = loc.File(utils.resource_path("cellml_2.cellml"), False) assert file.type == loc.File.Type.UnknownFile assert file.contents == [] - file.contents = utils.string_to_list(utils.CellmlContents) + file.contents = utils.text_to_list( + utils.text_file_contents(utils.resource_path("cellml_2.cellml")) + ) assert file.type == loc.File.Type.CellmlFile def test_type_sedml_virtual_file(): - file = loc.File(utils.resource_path(utils.Sedml2File), False) + file = loc.File(utils.resource_path("cellml_2.sedml"), False) assert file.type == loc.File.Type.UnknownFile assert file.contents == [] - file.contents = utils.string_to_list(utils.SedmlContents) + file.contents = utils.text_to_list( + utils.text_file_contents(utils.resource_path("cellml_2.sedml")) + ) assert file.type == loc.File.Type.SedmlFile def test_type_combine_virtual_archive(): - file = loc.File(utils.resource_path(utils.Combine2Archive), False) + file = loc.File(utils.resource_path("cellml_2.omex"), False) assert file.type == loc.File.Type.UnknownFile assert file.contents == [] - file.contents = utils.binary_to_list(utils.Base64CombineArchiveContents) + file.contents = utils.binary_to_list( + utils.binary_file_contents(utils.resource_path("cellml_2.omex")) + ) assert file.type == loc.File.Type.CombineArchive diff --git a/tests/bindings/python/test_logger_coverage.py b/tests/bindings/python/test_logger_coverage.py index c5465ea82..e20c14419 100644 --- a/tests/bindings/python/test_logger_coverage.py +++ b/tests/bindings/python/test_logger_coverage.py @@ -18,32 +18,32 @@ def test_has_issues(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert not file.has_issues def test_issue_count(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert file.issue_count == 0 def test_issues(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert len(file.issues) == 0 def test_issue(): - file = loc.File(utils.resource_path(utils.ErrorCellmlFile)) + file = loc.File(utils.resource_path("error.cellml")) assert file.issue(0) is not None assert file.issue(file.issue_count) is None def test_issue_str(): - file = loc.File(utils.resource_path(utils.ErrorCellmlFile)) + file = loc.File(utils.resource_path("error.cellml")) issue = file.issue(0) assert issue is not None @@ -51,50 +51,50 @@ def test_issue_str(): def test_has_errors(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert not file.has_errors def test_error_count(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert file.error_count == 0 def test_errors(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert len(file.errors) == 0 def test_error(): - file = loc.File(utils.resource_path(utils.ErrorCellmlFile)) + file = loc.File(utils.resource_path("error.cellml")) assert file.error(0) is not None assert file.error(file.error_count) is None def test_has_warnings(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert not file.has_warnings def test_warning_count(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert file.warning_count == 0 def test_warnings(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) assert len(file.warnings) == 0 def test_warning(): - file = loc.File(utils.resource_path(utils.Sedml2File)) + file = loc.File(utils.resource_path("cellml_2.sedml")) document = loc.SedDocument(file) assert document.warning(0) is not None diff --git a/tests/bindings/python/test_sed_basic.py b/tests/bindings/python/test_sed_basic.py index cea4fa8c9..38a4b6c2b 100644 --- a/tests/bindings/python/test_sed_basic.py +++ b/tests/bindings/python/test_sed_basic.py @@ -36,26 +36,26 @@ def test_unknown_file(): ], ] - file = loc.File(utils.resource_path(utils.UnknownFile)) + file = loc.File(utils.resource_path("unknown_file.txt")) document = loc.SedDocument(file) assert_issues(document, expected_issues) def test_cellml_file(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) assert not document.has_issues def test_sedml_file(): - file = loc.File(utils.resource_path(utils.Sedml2File)) + file = loc.File(utils.resource_path("cellml_2.sedml")) document = loc.SedDocument(file) assert document.has_issues - needed_file = loc.File(utils.resource_path(utils.Cellml2File)) + needed_file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) @@ -68,7 +68,7 @@ def test_sedml_file_with_absolute_cellml_file(): assert document.has_issues - needed_file = loc.File(utils.LocalFile) + needed_file = loc.File(utils.resource_path("file.txt")) document = loc.SedDocument(file) @@ -89,7 +89,7 @@ def test_sedml_file_with_remote_cellml_file(): def test_combine_archive(): - file = loc.File(utils.resource_path(utils.Combine2Archive)) + file = loc.File(utils.resource_path("cellml_2.omex")) document = loc.SedDocument(file) assert not document.has_issues @@ -176,7 +176,7 @@ def test_irretrievable_file(): ], ] - file = loc.File(utils.resource_path(utils.IrretrievableFile)) + file = loc.File(utils.resource_path("irretrievable_file.txt")) document = loc.SedDocument(file) assert_issues(document, expected_issues) diff --git a/tests/bindings/python/test_sed_coverage.py b/tests/bindings/python/test_sed_coverage.py index b4a76497f..7f36c3100 100644 --- a/tests/bindings/python/test_sed_coverage.py +++ b/tests/bindings/python/test_sed_coverage.py @@ -37,7 +37,7 @@ def test_models(): assert len(document.models) == 0 assert not document.add_model(None) - file = loc.File(utils.LocalFile) + file = loc.File(utils.resource_path("file.txt")) model = loc.SedModel(document, file) assert model.file == file @@ -239,7 +239,7 @@ def test_tasks(): assert len(document.tasks) == 0 assert not document.add_task(None) - file = loc.File(utils.LocalFile) + file = loc.File(utils.resource_path("file.txt")) model = loc.SedModel(document, file) simulation = loc.SedUniformTimeCourse(document) task = loc.SedTask(document, model, simulation) @@ -330,7 +330,7 @@ def test_nla_solver(): def test_sed_one_step(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = loc.SedOneStep(document) @@ -342,7 +342,7 @@ def test_sed_one_step(): def test_sed_uniform_time_course(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = loc.SedUniformTimeCourse(document) @@ -459,20 +459,34 @@ def test_sed_instance_and_sed_instance_task_non_differential_model(): def test_sed_document(): - file = loc.File(utils.resource_path(utils.HttpRemoteCellmlFile)) + # Note: the three following URLs use http rather than https to help with coverage testing. + + file = loc.File( + utils.resource_path( + "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml" + ) + ) loc.SedDocument(file) - file = loc.File(utils.resource_path(utils.HttpRemoteSedmlFile)) + file = loc.File( + utils.resource_path( + "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml" + ) + ) loc.SedDocument(file) - file = loc.File(utils.resource_path(utils.HttpRemoteCombineArchive)) + file = loc.File( + utils.resource_path( + "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex" + ) + ) loc.SedDocument(file) def test_solver(): # Get the duplicate() method of different solvers to be covered. - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) document.simulations[0].ode_solver = loc.SolverForwardEuler() @@ -808,3 +822,11 @@ def test_legacy_sedml_file_unknown_property(): document = loc.SedDocument(sedml_file) assert_issues(document, expected_issues) + + +def test_sedml_file_with_bare_filename(): + file = loc.File("cellml_2.sedml") + + file.contents = utils.text_to_list( + utils.text_file_contents(utils.resource_path("cellml_2.sedml")) + ) diff --git a/tests/bindings/python/test_sed_instance.py b/tests/bindings/python/test_sed_instance.py index c31f308fc..4ef735047 100644 --- a/tests/bindings/python/test_sed_instance.py +++ b/tests/bindings/python/test_sed_instance.py @@ -45,7 +45,7 @@ def test_invalid_cellml_file(): ], ] - file = loc.File(utils.resource_path(utils.ErrorCellmlFile)) + file = loc.File(utils.resource_path("error.cellml")) document = loc.SedDocument(file) instance = document.instantiate() @@ -139,7 +139,7 @@ def run_ode_model(): ], ] - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] cvode = simulation.ode_solver @@ -175,7 +175,7 @@ def test_ode_model_with_no_ode_solver(): ], ] - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) document.simulations[0].ode_solver = None @@ -288,7 +288,7 @@ def test_dae_model_with_no_ode_or_nla_solver(): def test_combine_archive(): - file = loc.File(utils.resource_path(utils.Combine2Archive)) + file = loc.File(utils.resource_path("cellml_2.omex")) document = loc.SedDocument(file) instance = document.instantiate() @@ -351,8 +351,8 @@ def test_dae_model_from_sedml_file(): def test_dae_model_from_combine_archive(): - combine_archive = loc.File(utils.resource_path("api/sed/dae/model.omex")) - document = loc.SedDocument(combine_archive) + file = loc.File(utils.resource_path("api/sed/dae/model.omex")) + document = loc.SedDocument(file) assert not document.has_issues @@ -396,8 +396,8 @@ def test_dae_model_from_legacy_sedml_file(): def test_dae_model_from_legacy_combine_archive(): - combine_archive = loc.File(utils.resource_path("api/sed/dae/model_legacy.omex")) - document = loc.SedDocument(combine_archive) + file = loc.File(utils.resource_path("api/sed/dae/model_legacy.omex")) + document = loc.SedDocument(file) assert not document.has_issues @@ -415,3 +415,48 @@ def test_dae_model_from_legacy_combine_archive(): instance.run() assert not instance.has_issues + + +def test_simulation_with_initial_time(): + file = loc.File(utils.resource_path("api/sed/simulation_with_initial_time.omex")) + document = loc.SedDocument(file) + instance = document.instantiate() + + assert not instance.has_issues + + instance.run() + + assert not instance.has_issues + + instance_task = instance.tasks[0] + voi = instance_task.voi + + assert len(voi) == 50001 + assert voi[0] == 0.0 + assert voi[50000] == 50.0 + + x = instance_task.state(0) + y = instance_task.state(1) + z = instance_task.state(2) + + assert len(x) == 50001 + assert len(y) == 50001 + assert len(z) == 50001 + + assert x[0] != 1.0 + assert y[0] != 1.0 + assert z[0] != 1.0 + + +def test_simulation_with_initial_time_failing(): + file = loc.File( + utils.resource_path("api/sed/simulation_with_initial_time_failing.omex") + ) + document = loc.SedDocument(file) + instance = document.instantiate() + + assert not instance.has_issues + + instance.run() + + assert instance.has_issues diff --git a/tests/bindings/python/test_sed_serialise.py b/tests/bindings/python/test_sed_serialise.py index 3bc6f9d74..9b674ef5c 100644 --- a/tests/bindings/python/test_sed_serialise.py +++ b/tests/bindings/python/test_sed_serialise.py @@ -109,7 +109,7 @@ def kinsol_expected_serialisation(parameters=None): def test_local_cellml_file_with_base_path(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) assert document.serialise(utils.ResourceLocation) == cvode_expected_serialisation( @@ -118,24 +118,23 @@ def test_local_cellml_file_with_base_path(): def test_local_cellml_file_without_base_path(): - file = loc.File(utils.LocalFile) + file_path = utils.resource_path("cellml_2.cellml") + file = loc.File(file_path) - file.contents = utils.string_to_list(utils.CellmlContents) + file.contents = utils.text_to_list(utils.text_file_contents(file_path)) document = loc.SedDocument(file) if platform.system() == "Windows": - assert document.serialise() == cvode_expected_serialisation( - "file:///P:/some/path/file.txt" - ) + expected_url = "file:///" + utils.forward_slash_path(file_path) else: - assert document.serialise() == cvode_expected_serialisation( - "file:///some/path/file.txt" - ) + expected_url = f"file://{file_path}" + + assert document.serialise() == cvode_expected_serialisation(expected_url) def test_relative_local_cellml_file_with_base_path(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) assert document.serialise( @@ -144,9 +143,11 @@ def test_relative_local_cellml_file_with_base_path(): def test_relative_local_cellml_file_without_base_path(): - file = loc.File(utils.Cellml2File) + file = loc.File("cellml_2.cellml") - file.contents = utils.string_to_list(utils.CellmlContents) + file.contents = utils.text_to_list( + utils.text_file_contents(utils.resource_path("cellml_2.cellml")) + ) document = loc.SedDocument(file) @@ -276,12 +277,12 @@ def test_algebraic_model(): assert document.serialise(utils.ResourceLocation) == expected_serialisation -def sed_change_expected_serialisation(component, variable, new_value): - source = ( - "file:///P:/some/path/file.txt" - if platform.system() == "Windows" - else "file:///some/path/file.txt" - ) +def sed_change_expected_serialisation(file_path, component, variable, new_value): + if platform.system() == "Windows": + source = "file:///" + utils.forward_slash_path(file_path) + else: + source = f"file://{file_path}" + return f""" @@ -307,14 +308,14 @@ def test_changes(): assert change_attribute.new_value == "123.456789" document = loc.SedDocument() - file = loc.File(utils.LocalFile) + file = loc.File(utils.resource_path("file.txt")) model = loc.SedModel(document, file) assert model.add_change(change_attribute) assert document.add_model(model) assert document.serialise() == sed_change_expected_serialisation( - "component", "variable", "123.456789" + file.path, "component", "variable", "123.456789" ) change_attribute.component_name = "new_component" @@ -330,7 +331,7 @@ def test_changes(): assert change_attribute.new_value == "987.654321" assert document.serialise() == sed_change_expected_serialisation( - "new_component", "new_variable", "987.654321" + file.path, "new_component", "new_variable", "987.654321" ) @@ -355,7 +356,7 @@ def test_fixed_step_ode_solver(): """ - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] @@ -365,7 +366,7 @@ def test_fixed_step_ode_solver(): def test_cvode_solver_with_adams_moulton_interation_method(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -378,7 +379,7 @@ def test_cvode_solver_with_adams_moulton_interation_method(): def test_cvode_solver_with_functional_iteration_type(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -391,7 +392,7 @@ def test_cvode_solver_with_functional_iteration_type(): def test_cvode_solver_with_banded_linear_solver(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -404,7 +405,7 @@ def test_cvode_solver_with_banded_linear_solver(): def test_cvode_solver_with_diagonal_linear_solver(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -417,7 +418,7 @@ def test_cvode_solver_with_diagonal_linear_solver(): def test_cvode_solver_with_gmres_linear_solver(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -430,7 +431,7 @@ def test_cvode_solver_with_gmres_linear_solver(): def test_cvode_solver_with_bicgstab_linear_solver(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -443,7 +444,7 @@ def test_cvode_solver_with_bicgstab_linear_solver(): def test_cvode_solver_with_tfqmr_linear_solver(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -456,7 +457,7 @@ def test_cvode_solver_with_tfqmr_linear_solver(): def test_cvode_solver_with_no_preconditioner(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -469,7 +470,7 @@ def test_cvode_solver_with_no_preconditioner(): def test_cvode_solver_with_no_interpolate_solution(): - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) simulation = document.simulations[0] solver = simulation.ode_solver @@ -548,7 +549,7 @@ def test_one_step_simulation(): """ - file = loc.File(utils.resource_path(utils.Cellml2File)) + file = loc.File(utils.resource_path("cellml_2.cellml")) document = loc.SedDocument(file) document.remove_simulation(document.simulations[0]) @@ -597,7 +598,7 @@ def test_sedml_file(): """ - file = loc.File(utils.resource_path(utils.Sedml2File)) + file = loc.File(utils.resource_path("cellml_2.sedml")) document = loc.SedDocument(file) assert_issues(document, expected_issues) diff --git a/tests/bindings/python/utils.in.py b/tests/bindings/python/utils.in.py index 9a6c58841..305ce4e7e 100644 --- a/tests/bindings/python/utils.in.py +++ b/tests/bindings/python/utils.in.py @@ -24,43 +24,8 @@ ResourceLocation = "@RESOURCE_LOCATION@" -UnknownFile = "unknown_file.txt" -SbmlFile = "sbml.sbml" -ErrorCellmlFile = "error.cellml" -ErrorSedmlFile = "error.sedml" -Cellml1xFile = "cellml_1_x.cellml" -Sedml1xFile = "cellml_1_x.sedml" -Combine1xArchive = "cellml_1_x.omex" -Cellml2File = "cellml_2.cellml" -Sedml2File = "cellml_2.sedml" -Combine2Archive = "cellml_2.omex" -IrretrievableFile = "irretrievable_file.txt" - - -if platform.system() == "Windows": - LocalFile = "P:\\some\\path\\file.txt" -else: - LocalFile = "/some/path/file.txt" - - -# Note: the three following URLs use http rather than https to help with coverage testing. -HttpRemoteCellmlFile = "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml" -HttpRemoteSedmlFile = "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml" -HttpRemoteCombineArchive = ( - "http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex" -) RemoteBasePath = "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res" RemoteFile = "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml" -EncodedRemoteFile = "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml" -NonEncodedRemoteFile = "https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml" -UnknownRemoteFile = "https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt" -IrretrievableRemoteFile = "https://some.domain.com/irretrievable_file.txt" - - -UnknownContents = "Some unknown contents..." -CellmlContents = """@CELLML_CONTENTS@""" -SedmlContents = """@SEDML_CONTENTS@""" -Base64CombineArchiveContents = base64.b64decode(b"@BASE64_COMBINE_ARCHIVE_CONTENTS@") def assert_issues(logger, expected_issues): @@ -133,20 +98,19 @@ def resource_path(relative_path=""): return os.path.realpath(ResourceLocation + "/" + relative_path) -def string_to_list(string): - return [ord(x) for x in string] - +def forward_slash_path(path): + if platform.system() == "Windows": + return path.replace("\\", "/") -def binary_to_list(string): - return [x for x in string] + return path -def string_to_path(string): - return pathlib.Path(string) +def text_to_list(text): + return [ord(x) for x in text] -def path_to_string(path): - return str(path) +def binary_to_list(binary): + return [x for x in binary] def to_string(array): @@ -156,3 +120,8 @@ def to_string(array): def text_file_contents(file_name): with open(file_name, "r") as file: return file.read() + + +def binary_file_contents(file_name): + with open(file_name, "rb") as file: + return file.read() diff --git a/tests/res/api/sed/simulation_with_initial_time.omex b/tests/res/api/sed/simulation_with_initial_time.omex new file mode 100644 index 000000000..ef9afbf2a Binary files /dev/null and b/tests/res/api/sed/simulation_with_initial_time.omex differ diff --git a/tests/res/api/sed/simulation_with_initial_time_failing.omex b/tests/res/api/sed/simulation_with_initial_time_failing.omex new file mode 100644 index 000000000..fd1c8baf3 Binary files /dev/null and b/tests/res/api/sed/simulation_with_initial_time_failing.omex differ diff --git a/tests/support/cellml/basictests.cpp b/tests/support/cellml/basictests.cpp index cc01bfbab..bf2aae5eb 100644 --- a/tests/support/cellml/basictests.cpp +++ b/tests/support/cellml/basictests.cpp @@ -22,7 +22,7 @@ limitations under the License. TEST(BasicCellmlTest, cellml1xModel) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_1_X_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_1_x.cellml")); auto cellmlFile = libOpenCOR::CellmlFile::create(file); EXPECT_FALSE(cellmlFile->hasIssues()); @@ -30,7 +30,7 @@ TEST(BasicCellmlTest, cellml1xModel) TEST(BasicCellmlTest, cellml2Model) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml")); auto cellmlFile = libOpenCOR::CellmlFile::create(file); EXPECT_FALSE(cellmlFile->hasIssues()); @@ -54,7 +54,7 @@ TEST(BasicCellmlTest, modelWithInvalidImports) TEST(BasicCellmlTest, createCellmlFileWithNonCellmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("unknown_file.txt")); auto cellmlFile = libOpenCOR::CellmlFile::create(file); EXPECT_EQ(cellmlFile, nullptr); diff --git a/tests/support/cellml/runtimetests.cpp b/tests/support/cellml/runtimetests.cpp index 7ed3afe8e..c24872c9a 100644 --- a/tests/support/cellml/runtimetests.cpp +++ b/tests/support/cellml/runtimetests.cpp @@ -22,7 +22,7 @@ limitations under the License. TEST(RuntimeCellmlTest, validRuntime) { - auto file {libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::CELLML_2_FILE))}; + auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.cellml"))}; auto cellmlFile {libOpenCOR::CellmlFile::create(file)}; auto cellmlFileRuntime {cellmlFile->runtime()}; diff --git a/tests/support/combine/basictests.cpp b/tests/support/combine/basictests.cpp index 829f66d2a..83498c676 100644 --- a/tests/support/combine/basictests.cpp +++ b/tests/support/combine/basictests.cpp @@ -22,7 +22,7 @@ limitations under the License. TEST(BasicOmexTest, createCombineArchiveWithNonCombineArchive) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("unknown_file.txt")); auto combineArchive = libOpenCOR::CombineArchive::create(file); EXPECT_EQ(combineArchive, nullptr); diff --git a/tests/support/combine/coveragetests.cpp b/tests/support/combine/coveragetests.cpp index c87f85abc..ad7e935b2 100644 --- a/tests/support/combine/coveragetests.cpp +++ b/tests/support/combine/coveragetests.cpp @@ -22,7 +22,7 @@ limitations under the License. TEST(CoverageOmexTest, file) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::COMBINE_2_ARCHIVE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.omex")); auto combineArchive = libOpenCOR::CombineArchive::create(file); EXPECT_NE(combineArchive->file(0), nullptr); diff --git a/tests/support/sedml/basictests.cpp b/tests/support/sedml/basictests.cpp index 0c01bb100..fa9d1182f 100644 --- a/tests/support/sedml/basictests.cpp +++ b/tests/support/sedml/basictests.cpp @@ -22,7 +22,7 @@ limitations under the License. TEST(BasicCellmlTest, sedmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::SEDML_2_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("cellml_2.sedml")); auto sedmlFile = libOpenCOR::SedmlFile::create(file); EXPECT_FALSE(sedmlFile->hasIssues()); @@ -30,7 +30,7 @@ TEST(BasicCellmlTest, sedmlFile) TEST(BasicSedmlTest, createSedmlFileWithNonSedmlFile) { - auto file = libOpenCOR::File::create(libOpenCOR::resourcePath(libOpenCOR::UNKNOWN_FILE)); + auto file = libOpenCOR::File::create(libOpenCOR::resourcePath("unknown_file.txt")); auto sedmlFile = libOpenCOR::SedmlFile::create(file); EXPECT_EQ(sedmlFile, nullptr); diff --git a/tests/utils.cpp b/tests/utils.cpp index 99720a6ef..ab939c5ec 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -109,15 +109,4 @@ UnsignedChars charArrayToUnsignedChars(const char *pContents) return {pContents, pContents + strlen(pContents)}; // NOLINT } -UnsignedChars base64Decode(const char *pContents) -{ - char *buffer {new char[modp_b64_decode_len(strlen(pContents))]}; - const size_t length {modp_b64_decode(buffer, pContents, strlen(pContents))}; - UnsignedChars res(buffer, buffer + length); // NOLINT - - delete[] buffer; - - return res; -} - } // namespace libOpenCOR diff --git a/tests/utils.in.h b/tests/utils.in.h index ed42ce39a..f871f06a1 100644 --- a/tests/utils.in.h +++ b/tests/utils.in.h @@ -32,39 +32,8 @@ namespace libOpenCOR { static constexpr auto RESOURCE_LOCATION {"@RESOURCE_LOCATION@"}; -static constexpr auto UNKNOWN_FILE {"unknown_file.txt"}; -static constexpr auto SBML_FILE {"sbml.sbml"}; -static constexpr auto ERROR_CELLML_FILE {"error.cellml"}; -static constexpr auto ERROR_SEDML_FILE {"error.sedml"}; -static constexpr auto CELLML_1_X_FILE {"cellml_1_x.cellml"}; -static constexpr auto SEDML_1_X_FILE {"cellml_1_x.sedml"}; -static constexpr auto COMBINE_1_X_ARCHIVE {"cellml_1_x.omex"}; -static constexpr auto CELLML_2_FILE {"cellml_2.cellml"}; -static constexpr auto SEDML_2_FILE {"cellml_2.sedml"}; -static constexpr auto COMBINE_2_ARCHIVE {"cellml_2.omex"}; -static constexpr auto IRRETRIEVABLE_FILE {"irretrievable_file.txt"}; - -#ifdef BUILDING_ON_WINDOWS -static constexpr auto LOCAL_FILE {R"(P:\some\path\file.txt)"}; -#else -static constexpr auto LOCAL_FILE {"/some/path/file.txt"}; -#endif - -// Note: the three following URLs use http rather than https to help with coverage testing. -static constexpr auto HTTP_REMOTE_CELLML_FILE {"http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml"}; -static constexpr auto HTTP_REMOTE_SEDML_FILE {"http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.sedml"}; -static constexpr auto HTTP_REMOTE_COMBINE_ARCHIVE {"http://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.omex"}; static constexpr auto REMOTE_BASE_PATH {"https://raw.githubusercontent.com/opencor/libopencor/master/tests/res"}; static constexpr auto REMOTE_FILE {"https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/cellml_2.cellml"}; -static constexpr auto ENCODED_REMOTE_FILE {"https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO%20BG%20example%203.1.cellml"}; -static constexpr auto NON_ENCODED_REMOTE_FILE {"https://models.physiomeproject.org/workspace/aed/@@rawfile/d4accf8429dbf5bdd5dfa1719790f361f5baddbe/FAIRDO BG example 3.1.cellml"}; -static constexpr auto UNKNOWN_REMOTE_FILE {"https://raw.githubusercontent.com/opencor/libopencor/master/tests/res/unknown_file.txt"}; -static constexpr auto IRRETRIEVABLE_REMOTE_FILE {"https://some.domain.com/irretrievable_file.txt"}; - -static constexpr auto UNKNOWN_CONTENTS {"Some unknown contents..."}; -static constexpr auto CELLML_CONTENTS {"@CELLML_CONTENTS_C@"}; -static constexpr auto SEDML_CONTENTS {"@SEDML_CONTENTS_C@"}; -static constexpr auto BASE64_COMBINE_ARCHIVE_CONTENTS {"@BASE64_COMBINE_ARCHIVE_CONTENTS@"}; typedef struct { @@ -92,10 +61,8 @@ void expectEqualValues(const SedInstanceTaskPtr &pInstanceTask, size_t pIndex, expectEqualValues(pInstanceTask, pIndex, pStateValues, pStateAbsTols, pRateValues, pRateAbsTols, pConstantValues, pConstantAbsTols, pComputedConstantValues, pComputedConstantAbsTols, pAlgebraicValues, pAlgebraicAbsTols) std::string resourcePath(const std::string &pResourceRelativePath = {}); -std::string textFileContents(const std::string &pFileName); +std::string textFileContents(const std::string &pFileName); UnsignedChars charArrayToUnsignedChars(const char *pContents); -UnsignedChars base64Decode(const char *pContents); - } // namespace libOpenCOR