Skip to content

Commit fe2c3d2

Browse files
committed
Added homework for Closures and Scopes
1 parent 6ac9053 commit fe2c3d2

5 files changed

Lines changed: 104 additions & 4 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Classical Inheritance
2+
==================================
3+
4+
### Task 1.
5+
6+
* Create a module for working with books
7+
* The module must provide the following functionalities:
8+
* Add a new book to category
9+
* Each book has unique name, author and ISBN
10+
* List all books
11+
* Books are sorted by ID
12+
* This can be done by author, by category or all
13+
* Add new category
14+
* Each category has a unique name
15+
* List all categories
16+
* Categories are sorted by ID
17+
* Each book/catagory has a unique identifier (ID) that is a number greater than 1
18+
* When adding a book/category, the is generated automatically
19+
* Add validation everywhere, where possible
20+
* Book and category names must be between 2 and 100 characters, including letters, digits and special characters ('!', ',', '.', etc)
21+
* Unique params are Book name, Category name, and Book ISBN
22+
* Book authors can be repeated
23+
* If something is not valid - throw Error
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "test-driven-hw-mocha",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "mocha -R spec tests"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"devDependencies": {
12+
"chai": "^3.0.0"
13+
}
14+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Task Description */
2+
/*
3+
* Create a module for working with books
4+
* The module must provide the following functionalities:
5+
* Add a new book to category
6+
* Each book has unique name, author and ISBN
7+
* List all books
8+
* Books are sorted by ID
9+
* This can be done by author, by category or all
10+
* Add new category
11+
* Each category has a unique name
12+
* List all categories
13+
* Categories are sorted by ID
14+
* Each book/catagory has a unique identifier (ID) that is a number greater than 1
15+
* When adding a book/category, the is generated automatically
16+
* Add validation everywhere, where possible
17+
* Book and category names must be between 2 and 100 characters, including letters, digits and special characters ('!', ',', '.', etc)
18+
* Unique params are Book name, Category name, and Book ISBN
19+
* Book authors can be repeated
20+
* If something is not valid - throw Error
21+
*/
22+
function solve() {
23+
var library = (function () {
24+
25+
function listBooks() {
26+
27+
}
28+
29+
function addBook() {
30+
31+
}
32+
33+
function listCategories() {
34+
35+
}
36+
37+
function addCategory() {
38+
39+
}
40+
41+
return {
42+
books: {
43+
list: listBooks,
44+
add: addBook
45+
},
46+
categories: {
47+
list: listCategories,
48+
addCategory
49+
}
50+
};
51+
} ());
52+
return library;
53+
}
54+
module.exports = solve;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* globals describe, it */
2+
var Person = require('../tasks/task-1')();
3+
var expect = require('chai').expect;
4+
5+
describe('Tests for Closures and Scopes in JavaScript', function () {
6+
describe('"Task 1"', function () {
7+
/* soon */
8+
});
9+
});

‎03. Classical Inheritance/00. homework/tests/tests-task-1.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ describe('Tests for Classical Inheritance in JavaScript', function () {
106106

107107
it('expect introduce to be attached to prototype', function () {
108108
expect(Person.prototype).to.has.property('introduce');
109-
});
110-
109+
});
110+
111111
it('expect fullname setter to set firstname and lastname', function () {
112112
var person = new Person(CONSTS.VALID.FIRSTNAME, CONSTS.VALID.LASTNAME, CONSTS.VALID.AGE);
113113
var old = {
114114
fname: person.fname,
115115
lname: person.lname
116116
};
117-
117+
118118
person.fullname = person.fullname + 'z';
119119
expect(person.firstname).to.equal(old.firstname);
120-
expect(person.lastname).to.equal(old.lastname + 'z');
120+
expect(person.lastname).to.equal(old.lastname + 'z');
121121
});
122122
});
123123
});

0 commit comments

Comments
 (0)