From 57fbb16bd884bdac89519c378786d5b33c90011d Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Fri, 15 Nov 2024 03:48:19 +0900 Subject: [PATCH] Add Advanced Mathematics Test --- app.js | 54 +++++++++++++++++++---------------- data/test-misc.json | 7 ++++- data/test-msoffice.json | 4 +-- data/test-oss-korea-2023.json | 4 +-- testloader.js | 52 +++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 29 deletions(-) diff --git a/app.js b/app.js index 07091b4..fd4b6da 100644 --- a/app.js +++ b/app.js @@ -45,7 +45,7 @@ var console = { }, _echoCallback: null, _echo: function(args, type) { - var message = ""; + var messages = []; var params = { type: type, scope: [], @@ -53,32 +53,38 @@ var console = { datetime: new Date().toISOString() }; - if (args.length > 0) { - if (typeof args[0] === "string") { - // if not type is "log", then "{type}: {message}" - if (typeof type !== "undefined") { - message += (type + ": " + this._join(args)); - } else { - message += this._join(args); - } - this._echoDefault(message); - this._messages.push(message); - params.message = message; - } else if (typeof args[0] === "object") { - if ('message' in args[0]) { - if (typeof type !== "undefined") { - message += (type + ": " + args[0].message); + var argl = args.length; + for (var i = 0; i < argl; i++) { + switch (typeof args[i]) { + case "string": + messages.push(args[i]); + break; + + case "number": + case "boolean": + messages.push(String(args[i])); + break; + + case "object": + if ("message" in args[i]) { + messages.push(args[i].message); + for (var k in args[i]) { + params[k] = args[i][k]; + } } else { - message += args[0].message; + messages.push("[object Object]"); } - } - this._echoDefault(message); - this._messages.push(args[0].message); - for (var k in args[0]) { - params[k] = args[0][k]; - } + break; + + case "unknown": + messages.push("[unknown]"); + break; } } + + var message = messages.join(' '); + this._echoDefault(message); + this._messages.push(message); if (params.scope.length > 0 && this._echoCallback != null) { try { @@ -646,7 +652,7 @@ var is = require("app/assets/js/is-0.9.0.min"); //console.log(new Intl.NumberFormat().format(1234567890.123456)); // numbers.js - Advanced Mathematics Library for Node.js and JavaScript -var numbers = require("app/assets/js/numbers-0.7.0.wsh") +var numbers = require("app/assets/js/numbers-0.7.0.wsh"); // linq.js - LINQ for JavaScript var Enumerable = require("app/assets/js/linq-4.0.2.wsh")._default; diff --git a/data/test-misc.json b/data/test-misc.json index 30da10a..fc04e9e 100644 --- a/data/test-misc.json +++ b/data/test-misc.json @@ -1,6 +1,6 @@ { "description": "WelsonJS test profile (test-misc.json)", - "released": "2024-09-27", + "updated_on": "2024-11-15", "dependencies": { "welsonjs": "0.2.7" }, @@ -100,6 +100,11 @@ "id": "proxy_serp", "description": "HTTP proxy with a SERP provider", "tags": ["Network", "HTTP"] + }, + { + "id": "numbers_test", + "description": "number.js test", + "tags": ["Mathematics"] } ] } diff --git a/data/test-msoffice.json b/data/test-msoffice.json index 1997f94..88c0c5a 100644 --- a/data/test-msoffice.json +++ b/data/test-msoffice.json @@ -1,11 +1,11 @@ { "description": "WelsonJS test profile for Microsoft Office", - "released": "2024-06-02", + "updated_on": "2024-06-02", "dependencies": { "welsonjs": "0.2.7" }, "authors": [ - "Namhyeon Go " + "Namhyeon Go " ], "references": [ "https://github.com/gnh1201/welsonjs", diff --git a/data/test-oss-korea-2023.json b/data/test-oss-korea-2023.json index 0e365c3..be21fe2 100644 --- a/data/test-oss-korea-2023.json +++ b/data/test-oss-korea-2023.json @@ -1,11 +1,11 @@ { "description": "2023 South Korea OSS Contest Test Profile for WelsonJS", - "released": "2023-10-30", + "updated_on": "2023-10-30", "dependencies": { "welsonjs": "0.2.7" }, "authors": [ - "Namhyeon Go " + "Namhyeon Go " ], "references": [ "https://github.com/gnh1201/welsonjs", diff --git a/testloader.js b/testloader.js index c5f97f9..9554bdb 100644 --- a/testloader.js +++ b/testloader.js @@ -1043,6 +1043,58 @@ var test_implements = { .send(); console.log("responseBody:", response.responseBody); + }, + + "numbers_test": function() { + // Riemann integrals + console.log("Test Riemann integrals (with 200 subdivisions)"); + console.log(numbers.calculus.Riemann(Math.sin, -2, 4, 200)); + + // Adaptive simpson quadrature + //console.log("Test Adaptive simpson quadrature (with epsilon .0001)"); + //console.log(numbers.calculus.adaptiveSimpson(Math.sin, -2, 4, .0001)); + + // User-defined function + console.log("Test User-defined functions"); + var myFunc = function(x) { + return 2*Math.pow(x,2) + 1; + } + console.log("Test Riemann sum"); + console.log(numbers.calculus.Riemann(myFunc, -2, 4, 200)); + console.log("Test Adaptive Simpson's Rule"); + console.log(numbers.calculus.adaptiveSimpson(myFunc, -2, 4, .0001)); + + // example array + var array1 = [0, 1, 2]; + var array2 = [3, 4, 5]; + var array = array1.concat(array2); + + // add two matrices + console.log("Test Add two metrices"); + console.log(JSON.stringify(numbers.matrix.addition(array1, array2))); + + // transpose a matrix + //console.log("Test Transpose a matrix"); + //console.log(JSON.stringify(numbers.matrix.transpose(array))); + + // basic check + var number = 3; // number + + console.log("Test Prime Number Check (Simple test)"); + console.log(numbers.prime.simple(number)); + + // Miller-Rabin primality test + console.log("Test Prime Number Check (Miller-Rabin primality test)"); + console.log(numbers.prime.millerRabin(number)); + + // mean, median, mode, standard deviation, random sample generator, correlation, confidence intervals, t-test, chi-square, and more. + console.log("Test mean, median, mode, standard deviation, random sample generator, correlation, confidence intervals, t-test, chi-square, and more."); + console.log(numbers.statistic.mean(array)); + console.log(numbers.statistic.median(array)); + console.log(numbers.statistic.mode(array)); + console.log(numbers.statistic.standardDev(array)); + //console.log(numbers.statistic.randomSample(100, 100, 20)); + console.log(numbers.statistic.correlation(array1, array2)); } };