mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
* feat: toBest tests * feat: toBest function initial * fix: tests and function changes * fix: dependencies * new way to handle * updated tests * test updated * tests fixed * cleaned useless tests * cleaned useless condition * fix: missing comments * fix: moved tests * other fix and clean * change test to work with npx mocha "path" -g "toBest" * deleted check large and small value * deleted precision test and fix options to bestprefix * fix: moved toBest tests in correct file * fix: math create * fix: aligned files pre-mr * fix: toBest docs test * fix: lint issues * fix: comments * fix: added a helper function to simplify the test readability * fix: unit.md and units.md docs updated * fix: test on units.length * added post process denormalize for tobest function to string returned value * removed this.clone into format * feat improve incompatible units test * fix assign prefixes * fixed examples * changed order of params of assertUnit * fixed comments and added toBest in knowProblems at doc.test * refactor: update toBest functionality and adjust related tests for accuracy * refactor: remove unnecessary offset initialization in prefix application --------- Co-authored-by: Luca Quercetti <l.quercetti@wecodeyou.it> Co-authored-by: Elia Alesiani <elia.alesiani@gmail.com> Co-authored-by: Jos de Jong <wjosdejong@gmail.com> Co-authored-by: lucaQ <lucaquercetti@gmail.com> Co-authored-by: EliaAlesiani <105418798+EliaAlesiani@users.noreply.github.com>
74 lines
2.4 KiB
HTML
74 lines
2.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>mathjs test</title>
|
|
|
|
<script>
|
|
console.time('load')
|
|
</script>
|
|
<script src="../../lib/browser/math.js" type="text/javascript"></script>
|
|
<script>
|
|
console.timeEnd('load')
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<p>
|
|
Use the mathjs library from the console...
|
|
</p>
|
|
<script>
|
|
// force loading all functions
|
|
console.time('load-lazy')
|
|
var math2 = {}
|
|
Object.keys(math).forEach(function (key) {
|
|
// console.log('key', key)
|
|
math2[key] = math[key]
|
|
})
|
|
console.timeEnd('load-lazy')
|
|
|
|
function print (args) {
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
document.write(arguments[i] + '');
|
|
}
|
|
document.write('<br>');
|
|
}
|
|
|
|
var complex1 = math.complex(3, -4);
|
|
print(complex1.toString());
|
|
|
|
print('sqrt(25) = ' + math.sqrt(25));
|
|
print('sqrt(' + complex1.toString() + ') = ' + math.sqrt(complex1));
|
|
print('sqrt(-4) = ' + math.sqrt(-4));
|
|
|
|
var parser = math.parser();
|
|
|
|
print(math.unit('0.01m').toString());
|
|
print(math.unit('1m').toString());
|
|
print(math.unit('10m').toString());
|
|
print(math.unit('100m').toString());
|
|
print(math.unit('500m').toString());
|
|
print(math.unit('800m').toString());
|
|
print(math.unit('1000m').toString());
|
|
print(math.unit('1100m').toString());
|
|
|
|
print(parser.evaluate('a=[1,2,3;4,5,6]'));
|
|
print(parser.get('a'));
|
|
//print(parser.evaluate('a[1,1]'));
|
|
print(parser.evaluate('a[2,1:2]'));
|
|
print(parser.evaluate('b=2.3'));
|
|
print(parser.evaluate('b + 2'));
|
|
print(parser.evaluate('0.1 + 0.2'));
|
|
|
|
print(math.unit('5cm').toBest(['km', 'm', 'cm', 'mm', 'um', 'nm']).toString());
|
|
print("math.unit(10, 'm').toBest(['mm', 'km'], { offset: 1.5 }) => ", math.unit(10, 'm').toBest(['mm', 'km'], { offset: 1.5 }));
|
|
print("math.unit(10, 'm').toBest(['cm', 'km'], { offset: 0.5 }) => ", math.unit(10, 'm').toBest(['cm', 'km'], { offset: 0.5 }));
|
|
print("math.unit(10, 'm').toBest(['nm', 'km'], { offset: 1.5 }) => ", math.unit(10, 'm').toBest(['nm', 'km'], { offset: 1.5 }));
|
|
print("math.unit(10, 'm').toBest(['um', 'nm'], { offset: 1.5 }) => ", math.unit(10, 'm').toBest(['um', 'nm'], { offset: 1.5 }));
|
|
|
|
print("math.unit(10, 'm').toBest(['Mm', 'km'], { offset: 1.5 }) => ", math.unit(10, 'm').toBest(['Mm', 'km'], { offset: 1.5 }));
|
|
print("math.unit(10, 'm').toBest(['Gm', 'km'], { offset: 1.5 }) => ", math.unit(10, 'm').toBest(['Gm', 'km'], { offset: 1.5 }));
|
|
print("math.unit(2 / 3, 'cm').toBest() => ", math.unit(2 / 3, 'cm').toBest());
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|