Skip to content
Open
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
24 changes: 24 additions & 0 deletions module-1/classification.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ function grade(score) {
*/
// PLACE YOUR CODE BETWEEN THIS...

// 1st solution

/* if (0 <= score && score <= 100){
if (score >= 90){
gradeOfStudent = 5;
} else if (score >= 80 ){
gradeOfStudent = 4;
} else if (score >= 70 ){
gradeOfStudent = 3;
} else if (score >= 60 ){
gradeOfStudent = 2;
} else {
gradeOfStudent = 1;
}
} else {
gradeOfStudent = 0;
} */

// 2nd solution
//gradeOfStudent = (0 <= score && score <= 100) ? (score >= 90) ? 5 : (score >= 80) ? 4 : (score >= 70) ? 3 : (score >= 60) ? 2 : 1 : 0;

// 3rd solution
gradeOfStudent = (score < 0 || score > 100) ? 0 : Math.min(Math.max(Math.ceil((score - 49) / 10), 1), 5);

// ...AND THIS COMMENT LINE!
return gradeOfStudent;
}
Expand Down
14 changes: 13 additions & 1 deletion module-1/euclidean.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ function euclidean(a, b) {
*/
// PLACE YOUR CODE BETWEEN THIS...


if (a > 0 && b > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting of your code is inconsistent. Well-formatted code is easy to understand and important from maintenance perspective as well. Last but not least, looks cool. Please mind the formatting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you specify which part of the code is inconsistent?
I reviewed it and I don't see which code snippet is wrong.

while (a !== b){
if (a > b){
a = a- b;
} else {
b = b - a;
}
}
gcd = a;
} else {
gcd = 0;
}

// ...AND THIS COMMENT LINE!
return gcd;
}
Expand Down
20 changes: 20 additions & 0 deletions module-1/fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ function fibonacci(n) {
*/
// PLACE YOUR CODE BETWEEN THIS...

if (n >= 0){
if (n < 2){
nThFibonacci = n;
} else {
//nThFibonacci = fibonacci(n-2) + fibonacci(n-1)

let f0 = 0;
let f1 = 1;

for (let i = 2; i<=n ; ++i){
const sum = f0 + f1;
f0 = f1;
f1 = sum;
}
nThFibonacci = f1;
}
} else {
nThFibonacci = 0;
}

// ...AND THIS COMMENT LINE!
return nThFibonacci;
}
Expand Down
118 changes: 118 additions & 0 deletions module-2/test/calc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,123 @@ describe.only('calc', () => {
* .times(6).v // 24
*/
// TODO: write test cases to test calculator

// constructor
it("should have a proper value", () => {
const c = calc(3);
expect(c).not.to.be.undefined;
});

describe("add", () => {
// Checks If I have a calculator there is an "add" method as well?
// If the first IT fails within a describe, the other IT test cases won't be checked
it("should exist", () => {
const c = calc(3);
expect(c.add).not.to.be.undefined;
});

it("should be able to add a number to the current value", () => {
// GIVEN
const c = calc(3);
// WHEN
const result = c.add(5).v;
// THEN
expect(result).to.equal(8);
});
});

describe("minus", () => {
it("should exist", () => {
const c = calc(3);
expect(c.minus).not.to.be.undefined;
});

it("should be able to substract a number from the current value", () => {
const c = calc(3);
const result = c.minus(2).v;
expect(result).to.equal(1);
});
});

describe("square", () => {
it("should exist", () => {
const c = calc(3);
expect(c.sqrt).not.to.be.undefined;
});

it("should be able to get the square root of the current value", () => {
const c = calc(4);

const result = c.sqrt(2).v;

expect(result).to.be.equal(2);
});

it("should handle square root with negative number", () => {
const c = calc(-4);

expect(() => c.sqrt()).to.throw("Square root of negative value cannot be determined!");
});
});

describe("times", () => {
it("should exist", () => {
const c = calc(3);
expect(c.times).not.to.be.undefined;
});

it("should be able to multiply the current value with the given number", () => {
const c = calc(3);

const result = c.times(10).v;

expect(result).to.be.equal(30);
});
});

describe("divide", () => {
it("should exist", () => {
const c = calc(3);
expect(c.divide).not.to.be.undefined;
});

it("should be able to divide the current value with the given number", () => {
const c = calc(10);

const result = c.divide(2).v;

expect(result).to.be.equal(5);
});

it("should handle division by 0", () => {
const c = calc(42);
expect(() => c.divide(0)).to.throw("Division by 0 is not possible!");
//expect(c.divide.bind(null, 0)).to.throw();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need the commented code snippet?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't need that many comments in my code.

I changed it, and I left only the essential ones.

});
});

describe("modulo", () => {
it("should exist", () => {
const c = calc(3);
expect(c.modulo).not.to.be.undefined;
});

it("should be able to get the modulo by dividing the current number with the given number", () => {
const c = calc(10);

const result = c.modulo(5).v;

expect(result).to.be.equal(0);
});
});

describe("complexExpression", () => {
it("should be able to calculate the given more complex expression", () => {
const c = calc(3);

const result = c.add(4).minus(3).times(6).v;

expect(result).to.be.equal(24);
});
});
});
36 changes: 35 additions & 1 deletion module-3/pop/Element.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//const ElementFinder = require("../test/mock/ElementFinder");

