Add Advanced Mathematics Test

This commit is contained in:
Namhyeon Go 2024-11-15 03:48:19 +09:00
parent 13a8c94bcf
commit 57fbb16bd8
5 changed files with 92 additions and 29 deletions

54
app.js
View File

@ -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;

View File

@ -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"]
}
]
}

View File

@ -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 <gnh1201@gmail.com>"
"Namhyeon Go <abuse@catswords.net>"
],
"references": [
"https://github.com/gnh1201/welsonjs",

View File

@ -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 <gnh1201@gmail.com>"
"Namhyeon Go <abuse@catswords.net>"
],
"references": [
"https://github.com/gnh1201/welsonjs",

View File

@ -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));
}
};