-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathscripts_spec.js
104 lines (78 loc) · 2.83 KB
/
scripts_spec.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
var tester = {
init: function(sprintObj){
console.log("Initializing test...");
this.sprintObj = sprintObj;
this.testLargestEl();
this.testReversed();
this.testLoudSnakeCase();
this.testCompareArrays();
this.testFizzBuzz();
this.testMyMap();
this.testPrimes();
this.displayResults();
},
results: {},
testLargestEl: function(){
var input = [2,4,2,1,5,2,5];
var exp = 5;
var actual = this.sprintObj.largestEl(input);
this.results.largestEl = (actual == exp);
},
testReversed: function(){
var input = "I am a special string!";
var exp = "!gnirts laiceps a ma I";
var actual = this.sprintObj.reversed(input);
this.results.reversed = (actual == exp);
},
testLoudSnakeCase: function(){
var input = "I am a strange code. I like it though!";
var exp = "I_Am_A_Strange_Code_I_Like_It_Though";
var actual = this.sprintObj.loudSnakeCase(input);
this.results.loudSnakeCase = ( actual == exp);
},
testCompareArrays: function(){
var startArr = [1,2,4,3];
var diffArr = [1,2,3,4];
// Happy path
var actual1 = this.sprintObj.compareArrays(startArr, startArr);
var test1 = ( actual1 == true);
// Sad path
var actual2 = this.sprintObj.compareArrays(startArr, diffArr);
var test2 = ( actual2 == false);
this.results.compareArrays = ( test1 && test2 );
},
testFizzBuzz: function(){
var input = 16;
var exp = [1,2,"FIZZ",4,"BUZZ","FIZZ",7,8,"FIZZ","BUZZ",11,"FIZZ",13,14,"FIZZBUZZ",16];
var actual = this.sprintObj.fizzBuzz(16);
if (typeof actual === 'undefined') { actual = [] };
this.results.fizzBuzz = ( this.sprintObj.compareArrays(exp,actual) );
},
testMyMap: function(){
var inputArr = [1,2,3,4,5];
var inputFunc = function(el){ return el*2; };
var exp = [2,4,6,8,10];
var actual = this.sprintObj.myMap(inputArr,inputFunc);
if (typeof actual === 'undefined') { actual = [] };
this.results.myMap = ( this.sprintObj.compareArrays(exp, actual) );
},
testPrimes: function(){
var input = 12;
var exp = [2,3,5,7,11];
var actual = this.sprintObj.primes(input);
if (typeof actual === 'undefined') { actual = [] };
this.results.primes = ( this.sprintObj.compareArrays(exp, actual));
},
displayResults: function(){
console.log("Displaying results...");
console.log(this.results)
$("#largest-el").html(String(this.results.largestEl));
$("#reversed").html(String(this.results.reversed));
$("#loud-snake-case").html(String(this.results.loudSnakeCase));
$("#compare-arrays").html(String(this.results.compareArrays));
$("#fizz-buzz").html(String(this.results.fizzBuzz));
$("#my-map").html(String(this.results.myMap));
$("#primes").html(String(this.results.primes));
}
}
$(document).ready( function(){ tester.init( sprintFunctions )});