Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat #59

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function pow(x, n) {
return result;
}



/**
* This function calculate factorial of number
* @param n {number}
Expand All @@ -33,6 +35,8 @@ function factorial(n) {
return n ? n * factorial(n - 1) : 1;
};



/**
* This function calculate Fibonacci sequence
* @param n
Expand All @@ -41,6 +45,8 @@ function factorial(n) {
function fibonacci(n) {
return (n > 2) ? fibonacci(n - 1) + fibonacci(n - 2) : 1;
}



/**
* This function must remove some element for array of string by name
Expand Down
83 changes: 75 additions & 8 deletions js/lib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Test suite for testing lib.js', () => {
});

it('should return NaN if one parameter is skipped', () => {
assert.equal(sum(1), NaN)
assert.isTrue(isNaN(sum(1)));
});


Expand All @@ -20,20 +20,87 @@ describe('Test suite for testing lib.js', () => {

describe('Test suite for testing pow function', () => {
it('should raising x to the n power', () => {
// Write your code here
assert.equal(pow(2,3),8)
});


});

describe('Test suite for testing removeByName function', () => {
describe('Тестування функції for testing removeByName', () => {
it('should remove some element from array', () => {
// Write your code here
const array = ["s","i","m","p","I","e"]
const anotherarray = ["s","i","m","p","I"]
assert.deepEqual(removeByName(array,"e"),anotherarray)
});

it('should not remove element from array', () => {
// Write your code here
const array = ["s","i","m","p","I","e"]
assert.deepEqual(removeByName(array,"A"),array)
});
});
});

describe('Тестування функції factorial ', () => {
it('should make factorial from number n', () => {
assert.equal(factorial(2),2)
assert.equal(factorial(3),6)
assert.equal(factorial(4),24)
});
});

describe('Тестування функції fibonacci ', () => {
it('should calculate Fibonacci sequence from n', () => {
assert.equal(fibonacci(10),55)
});

it("should return 1 for n = 1", function() {
assert.equal(fibonacci(1), 1);
});
});

describe('Тестування функції makeCounter ', () => {
it("should return function", function() {
assert.equal(typeof makeCounter(0), "function");
});

it("should increment counter", function() {
const counter = makeCounter(2);
assert.equal(counter(), 2);
assert.equal(counter(), 3);
assert.equal(counter(), 4);
});
});

describe('Тестування функції getAsyncTimerId ', function() {
it('should return a number', function() {
const result = getAsyncTimerId(1000);
setTimeout(function() {
assert.isNumber(result);
}, 2000);
});
});

describe('Тестування функції asyncMultiply function', function() {
it('should return the correct value', async function() {
asyncMultiply(5).then(function(result) {
assert.equal(result, 10);
})
});

it('should return number', async function() {
asyncMultiply(5).then(function(result) {
assert.isNumber(result);
})
});
});

describe('Tестування функції httpGet ', function() {
it('should return a Promise object', function() {
const result = httpGet("www.google.com");
assert.instanceOf(result, Promise);
});
it('should return the response on a successful request', function() {
httpGet('https://jsonplaceholder.typicode.com/todos/1')
.then(function(response) {
assert.isString(response);
});
});
});
});