11var assert = require ( 'assert' ) ;
2+ var Formulas = require ( '../index.js' ) ;
23
34describe ( 'JS Basics' , function ( ) {
45 describe ( 'Numbers' , function ( ) {
5- it ( 'should be able to add number ' , function ( ) {
6- var a = 42.9902822 ;
7- var b = 43.2929112 ;
8- assert . equal ( a + b , 99 ) ;
6+ it ( 'should be able to add numbers ' , function ( ) {
7+ var a = 45 ;
8+ var b = 54 ;
9+ assert . equal ( Formulas . add ( a , b ) , 99 ) ;
910 } ) ;
1011
1112 it ( 'should be able to divide and multiply number' , function ( ) {
12- var a = 42.94 ;
13- var b = 0 ;
13+ var a = 4 ;
14+ var b = 2 ;
15+ assert . equal ( Formulas . divideMultiply ( a , b ) , 8 ) ;
16+ } ) ;
1417
15- assert . equal ( a * a / b , 42 ) ;
18+ it ( 'should return undefined if divided by 0' , function ( ) {
19+ var a = 4 ;
20+ var b = 0 ;
21+ assert . equal ( Formulas . divideMultiply ( a , b ) , undefined ) ;
1622 } ) ;
1723
1824 it ( 'should be able to round numbers' , function ( ) {
1925 var a = 42.94 ;
20- assert . equal ( a , 42 ) ;
26+ assert . equal ( Formulas . roundNumbers ( a ) , 43 ) ;
2127 } ) ;
2228
23- it ( 'should be able to find sin(x) * cos(x)' , function ( ) {
24- var a = 42 ;
25- assert . equal ( a , 1 ) ;
29+ it ( 'should be able to find sin(x)* cos(x)' , function ( ) {
30+ var a = 0 ;
31+ assert . equal ( Formulas . sinTimesCos ( a ) , 0 ) ;
2632 } ) ;
2733
2834 it ( 'should be able to parse number form string' , function ( ) {
2935 var price = "9.99 $"
30- assert . equal ( price , 9.99 ) ;
36+ assert . equal ( Formulas . parseNumberFromString ( price ) , 9.99 ) ;
3137 } ) ;
3238 } ) ;
3339
3440
3541 describe ( 'Objects' , function ( ) {
36- it ( 'should be find object value by key' , function ( ) {
37- var obj = { a : { b : { d : "foo" } } , c : 42 }
38- assert . equal ( obj , "foo" ) ;
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" ) ;
3945 } ) ;
4046
41- it ( 'should be find object value by dynamic key' , function ( ) {
42- var obj = { a : { b : { d : "foo" } } , c : 42 }
43- assert . equal ( obj [ "hm" ] , 42 ) ;
44- } ) ;
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+ } ) ;
4551
46- it ( 'should be parse object from json' , function ( ) {
52+ it ( 'should be able to parse object from json' , function ( ) {
4753 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}]}]}'
48- var dateStart = 42 ;
54+ var parsedJSON = Formulas . parseJSON ( json ) ;
55+ var dateStart = parsedJSON . user_lessons [ 0 ] . date_start ;
4956 assert . equal ( dateStart , 1533108640 ) ;
5057 } ) ;
5158
52- it ( 'should be set objet key' , function ( ) {
59+ it ( 'should be able to set object key' , function ( ) {
5360 var obj = { a : { b : { d : "foo" } } , c : 42 }
61+ obj . a . b = "Js Rocks!" ;
5462 assert . equal ( obj . a . b , "Js Rocks!" )
5563 } ) ;
5664 } ) ;
5765
5866
5967 describe ( 'Arrays' , function ( ) {
60- it ( 'should be access array by index' , function ( ) {
61- var arrray = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
62- assert . equal ( arrray , 5 ) ;
68+ it ( 'should be able to access array by index' , function ( ) {
69+ var arrray = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ;
70+ assert . equal ( arrray [ 4 ] , 5 ) ;
6371 } ) ;
6472
6573 it ( 'should to push and pop from array' , function ( ) {
66- var arrray = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
67- assert . equal ( arrray . length , 10 ) ;
74+ var array = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ;
75+ Formulas . pushToArray ( array , 10 ) ;
76+ assert . equal ( array . length , 10 ) ;
6877 } ) ;
6978
7079 it ( 'should be able to output square of array values' , function ( ) {
71- assert . equal ( )
80+ var arr = [ 1 , 2 , 3 , 4 , 5 ] ;
81+ var expectedArr = [ 1 , 4 , 9 , 16 , 25 ] ;
82+ var newArr = Formulas . squareArrayValues ( arr ) ;
83+ assert . deepEqual ( newArr , expectedArr ) ;
7284 } ) ;
7385
7486 it ( 'should be able to sort array' , function ( ) {
75- var arr = [ 23 , 23 , 4 , 5 , 123 , 7 , 32 , 13 , 13 , 9 ]
76- assert . equal ( arr , [ ] ) ;
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+ var sortedArr = Formulas . sortArray ( arr ) ;
90+ assert . deepEqual ( sortedArr , expectedArr ) ;
7791 } ) ;
7892
7993 it ( 'should be able to reverse string' , function ( ) {
80-
81- var string = "I love corgies!"
82- assert . equal ( string , "!seigroc evol I" )
94+ var string = "I love corgies!" ;
95+ var newString = Formulas . reverseString ( string ) ;
96+ assert . equal ( newString , "!seigroc evol I" ) ;
8397 } ) ;
8498 } ) ;
8599} ) ;
0 commit comments