/**
* Create Element class, which represents an element of
* the application, and
Expand All @@ -14,4 +16,36 @@
* in it's children (recursively) the Element with
* the given name or throws an Erorr if it cannot
* find the element
*/
*/
class Element {
constructor(name, locator) {
this.name = name;
this.locator = locator;
this.parent = null; // If we don't know the Object yet, it should be null
this.children = {};
}

setParent(parent) {
this.parent = parent;
}

addChildren(child) {
if(this.children.hasOwnProperty(child.name)){
throw new Error(child.name + " It is not possible to add a children twice!");
}
this.children[child.name] = child;
}

get(name) {
if(!name) {
return element(this.locator);
}
if(this.children.hasOwnProperty(name)) {
return this.children[name].get();
}

throw new Error(`${name} Element is not found!`);
}
}

module.exports = Element;
26 changes: 25 additions & 1 deletion module-3/pop/Elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,28 @@
* in the collection by the locator (.all()) in it's context
* 6. It has a method to retrieve one element from the collection
* by the locator (.get(n)) in it's context
*/
*/

const Element = require("./Element");

class Elements extends Element {
constructor(name, locator) {
super(name, locator);

this.children = null;
}

addChildren() {
throw new Error("Elements cannot have children!");
}

all() {
return element.all(this.locator);
}

get(n) {
return this.all().get(n);
}
}

module.exports = Elements;
24 changes: 23 additions & 1 deletion module-3/pop/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@
* Create HomePage class representing the EPAM.com home page.
* Add main widgets and element of the page and write tests
* for it (test/pop/HomePage.spec.js).
*/
*/
const Layout = require("./Layout");
const Element = require("./Element");

class HomePage extends Layout{
constructor(){
super('EPAM Home Page', 'https://www.epam.com/', { css: 'body' });

this.logoElement = new Element('Logo', { css: '.header__logo' });
this.addChildren(this.logoElement);

this.contactUs = new Element("Contact Us", {css: '.cta-button__text'});
this.addChildren(this.contactUs);

this.titleElement = new Element('Title', { css: 'span.title-slider__slide-row' });
this.addChildren(this.titleElement);

this.footerOurBrands = new Element('Our Brands', { css: ".footer__brands-title" });
this.addChildren(this.footerOurBrands);
}
}

module.exports = HomePage;
23 changes: 22 additions & 1 deletion module-3/pop/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,25 @@
* by name in any depth
* 7. It has a method to load the page, i.e. Navigates to
* the URL of it (.load())
*/
*/

const Element = require("./Element");

class Layout extends Element {
constructor(name, url, locator) {
super(name, locator);
this.url = url;
this.parent = null;
this.children = {};
}

setParent() {
throw new Error("It cannot have a parent element!");
}

load() {
return browser.get(this.url);
}
}

module.exports = Layout;
2 changes: 1 addition & 1 deletion module-3/test/pop/Elements.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Elements Class', () => {
const element = new Elements('Body', {css: 'body'});
const child = new Elements('Title', {css: 'h1'});

expect(() => element.addChildren(child)).to.throw();
expect(() => element.addChildren(child)).to.throw("Elements cannot have children!");
});
});

Expand Down
Loading