diff --git a/README.md b/README.md index afc55de..5a3b15d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Interactive data generation and fitting with TensorFlow.js [![](https://github.com/nurlicht/TensorFlow/actions/workflows/node.js.yml/badge.svg)](https://github.com/nurlicht/TensorFlow/actions) +# Interactive data generation and fitting [![](https://github.com/nurlicht/TensorFlow/actions/workflows/node.js.yml/badge.svg)](https://github.com/nurlicht/TensorFlow/actions)[![](https://github.com/nurlicht/TensorFlow/actions/workflows/deno.yml/badge.svg)](https://github.com/nurlicht/TensorFlow/actions) ### Background See the codelab [TensorFlow.js — Making Predictions from 2D Data](https://codelabs.developers.google.com/codelabs/tfjs-training-regression) for an introduction to TenosrFlow.js and also to the use-case and the code here. @@ -17,10 +17,18 @@ See the codelab [TensorFlow.js — Making Predictions from 2D Data](https://code ### Execution - Browser client - - Double-click on the file [index.html](./src/html/index.html) (or open it with your browser of choice). No server is needed. There is no node.js dependency. + - Double-click on the file [index.html](./src/html/index.html) (or open it with your browser of choice). No server is needed. - Node.js client - - Run the script ```npm install``` and then ```npm test```. + - Run the command ```npm install``` and then ```npm test```. - An example of this client is the [GitHub Action](./.github/workflows/node.js.yml) of this project. +- Deno client + - Run the command ```Deno test ./tests/javascript/deno/test.js --allow-read```. + - An example of this client is the [GitHub Action](./.github/workflows/deno.yml) of this project. + - If the main client is a Deno-client, it is recommended that the main code be imported in the test file. The current implementation is based on the restriction to support 3 different clients. + +### CI/CD + - GitHub Action for [node.js](./.github/workflows/node.js.yml) + - GitHub Action for [Deno](./.github/workflows/deno.yml) ### Snapshot of Control-Parameters and Outputs The sliders for ```epochs``` (250 vs. 400) and ```noise``` (2.5% vs. 5%) provide a dynamic and user-defined compromise between accuracy and speed (Note that these stochastic results are reproducible only in a statistical sense). diff --git a/package.json b/package.json index bf6a9eb..423b1f2 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,9 @@ "description": "", "main": "./src/javascript/index.js", "type": "module", - "directories": { - "test": "./test/javascript" - }, + "directories": {}, "scripts": { - "test": "jest" + "test": "jest ./tests/javascript/node" }, "keywords": [], "author": "", diff --git a/src/javascript/index.js b/src/javascript/index.js index 14dd6e1..571ee60 100644 --- a/src/javascript/index.js +++ b/src/javascript/index.js @@ -336,6 +336,12 @@ class Controller { class App { static async run(inputDataParameters) { + // Set inputDataParameters if not done + if (typeof inputDataParameters !== 'object') { + inputDataParameters = InputDataParameters.default(); + console.warn('inputDataParameters was set to defaults.') + } + // Initialize the scatter-plot View.showScatterPlot([]); @@ -385,5 +391,12 @@ class App { } } -exports.App = App; -exports.InputDataParameters = InputDataParameters; \ No newline at end of file +if (typeof Deno !== 'undefined' && Deno.version) { + console.log('Deno is defined.'); +} else if (typeof module !== 'undefined' && module.exports) { + console.log('Node is defined.'); + module.exports.App = App; + module.exports.InputDataParameters = InputDataParameters; +} else { + console.log('Browser is defined.'); +} diff --git a/tests/javascript/deno/test.js b/tests/javascript/deno/test.js new file mode 100644 index 0000000..31fe7a0 --- /dev/null +++ b/tests/javascript/deno/test.js @@ -0,0 +1,20 @@ +import tfjs from 'npm:@tensorflow/tfjs'; +import { assert } from "https://deno.land/std@0.211.0/assert/mod.ts"; +const codeAsString = Deno.readTextFileSync('./src/javascript/index.js'); + +Deno.test('Health-Check', async () => { + assert((await new Promise((res, rej) => res(4))) === 4); +}, 1000); + +Deno.test('TFJS app can be started and the fitted results are valid.', async () => { + const tfjsApi = {tf: tfjs, tfvis: {render: {scatterplot: ()=>{}}}}; + const code = codeAsString + 'App.start(undefined, tfjsApi);'; + const result = await eval(code); + assert(typeof result === 'object') + assert(Array.isArray(result)); + assert(result.length === 2); + assert(Array.isArray(result[0])); + assert(Array.isArray(result[1])); + assert(result[1].length === 400); + assert(result[1][0].x === 0.5); +}, 50000); diff --git a/test/javascript/test.js b/tests/javascript/node/test.js similarity index 93% rename from test/javascript/test.js rename to tests/javascript/node/test.js index 327885f..ede0633 100644 --- a/test/javascript/test.js +++ b/tests/javascript/node/test.js @@ -1,5 +1,5 @@ const tfjs = require('@tensorflow/tfjs'); -const AppModule = require('../../src/javascript/index.js'); +const AppModule = require('../../../src/javascript/index.js'); const App = AppModule.App; const InputDataParameters = AppModule.InputDataParameters;