UNPKG

5.65 kBJavaScriptView Raw
1var assert = require('assert'),
2 math = require('../index'),
3 approx = require('../tools/approx');
4
5describe('constants', function() {
6
7 describe('number', function () {
8
9 it('should have pi', function() {
10 approx.equal(math.pi, 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664);
11 approx.equal(math.sin(math.pi / 2), 1);
12 approx.equal(math.PI, math.pi);
13 });
14
15 it('should have tau', function() {
16 approx.equal(math.tau, 6.28318530717959);
17 });
18
19 it('should have phi, golden ratio', function() {
20 approx.equal(math.phi, 1.61803398874989484820458683436563811772030917980576286213545);
21 });
22
23 it('should have e (euler constant)', function() {
24 approx.equal(math.e, 2.71828182845905);
25 assert.equal(math.round(math.add(1,math.pow(math.e, math.multiply(math.pi, math.i))), 5), 0);
26 assert.equal(math.round(math.eval('1+e^(pi*i)'), 5), 0);
27 });
28
29 it('should have LN2', function() {
30 approx.equal(math.LN2, 0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573);
31 });
32
33 it('should have LN10', function() {
34 approx.equal(math.LN10, 2.30258509299404568401799145468436420760110148862877297603332790096757260967735248023599720508959829834196778404228624863);
35 });
36
37 it('should have LOG2E', function() {
38 approx.equal(math.LOG2E, 1.44269504088896340735992468100189213742664595415298593413544940693110921918118507988552662289350634449699751830965254425);
39 });
40
41 it('should have LOG10E', function() {
42 approx.equal(math.LOG10E, 0.43429448190325182765112891891660508229439700580366656611445378316586464920887077472922494933843174831870610674476630373);
43 });
44
45 it('should have PI', function() {
46 approx.equal(math.PI, 3.14159265358979);
47 });
48
49 it('should have SQRT1_2', function() {
50 approx.equal(math.SQRT1_2, 0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851);
51 });
52
53 it('should have SQRT2', function() {
54 approx.equal(math.SQRT2, 1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702);
55 });
56
57 it('should have Infinity', function() {
58 assert.strictEqual(math.Infinity, Infinity);
59 });
60
61 it('should have NaN', function() {
62 assert.ok(isNaN(math.NaN));
63 });
64
65 });
66
67 describe('bignumber', function () {
68 var bigmath = math.create({number: 'BigNumber', precision: 64});
69
70 it('should have bignumber pi', function() {
71 assert.equal(bigmath.pi.toString(), '3.141592653589793238462643383279502884197169399375105820974944592');
72 });
73
74 it('should have bignumber tau', function() {
75 assert.equal(bigmath.tau.toString(), '6.283185307179586476925286766559005768394338798750211641949889184');
76 });
77
78 it('should have bignumber phi, golden ratio', function() {
79 assert.equal(bigmath.phi.toString(), '1.618033988749894848204586834365638117720309179805762862135448623');
80 });
81
82 it('should have bignumber e', function() {
83 assert.equal(bigmath.e.toString(), '2.718281828459045235360287471352662497757247093699959574966967628');
84 });
85
86 it('should have bignumber LN2', function() {
87 assert.equal(bigmath.LN2.toString(), '0.6931471805599453094172321214581765680755001343602552541206800095');
88 });
89
90 it('should have bignumber LN10', function() {
91 assert.equal(bigmath.LN10.toString(), '2.302585092994045684017991454684364207601101488628772976033327901');
92 });
93
94 it('should have bignumber LOG2E', function() {
95 assert.equal(bigmath.LOG2E.toString(), '1.442695040888963407359924681001892137426645954152985934135449407');
96 });
97
98 it('should have bignumber LOG10E', function() {
99 assert.equal(bigmath.LOG10E.toString(), '0.4342944819032518276511289189166050822943970058036665661144537832');
100 });
101
102 it('should have bignumber PI (upper case)', function() {
103 assert.equal(bigmath.PI.toString(), '3.141592653589793238462643383279502884197169399375105820974944592');
104 });
105
106 it('should have bignumber SQRT1_2', function() {
107 assert.equal(bigmath.SQRT1_2.toString(), '0.707106781186547524400844362104849039284835937688474036588339869');
108 });
109
110 it('should have bignumber SQRT2', function() {
111 assert.equal(bigmath.SQRT2.toString(), '1.414213562373095048801688724209698078569671875376948073176679738');
112 });
113
114 it('should have bignumber Infinity', function() {
115 assert(bigmath.Infinity instanceof bigmath.type.BigNumber);
116 assert.strictEqual(bigmath.Infinity.toString(), 'Infinity');
117 });
118
119 it('should have bignumber NaN', function() {
120 assert(bigmath.NaN instanceof bigmath.type.BigNumber);
121 assert.equal(bigmath.NaN.toString(), 'NaN');
122 assert.ok(isNaN(bigmath.NaN));
123 });
124 });
125
126 it('should have i', function() {
127 assert.equal(math.i.re, 0);
128 assert.equal(math.i.im, 1);
129 assert.deepEqual(math.i, math.complex(0,1));
130 assert.deepEqual(math.sqrt(-1), math.i);
131 assert.deepEqual(math.eval('i'), math.complex(0, 1));
132 });
133
134 it('should have true and false', function() {
135 assert.strictEqual(math.true, true);
136 assert.strictEqual(math.false, false);
137 assert.strictEqual(math.eval('true'), true);
138 assert.strictEqual(math.eval('false'), false);
139 });
140
141 it('should have null', function() {
142 assert.strictEqual(math['null'], null);
143 });
144
145 it('should have version number', function() {
146 assert.equal(math.version, require('../package.json').version);
147 });
148
149});
\No newline at end of file