|
1 | 1 | var assert = require('assert'); |
2 | 2 | var Formulas = require('../index.js'); |
3 | 3 |
|
4 | | -describe('JS Basics', function() { |
5 | | - describe('Numbers', function() { |
6 | | - it('should be able to add numbers', function() { |
7 | | - var a = 45; |
| 4 | +describe('JS Basics', function () { |
| 5 | + describe('Numbers', function () { |
| 6 | + it('should be able to add numbers', function () { |
| 7 | + var a = 45; |
8 | 8 | var b = 54; |
9 | | - assert.equal(Formulas.add(a,b), 99); |
| 9 | + assert.equal(Formulas.add(a, b), 99); |
10 | 10 | }); |
11 | 11 |
|
12 | | - it('should be able to divide and multiply number', function() { |
13 | | - var a = 4; |
| 12 | + it('should be able to divide and multiply number', function () { |
| 13 | + var a = 4; |
14 | 14 | var b = 2; |
15 | | - assert.equal(Formulas.divideMultiply(a,b), 8); |
| 15 | + assert.equal(Formulas.divideMultiply(a, b), 8); |
16 | 16 | }); |
17 | 17 |
|
18 | | - it('should return undefined if divided by 0', function() { |
19 | | - var a = 4; |
| 18 | + it('should return undefined if divided by 0', function () { |
| 19 | + var a = 4; |
20 | 20 | var b = 0; |
21 | | - assert.equal(Formulas.divideMultiply(a,b), undefined); |
| 21 | + assert.equal(Formulas.divideMultiply(a, b), undefined); |
22 | 22 | }); |
23 | 23 |
|
24 | | - it('should be able to round numbers', function() { |
25 | | - var a = 42.94; |
| 24 | + it('should be able to round numbers', function () { |
| 25 | + var a = 42.94; |
26 | 26 | assert.equal(Formulas.roundNumbers(a), 43); |
27 | 27 | }); |
28 | 28 |
|
29 | | - it('should be able to find sin(x)*cos(x)', function() { |
| 29 | + it('should be able to find sin(x)*cos(x)', function () { |
30 | 30 | var a = 0; |
31 | 31 | assert.equal(Formulas.sinTimesCos(a), 0); |
32 | 32 | }); |
33 | 33 |
|
34 | | - it('should be able to parse number form string', function() { |
| 34 | + it('should be able to parse number form string', function () { |
35 | 35 | var price = "9.99 $" |
36 | 36 | assert.equal(Formulas.parseNumberFromString(price), 9.99); |
37 | 37 | }); |
38 | 38 | }); |
39 | 39 |
|
40 | 40 |
|
41 | | - describe('Objects', function() { |
42 | | - it('should be able to find object value by key', function() { |
43 | | - var obj = { a: {b: { d: "foo" }}, c: 42 }; |
44 | | - assert.equal(Formulas.findObjectByKey(obj,'d'), "foo"); |
| 41 | + describe('Objects', function () { |
| 42 | + it('should be able to find object value by key', function () { |
| 43 | + var obj = { a: { b: { d: "foo" } }, c: 42 }; |
| 44 | + assert.equal(Formulas.findObjectValueByKey(obj, 'd'), "foo"); |
45 | 45 | }); |
46 | 46 |
|
47 | | - it('should be able to find object value by dynamic key', function() { |
48 | | - var obj = {a: {b: { d: "foo" }}, c: 42 } |
49 | | - assert.equal(Formulas.findObjectByKey(obj,'c'), 42);; |
50 | | - }); |
| 47 | + it('should be able to find object value by dynamic key', function () { |
| 48 | + var obj = { a: { b: { d: "foo" } }, c: 42 } |
| 49 | + assert.equal(Formulas.findObjectValueByKey(obj, 'c'), 42);; |
| 50 | + }); |
51 | 51 |
|
52 | | - it('should be able to parse object from json', function() { |
| 52 | + it('should be able to parse object from json', function () { |
53 | 53 | var json = '{"ok":true,"user_lessons":[{"user_lesson_id":408097171313,"state":"completed","skip":false,"lesson_id":1,"date_start":1533108640,"tasks":[{"user_task_id":407936828624,"state":"skipped","current_step":"","task_id":1},{"user_task_id":408791535509,"state":"skipped","current_step":"","task_id":2},{"user_task_id":409970847238,"state":"skipped","current_step":"","task_id":3}]}]}' |
54 | 54 | var parsedJSON = Formulas.parseJSON(json); |
55 | 55 | var dateStart = parsedJSON.user_lessons[0].date_start; |
56 | 56 | assert.equal(dateStart, 1533108640); |
57 | 57 | }); |
58 | 58 |
|
59 | | - it('should be able to set object key', function() { |
60 | | - var obj = { a: {b: { d: "foo" }}, c: 42 } |
| 59 | + it('should be able to set object key', function () { |
| 60 | + var obj = { a: { b: { d: "foo" } }, c: 42 } |
61 | 61 | obj.a.b = "Js Rocks!"; |
62 | 62 | assert.equal(obj.a.b, "Js Rocks!") |
63 | 63 | }); |
64 | 64 | }); |
65 | 65 |
|
66 | 66 |
|
67 | | - describe('Arrays', function() { |
68 | | - it('should be able to access array by index', function() { |
69 | | - var arrray = [1,2,3,4,5,6,7,8,9]; |
| 67 | + describe('Arrays', function () { |
| 68 | + it('should be able to access array by index', function () { |
| 69 | + var arrray = [1, 2, 3, 4, 5, 6, 7, 8, 9]; |
70 | 70 | assert.equal(arrray[4], 5); |
71 | 71 | }); |
72 | 72 |
|
73 | | - it('should to push and pop from array', function() { |
74 | | - var array = [1,2,3,4,5,6,7,8,9]; |
| 73 | + it('should to push and pop from array', function () { |
| 74 | + var array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; |
75 | 75 | Formulas.pushToArray(array, 10); |
76 | 76 | assert.equal(array.length, 10); |
77 | 77 | }); |
78 | 78 |
|
79 | | - it('should be able to output square of array values', function() { |
80 | | - var arr = [1,2,3,4,5]; |
81 | | - var expectedArr = [1,4,9,16,25]; |
| 79 | + it('should be able to output square of array values', function () { |
| 80 | + var arr = [1, 2, 3, 4, 5]; |
| 81 | + var expectedArr = [1, 4, 9, 16, 25]; |
82 | 82 | var newArr = Formulas.squareArrayValues(arr); |
83 | 83 | assert.deepEqual(newArr, expectedArr); |
84 | 84 | }); |
85 | 85 |
|
86 | | - it('should be able to sort array', function() { |
87 | | - var arr = [23,23,4,5,123,7,32,13,13,9]; |
88 | | - var expectedArr = [4,5,7,9,13,13,23,23,32,123]; |
| 86 | + it('should be able to sort array', function () { |
| 87 | + var arr = [23, 23, 4, 5, 123, 7, 32, 13, 13, 9]; |
| 88 | + var expectedArr = [4, 5, 7, 9, 13, 13, 23, 23, 32, 123]; |
89 | 89 | var sortedArr = Formulas.sortArray(arr); |
90 | 90 | assert.deepEqual(sortedArr, expectedArr); |
91 | 91 | }); |
92 | 92 |
|
93 | | - it('should be able to reverse string', function() { |
94 | | - var string = "I love corgies!"; |
| 93 | + it('should be able to reverse string', function () { |
| 94 | + var string = "I love corgies!"; |
95 | 95 | var newString = Formulas.reverseString(string); |
96 | 96 | assert.equal(newString, "!seigroc evol I"); |
97 | 97 | }); |
|
0 commit comments