-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy pathnumbers-tests.js
924 lines (868 loc) · 31.5 KB
/
numbers-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
const assert = require('assert');
const tasks = require('../src/numbers-tasks');
it.optional = require('../extensions/it-optional');
const forbidden = require('../extensions/forbidden');
describe('core-js-numbers', () => {
it.optional('getRectangleArea should return a square of rectangle', () => {
assert.equal(tasks.getRectangleArea(5, 10), 50);
assert.equal(tasks.getRectangleArea(5, 5), 25);
assert.equal(
forbidden.isCommented(tasks.getRectangleArea),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'getCircleCircumference should return a circumference of circle',
() => {
assert.equal(tasks.getCircleCircumference(5), 31.41592653589793);
assert.equal(tasks.getCircleCircumference(3.14), 19.729201864543903);
assert.equal(tasks.getCircleCircumference(0), 0);
assert.equal(
forbidden.isCommented(tasks.getCircleCircumference),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getAverage should return an average of two numbers', () => {
assert.equal(tasks.getAverage(5, 5), 5);
assert.equal(tasks.getAverage(10, 0), 5);
assert.equal(tasks.getAverage(-3, 3), 0);
assert.equal(
tasks.getAverage(Number.MAX_VALUE - 2, Number.MAX_VALUE),
Number.MAX_VALUE - 1
);
assert.equal(
tasks.getAverage(Number.MAX_VALUE, -Number.MAX_VALUE / 2),
Number.MAX_VALUE / 4
);
assert.equal(
forbidden.isCommented(tasks.getAverage),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'getDistanceBetweenPoints should return a distance between points',
() => {
assert.equal(tasks.getDistanceBetweenPoints(0, 0, 0, 1), 1);
assert.equal(tasks.getDistanceBetweenPoints(0, 0, 1, 0), 1);
assert.equal(
tasks.getDistanceBetweenPoints(-5, 0, 10, -10),
18.027756377319946
);
assert.equal(
forbidden.isCommented(tasks.getDistanceBetweenPoints),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getLinearEquationRoot should return a root of linear equation',
() => {
assert.equal(tasks.getLinearEquationRoot(5, -10), 2);
assert.equal(tasks.getLinearEquationRoot(1, 8), -8);
assert.equal(tasks.getLinearEquationRoot(5, 0), 0);
assert.equal(
forbidden.isCommented(tasks.getLinearEquationRoot),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getAngleBetweenVectors should return a angle (in radians) between two linear vectors',
() => {
assert.equal(tasks.getAngleBetweenVectors(1, 0, 0, 1), Math.PI / 2);
assert.equal(tasks.getAngleBetweenVectors(0, 1, 0, -1), Math.PI);
assert.equal(tasks.getAngleBetweenVectors(0, -1, 1, 0), Math.PI / 2);
assert.equal(tasks.getAngleBetweenVectors(0, 1, 0, 1), 0);
assert.equal(
forbidden.isCommented(tasks.getAngleBetweenVectors),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getLastDigit should return a last digit of the number', () => {
assert.equal(tasks.getLastDigit(100), 0);
assert.equal(tasks.getLastDigit(37), 7);
assert.equal(tasks.getLastDigit(11), 1);
assert.equal(tasks.getLastDigit(5), 5);
assert.equal(tasks.getLastDigit(0), 0);
assert.equal(
forbidden.isCommented(tasks.getLastDigit),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'parseNumberFromString should return a number from the given string representation',
() => {
assert.equal(tasks.parseNumberFromString('100'), 100);
assert.equal(tasks.parseNumberFromString('37'), 37);
assert.equal(tasks.parseNumberFromString('-525.5'), -525.5);
assert.equal(
forbidden.isCommented(tasks.parseNumberFromString),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getParallelepipedDiagonal should return a diagonal length of the rectangular parallepiped',
() => {
assert.equal(tasks.getParallelepipedDiagonal(1, 1, 1), Math.sqrt(3));
assert.equal(tasks.getParallelepipedDiagonal(3, 3, 3), Math.sqrt(27));
assert.equal(tasks.getParallelepipedDiagonal(1, 2, 3), Math.sqrt(14));
assert.equal(
forbidden.isCommented(tasks.getParallelepipedDiagonal),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'roundToPowerOfTen should return an number rounded to specified power of 10',
() => {
assert.equal(tasks.roundToPowerOfTen(1234, 0), 1234);
assert.equal(tasks.roundToPowerOfTen(1234, 1), 1230);
assert.equal(tasks.roundToPowerOfTen(1234, 2), 1200);
assert.equal(tasks.roundToPowerOfTen(1234, 3), 1000);
assert.equal(tasks.roundToPowerOfTen(9678, 0), 9678);
assert.equal(tasks.roundToPowerOfTen(9678, 1), 9680);
assert.equal(tasks.roundToPowerOfTen(9678, 2), 9700);
assert.equal(tasks.roundToPowerOfTen(9678, 3), 10000);
assert.equal(
forbidden.isCommented(tasks.roundToPowerOfTen),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('isPrime should return true if specified number is prime', () => {
assert.equal(tasks.isPrime(2), true, 'number 2 is prime');
assert.equal(tasks.isPrime(3), true, 'number 3 is prime');
assert.equal(tasks.isPrime(4), false, '4 is not a prime number');
assert.equal(tasks.isPrime(5), true, 'number 5 is prime');
assert.equal(tasks.isPrime(6), false, '6 is not a prime number');
assert.equal(tasks.isPrime(7), true, 'number 7 is prime');
assert.equal(tasks.isPrime(8), false, '8 is not a prime number');
assert.equal(tasks.isPrime(9), false, '9 is not a prime number');
assert.equal(tasks.isPrime(10), false, '10 is not a prime number');
assert.equal(tasks.isPrime(11), true, 'number 11 is prime');
assert.equal(tasks.isPrime(12), false, '12 is not a prime number');
assert.equal(tasks.isPrime(13), true, 'number 13 is prime');
assert.equal(tasks.isPrime(113), true, 'number 113 is prime');
assert.equal(tasks.isPrime(119), false, '119 is not a prime number');
assert.equal(
forbidden.isCommented(tasks.isPrime),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'toNumber should convert any value to number or return the default',
() => {
assert.equal(tasks.toNumber(null, 0), 0);
assert.equal(tasks.toNumber('test', 0), 0);
assert.equal(tasks.toNumber('1', 0), 1);
assert.equal(tasks.toNumber(42, 0), 42);
assert.equal(tasks.toNumber(undefined, -1), -1);
assert.equal(
forbidden.isCommented(tasks.toNumber),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getCube returns the cube of the given number', () => {
assert.equal(tasks.getCube(3), 27);
assert.equal(tasks.getCube(-2), -8);
assert.equal(tasks.getCube(0), 0);
});
it.optional(
'getFibonacciNumber returns the Fibonacci number located at the index position',
() => {
assert.equal(tasks.getFibonacciNumber(0), 0);
assert.equal(tasks.getFibonacciNumber(1), 1);
assert.equal(tasks.getFibonacciNumber(2), 1);
assert.equal(tasks.getFibonacciNumber(3), 2);
assert.equal(tasks.getFibonacciNumber(10), 55);
assert.equal(
forbidden.isCommented(tasks.getFibonacciNumber),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getSumToN returns the sum of all numbers from 1 to n', () => {
assert.equal(tasks.getSumToN(5), 15);
assert.equal(tasks.getSumToN(10), 55);
assert.equal(tasks.getSumToN(1), 1);
});
it.optional(
'getSumOfDigits returns the sum of the digits of a given number',
() => {
assert.equal(tasks.getSumOfDigits(123), 6);
assert.equal(tasks.getSumOfDigits(202), 4);
assert.equal(tasks.getSumOfDigits(5), 5);
assert.equal(tasks.getSumOfDigits(101010101010), 6);
assert.equal(
forbidden.isCommented(tasks.getSumOfDigits),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'isPowerOfTwo returns true if the given number is a power of two, false otherwise',
() => {
assert.equal(tasks.isPowerOfTwo(4), true, 'the value 4 is a power of 2');
assert.equal(
tasks.isPowerOfTwo(16),
true,
'the value 16 is a power of 2'
);
assert.equal(
tasks.isPowerOfTwo(15),
false,
'the value 15 is not a power of 2'
);
assert.equal(
tasks.isPowerOfTwo(512),
true,
'the value 512 is a power of 2'
);
assert.equal(
tasks.isPowerOfTwo(1000),
false,
'the value 1000 is not a power of 2'
);
assert.equal(
forbidden.isCommented(tasks.isPowerOfTwo),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getSine the sine of a number', () => {
assert.equal(tasks.getSine(0), 0);
assert.equal(tasks.getSine(Math.PI / 2), 1);
assert.equal(
forbidden.isCommented(tasks.getSine),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'numberToStringInBase returns a string representation of a number in exponential notation',
() => {
assert.equal(tasks.numberToStringInBase(255, 16), 'ff');
assert.equal(tasks.numberToStringInBase(2, 2), '10');
assert.equal(tasks.numberToStringInBase(8, 8), '10');
assert.equal(tasks.numberToStringInBase(123, 2), '1111011');
assert.equal(tasks.numberToStringInBase(-15, 2), '-1111');
assert.equal(tasks.numberToStringInBase(123, 10), '123');
assert.equal(tasks.numberToStringInBase(999, 16), '3e7');
assert.equal(
forbidden.isCommented(tasks.numberToStringInBase),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'toExponential returns a string representation of a number in exponential notation',
() => {
assert.equal(tasks.toExponential(12345, 2), '1.23e+4');
assert.equal(tasks.toExponential(-12345, 3), '-1.235e+4');
assert.equal(tasks.toExponential(12345, 1), '1.2e+4');
assert.equal(
forbidden.isCommented(tasks.toExponential),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'toFixed returns a string representation of a number in fixed-point notation',
() => {
assert.equal(tasks.toFixed(12345, 2), 12345.0);
assert.equal(tasks.toFixed(12.345, 1), 12.3);
assert.equal(
forbidden.isCommented(tasks.toFixed),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'toPrecision returns a string representation of a number in normal notation rounded to precision significant digits',
() => {
assert.equal(tasks.toPrecision(12345, 7), 12345.0);
assert.equal(tasks.toPrecision(12.345, 4), 12.35);
assert.equal(
forbidden.isCommented(tasks.toPrecision),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getNumberValue returns the primitive value of a Number object',
() => {
assert.equal(tasks.getNumberValue(Number(5)), 5);
assert.equal(tasks.getNumberValue(Number(-5)), -5);
assert.equal(tasks.getNumberValue(Number(0)), 0);
assert.equal(
forbidden.isCommented(tasks.getNumberValue),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'isNumber returns a boolean value indicating whether a number or not',
() => {
assert.equal(
tasks.isNumber(Infinity),
false,
'value Infinity is not a number'
);
assert.equal(tasks.isNumber(NaN), false, 'value NaN is not a number');
assert.equal(tasks.isNumber(0), true, 'value 0 is a number');
assert.equal(
tasks.isNumber('a' / 1),
false,
'value "a"/1 is not a number'
);
assert.equal(tasks.isNumber('a'), false, 'value "a" is not a number');
assert.equal(tasks.isNumber(5), true, 'value 5 is a number');
assert.equal(tasks.isNumber('5'), false, 'value "5" is not a number');
assert.equal(tasks.isNumber(null), false, 'value null is not a number');
assert.equal(tasks.isNumber(''), false, 'value "" is not a number');
assert.equal(tasks.isNumber(true), false, 'value true is not a number');
assert.equal(tasks.isNumber(10), true, 'value 10 is a number');
assert.equal(
forbidden.isCommented(tasks.isNumber),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'isInteger returns a boolean value indicating whether a number is an integer or not',
() => {
assert.equal(tasks.isInteger(5), true, 'value 5 is an integer');
assert.equal(tasks.isInteger(5.1), false, 'value 5.1 is not an integer');
assert.equal(tasks.isInteger('5'), false, 'value "5" is not an integer');
assert.equal(
tasks.isInteger(3 / 2),
false,
'value 3/2 is not an integer'
);
assert.equal(
forbidden.isCommented(tasks.isInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getFloatOnString a floating point number or NaN', () => {
assert.equal(tasks.getFloatOnString('4.567abcdefgh'), 4.567);
assert.equal(tasks.getFloatOnString('4.567abcdefgh123'), 4.567);
assert.equal(tasks.getFloatOnString('abcdefgh'), NaN);
assert.equal(
forbidden.isCommented(tasks.getFloatOnString),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'getIntegerOnString an integer of the specified base or NaN',
() => {
assert.equal(tasks.getIntegerOnString('4.567abcdefgh', 10), 4);
assert.equal(tasks.getIntegerOnString('abcdefgh', 10), NaN);
assert.equal(tasks.getIntegerOnString('1.234', 2), 1);
assert.equal(tasks.getIntegerOnString('10', 8), 8);
assert.equal(
forbidden.isCommented(tasks.getIntegerOnString),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'isSafeInteger returns whether a number is a safe integer',
() => {
assert.equal(tasks.isSafeInteger(10), true, 'value 10 is a safe integer');
assert.equal(
tasks.isSafeInteger(3.5),
false,
'value 3.5 is not a safe integer'
);
assert.equal(
tasks.isSafeInteger(2 ** 53),
false,
'value 2**53 is not a safe integer'
);
assert.equal(
forbidden.isCommented(tasks.isSafeInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'roundToSmallestInteger returns the largest integer less than or equal to a given number',
() => {
assert.equal(tasks.roundToSmallestInteger(5.9), 5);
assert.equal(tasks.roundToSmallestInteger(-5.1), -6);
assert.equal(
forbidden.isCommented(tasks.roundToSmallestInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'roundToLargestInteger returns the smallest integer greater than or equal to a given number',
() => {
assert.equal(tasks.roundToLargestInteger(5.1), 6);
assert.equal(tasks.roundToLargestInteger(-5.9), -5);
assert.equal(
forbidden.isCommented(tasks.roundToLargestInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'roundToNearestInteger returns the value of a number rounded to the nearest integer',
() => {
assert.equal(tasks.roundToNearestInteger(5.5), 6);
assert.equal(tasks.roundToNearestInteger(5.4), 5);
assert.equal(tasks.roundToNearestInteger(-5.5), -5);
assert.equal(
forbidden.isCommented(tasks.roundToNearestInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getIntegerPartNumber returns the integer part of a number by removing any fractional digits',
() => {
assert.equal(tasks.getIntegerPartNumber(5.5), 5);
assert.equal(tasks.getIntegerPartNumber(5.4), 5);
assert.equal(tasks.getIntegerPartNumber(-5.5), -5);
assert.equal(
forbidden.isCommented(tasks.getIntegerPartNumber),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('getSumOfNumbers returns the sum of numbers', () => {
assert.equal(tasks.getSumOfNumbers(1, 2, 3), 6);
assert.equal(tasks.getSumOfNumbers(0.1, 0.2, 0.3), 0.6);
assert.equal(
forbidden.isCommented(tasks.getSumOfNumbers),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('getMaxNumber returns the largest number', () => {
assert.equal(tasks.getMaxNumber(1, 2), 2);
assert.equal(tasks.getMaxNumber(-5, -6), -5);
assert.equal(tasks.getMaxNumber(0, 5), 5);
assert.equal(
forbidden.isCommented(tasks.getMaxNumber),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'getRandomInteger returns a random integer in the range from min to max',
() => {
for (let i = 0; i < 10; i += 1) {
const min = Math.floor(Math.random() * 10);
const max = Math.floor(Math.random() * 10 + min + 1);
const result = tasks.getRandomInteger(min, max);
assert.equal(
Number.isInteger(result),
true,
`the ${result} is not an integer`
);
assert.equal(
min <= result && result <= max,
true,
`the ${result} is not in the range from ${min} to ${max}`
);
}
assert.equal(
forbidden.isCommented(tasks.getRandomInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getHypotenuse returns the length of the hypotenuse of a right triangle',
() => {
assert.equal(tasks.getHypotenuse(3, 4), 5);
assert.equal(tasks.getHypotenuse(5, 6).toPrecision(14), 7.8102496759067);
assert.equal(
tasks.getHypotenuse(Number.MAX_VALUE, 6),
1.7976931348623157e308
);
assert.equal(
forbidden.isCommented(tasks.getHypotenuse),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'getCountOfOddNumbers returns count of not even numbers from zero to the resulting number',
() => {
assert.equal(tasks.getCountOfOddNumbers(4), 2);
assert.equal(tasks.getCountOfOddNumbers(5), 3);
assert.equal(tasks.getCountOfOddNumbers(10), 5);
assert.equal(tasks.getCountOfOddNumbers(15), 8);
assert.equal(tasks.getCountOfOddNumbers(-4), 2);
assert.equal(tasks.getCountOfOddNumbers(-5), 3);
assert.equal(tasks.getCountOfOddNumbers(-10), 5);
assert.equal(tasks.getCountOfOddNumbers(-15), 8);
assert.equal(
forbidden.isCommented(tasks.getCountOfOddNumbers),
false,
'Be sure to remove comments from the final solution'
);
}
);
});
describe('core-js-numbers-tasks optimal implementation', () => {
it.optional('optimal implementation of getCube', function test() {
const fnStr = tasks.getCube.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('**'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#arithmetic_operators'
);
assert.equal(
forbidden.isCommented(tasks.getCube),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of getSine', function test() {
const fnStr = tasks.getSine.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.sin'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.getSine),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'optimal implementation of numberToStringInBase',
function test() {
const fnStr = tasks.numberToStringInBase.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('toString(base)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.numberToStringInBase),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('optimal implementation of toExponential', function test() {
const fnStr = tasks.toExponential.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('toExponential(fractionDigits)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.toExponential),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of toFixed', function test() {
const fnStr = tasks.toFixed.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('toFixed(fractionDigits)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.toFixed),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of toPrecision', function test() {
const fnStr = tasks.toPrecision.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('toPrecision(precision)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.toPrecision),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of getNumberValue', function test() {
const fnStr = tasks.getNumberValue.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('.valueOf()'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.getNumberValue),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of isNumber', function test() {
const fnStr = tasks.isNumber.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('.isFinite'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.isNumber),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of isInteger', function test() {
const fnStr = tasks.isInteger.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('.isInteger(number)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.isInteger),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of getFloatOnString', function test() {
const fnStr = tasks.getFloatOnString.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('.parseFloat(str)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.getFloatOnString),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of getIntegerOnString', function test() {
const fnStr = tasks.getIntegerOnString.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('.parseInt(str, base)'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.getIntegerOnString),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of isSafeInteger', function test() {
const fnStr = tasks.isSafeInteger.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('.isSafeInteger'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
);
assert.equal(
forbidden.isCommented(tasks.isSafeInteger),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional(
'optimal implementation of roundToSmallestInteger',
function test() {
const fnStr = tasks.roundToSmallestInteger.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.floor'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.roundToSmallestInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'optimal implementation of roundToLargestInteger',
function test() {
const fnStr = tasks.roundToLargestInteger.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.ceil'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.roundToLargestInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'optimal implementation of roundToNearestInteger',
function test() {
const fnStr = tasks.roundToNearestInteger.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.round'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.roundToNearestInteger),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional(
'optimal implementation of getIntegerPartNumber',
function test() {
const fnStr = tasks.getIntegerPartNumber.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.trunc'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.getIntegerPartNumber),
false,
'Be sure to remove comments from the final solution'
);
}
);
it.optional('optimal implementation of getMaxNumber', function test() {
const fnStr = tasks.getMaxNumber.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.max'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.getMaxNumber),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of getHypotenuse', function test() {
const fnStr = tasks.getHypotenuse.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('Math.hypot'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math'
);
assert.equal(
forbidden.isCommented(tasks.getHypotenuse),
false,
'Be sure to remove comments from the final solution'
);
});
it.optional('optimal implementation of getLastDigit', function test() {
const fnStr = tasks.getLastDigit.toString();
if (!fnStr.includes('return')) {
this.skip();
}
assert.equal(
fnStr.includes('%'),
true,
'You need to use a different method or operator, look for the appropriate method or operator in the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#arithmetic_operators'
);
assert.equal(
forbidden.isCommented(tasks.getLastDigit),
false,
'Be sure to remove comments from the final solution'
);
});
});