{}

Build your resume with HTML & CSS and win $100

Get featured on Programiz PRO and the Wall of Inspiration.

Build your resume with HTML & CSS and win $100

Join Challenge →
Join Challenge →

Build your resume with HTML & CSS and win $100

Get featured on Programiz PRO and the Wall of Inspiration.

Build your resume with HTML & CSS and win $100

Join Challenge →
Join Challenge →
run-icon
main.js
// Пример за функция за събиране function add(a, b) { return a + b; } // Unit тест за функцията add function testAdd() { // Първи тест - очакваме резултат 5 let result1 = add(2, 3); if (result1 === 5) { console.log('Тест 1 за add() - Успешен!'); } else { console.log('Тест 1 за add() - Неуспешен!'); } // Втори тест - друг случай let result2 = add(-1, 1); if (result2 === 0) { console.log('Тест 2 за add() - Успешен!'); } else { console.log('Тест 2 за add() - Неуспешен!'); } } // Функция за намиране максимална стойност function findMax(arr) { if (arr.length === 0) return null; return Math.max(...arr); } // Unit тест за функцията findMax function testFindMax() { // Тест с нормален масив let result1 = findMax([1, 5, 3, 9, 2]); if (result1 === 9) { console.log('Тест 1 за findMax() - Успешен!'); } else { console.log('Тест 1 за findMax() - Неуспешен!'); } // Тест с празен масив let result2 = findMax([]); if (result2 === null) { console.log('Тест 2 за findMax() - Успешен!'); } else { console.log('Тест 2 за findMax() - Неуспешен!'); } } // Функция за проверка дали дума е палиндром function isPalindrome(str) { str = str.toLowerCase().replace(/[^a-zA-Z0-9]/g, ''); return str === str.split('').reverse().join(''); } // Unit тест за функцията isPalindrome function testIsPalindrome() { // Тест с палиндром let result1 = isPalindrome('А, мила мома!'); if (result1 === true) { console.log('Тест 1 за isPalindrome() - Успешен!'); } else { console.log('Тест 1 за isPalindrome() - Неуспешен!'); } // Тест без палиндром let result2 = isPalindrome('Hello'); if (result2 === false) { console.log('Тест 2 за isPalindrome() - Успешен!'); } else { console.log('Тест 2 за isPalindrome() - Неуспешен!'); } } // Изпълнение на всички тестове function runAllTests() { testAdd(); testFindMax(); testIsPalindrome(); } // Извикване на функцията за стартиране на тестовете runAllTests();
Output