generated from Kenzie-Academy-Brasil-Developers/m1-palindromo-min-max
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testes.js
203 lines (197 loc) · 5.06 KB
/
testes.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
const palindromeTable = document.getElementById('palindrome_table');
const minMaxTable = document.getElementById('minmax_table');
const palindromeTests = [
{
id: 1,
text: 'Radar',
expectedReturn: true
},
{
id: 2,
text: 'Arara',
expectedReturn: true
},
{
id: 3,
text: 'Ovo',
expectedReturn: true
},
{
id: 4,
text: 'Anilina',
expectedReturn: true
},
{
id: 5,
text: 'Cadeira',
expectedReturn: false
},
{
id: 6,
text: 'Ursinho',
expectedReturn: false
},
{
id: 7,
text: 'Monitor',
expectedReturn: false
},
{
id: 8,
text: 'Kenzie',
expectedReturn: false
},
{
id: 9,
text: 'A sacada da casa',
expectedReturn: true
},
{
id: 10,
text: 'Ame o poema',
expectedReturn: true
},
{
id: 11,
text: 'A mala nada na lama',
expectedReturn: true
},
{
id: 12,
text: 'A torre da derrota',
expectedReturn: true
},
{
id: 13,
text: 'Estudar javascript',
expectedReturn: false
},
{
id: 14,
text: 'O rei roeu a roupa do rato',
expectedReturn: false
},
{
id: 15,
text: 'Cinco patinho foram passear',
expectedReturn: false
},
{
id: 16,
text: 'Um senhor doutor',
expectedReturn: false
}
]
const minMaxTests = [
{
id: 1,
array: [1,52,59,16,13,9],
min: 1,
max: 59
},
{
id: 2,
array: [2,30,33,11,51,56],
min: 2,
max: 56
},
{
id: 3,
array: [35,9,10,58,55,44],
min: 9,
max: 58
},
{
id: 4,
array: [52,58,47,31,37,5],
min: 5,
max: 58
},
{
id: 5,
array: [16,11,13,35,49,50],
min: 11,
max: 50
},
{
id: 6,
array: [59,57,28,22,13,5],
min: 5,
max: 59
},
]
// Funções palíndromo
function createPalindromeCard({id, text, expectedReturn}){
let template = `<tr id="teste_${id}" frase="${text}">
<th scope="row">${id}</th>
<td>${text}</td>
<td class="expected_return">${expectedReturn}</td>
<td class="return">-</td>
<td class="result">-</td>
</tr>`
return template;
}
function createPalindromeTestCard({id, text, expectedReturn}){
let retorno = isPalindrome(text);
let isExpectedReturn = retorno == expectedReturn;
let template = `<tr id="teste_${id}" frase="${text}">
<th scope="row">${id}</th>
<td>${text}</td>
<td class="expected_return">${expectedReturn}</td>
<td class="return">${retorno}</td>
<td class="result">${isExpectedReturn ? "✅" : "❌"}</td>
</tr>`;
return template;
}
function testPalindromos(){
let tbody = palindromeTable.querySelector('tbody');
tbody.innerHTML = "";
palindromeTests.forEach((test)=>{
tbody.insertAdjacentHTML('beforeend', createPalindromeTestCard(test));
})
document.querySelector('#accordionPalindrome .accordion-collapse.collapse').classList.add('show')
}
// Funções MinMax
function createMinMaxCard({id, array, min, max}){
let template = `<tr id="teste_${id}">
<th scope="row">${id}</th>
<td>[${array.toString()}]</td>
<td class="min">${min}</td>
<td class="max">${max}</td>
<td class="return">-</td>
<td class="result">-</td>
</tr>`
return template;
}
function createMinMaxTestCard({id, array, min, max}){
let retorno = arrayMaxMin(array);
let isExpectedReturn = retorno[0] == min && retorno[1] == max && retorno.length == 2;
let template = `<tr id="teste_${id}">
<th scope="row">${id}</th>
<td>[${array.toString()}]</td>
<td class="min">${min}</td>
<td class="max">${max}</td>
<td class="return">${retorno}</td>
<td class="result">${isExpectedReturn ? "✅" : "❌"}</td>
</tr>`
return template;
}
function testMinMax(){
let tbody = minMaxTable.querySelector('tbody');
tbody.innerHTML = "";
minMaxTests.forEach((test)=>{
tbody.insertAdjacentHTML('beforeend', createMinMaxTestCard(test));
})
document.querySelector('#accordionMinMax .accordion-collapse.collapse').classList.add('show')
}
function init(){
let tbodyPalindrome = palindromeTable.querySelector('tbody');
palindromeTests.forEach((test)=>{
tbodyPalindrome.insertAdjacentHTML('beforeend', createPalindromeCard(test));
})
let tbodyMinMax = minMaxTable.querySelector('tbody');
minMaxTests.forEach((test)=>{
tbodyMinMax.insertAdjacentHTML('beforeend', createMinMaxCard(test));
})
}
addEventListener("load", (event) => {init()});