class Human { #name; #surname; #birthday; constructor ( name = 'Jhon', surname = 'Doe' , birthday = new Date().toISOString().split`T`[0]) { this.#name = name this.#surname = surname this.#birthday = birthday } get name () { return this.#name } get surname () { return this.#surname } set name ( newName = 'Jhon' ) { this.#name = newName } set surname ( newSurname = 'Doe' ) { this.#surname = newSurname } get birthday () { return this.#birthday } getAge () { return `I'm ${(new Date() - new Date(this.#birthday))/1000/60/60/24/365|0} years old` } greeting () { return `Hello, my name is ${this.#name} ${this.#surname}` } } class Worker extends Human { #totalDays = 0 #hoursPerWeek = 0 #profession; constructor( name, surname, profession = 'Developer' ){ super() super.name = name super.surname = surname this.#profession = profession } get profession () { return this.#profession } get stats () { return { totalDays: this.#totalDays, hoursPerWeek: this.#hoursPerWeek } } doWork (hours = 8) { if (!(this.#totalDays % 7) && this.#totalDays) this.#hoursPerWeek = hours this.#hoursPerWeek += hours this.#totalDays += 1 return this } changeProfession ( newProfession ) { if ( !newProfession ) throw Error('The profession was not transferred!') if ( typeof newProfession !== 'string' ) throw TypeError('Incorrect new profession type!') this.#profession = newProfession this.#hoursPerWeek = 0 this.#totalDays = 0 return this } }
- class Human {
- #name;
- #surname;
constructor ( name = 'Jhon', surname = 'Doe' ) {- #birthday;
- constructor ( name = 'Jhon', surname = 'Doe' , birthday = new Date().toISOString().split`T`[0]) {
- this.#name = name
- this.#surname = surname
- this.#birthday = birthday
- }
- get name () {
- return this.#name
- }
- get surname () {
- return this.#surname
- }
- set name ( newName = 'Jhon' ) {
- this.#name = newName
- }
- set surname ( newSurname = 'Doe' ) {
- this.#surname = newSurname
- }
- get birthday () {
- return this.#birthday
- }
- getAge () {
- return `I'm ${(new Date() - new Date(this.#birthday))/1000/60/60/24/365|0} years old`
- }
- greeting () {
- return `Hello, my name is ${this.#name} ${this.#surname}`
- }
- }
- class Worker extends Human {
- #totalDays = 0
- #hoursPerWeek = 0
- #profession;
- constructor( name, surname, profession = 'Developer' ){
- super()
- super.name = name
- super.surname = surname
- this.#profession = profession
- }
- get profession () {
- return this.#profession
- }
- get stats () {
- return {
- totalDays: this.#totalDays,
- hoursPerWeek: this.#hoursPerWeek
- }
- }
- doWork (hours = 8) {
- if (!(this.#totalDays % 7) && this.#totalDays)
- this.#hoursPerWeek = hours
- this.#hoursPerWeek += hours
- this.#totalDays += 1
- return this
- }
- changeProfession ( newProfession ) {
- if ( !newProfession ) throw Error('The profession was not transferred!')
- if ( typeof newProfession !== 'string' ) throw TypeError('Incorrect new profession type!')
- this.#profession = newProfession
- this.#hoursPerWeek = 0
- this.#totalDays = 0
- return this
- }
- }
const { config, assert, expect } = require('chai') config.truncateThreshold = 0 const user0 = new Human(), user1 = new Human( 'Anatoly', 'Wasserman', '1952-12-09' ), user2 = new Human( 'Vladimir', 'Zelensky', '1978-01-25' ) describe('Humans tests:', () => { it('Creation tests', () => { assert.strictEqual( user0.name, 'Jhon' ) assert.strictEqual( user0.surname, 'Doe' ) assert.strictEqual( user0.birthday, new Date().toISOString().split`T`[0] ) assert.strictEqual( user1.name, 'Anatoly' ) assert.strictEqual( user1.surname, 'Wasserman' ) assert.strictEqual( user1.birthday, '1952-12-09') assert.strictEqual( user2.name, 'Vladimir' ) assert.strictEqual( user2.surname, 'Zelensky' ) assert.strictEqual( user2.birthday, '1978-01-25' ) }) it('Methods tests', () => { assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' ) assert.strictEqual( user0.getAge(), `I'm 0 years old` ) assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' ) assert.strictEqual( user1.getAge(), `I'm 69 years old` ) assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' ) assert.strictEqual( user2.getAge(), `I'm 44 years old` ) }) it('Mutation tests', () => { user0.name = 'Nils' assert.strictEqual( user0.name, 'Nils' ) assert.deepEqual( user0, {} ) user1.name = 'Albert' assert.strictEqual( user1.name, 'Albert' ) assert.deepEqual( user1, {} ) user2.name = 'Johann' assert.strictEqual( user2.name, 'Johann' ) assert.deepEqual( user2, {} ) }) }) const worker0 = new Worker('Nils', 'Bor', 'scientist'), worker1 = new Worker('Albert', 'Einstein','scientist'), worker2 = new Worker('Anatoly'), worker3 = new Worker('Vladimir', 'Zelensky', 'comedian') describe('Wokers tests', () => { it('Creation tests', () => { assert.strictEqual( worker0.name, 'Nils' ) assert.strictEqual( worker0.surname, 'Bor' ) assert.strictEqual( worker0.profession, 'scientist') assert.strictEqual( worker1.name, 'Albert' ) assert.strictEqual( worker1.surname, 'Einstein' ) assert.strictEqual( worker1.profession, 'scientist') }) it('Methods tests', () => { worker0.doWork() assert.deepEqual(worker0.stats,{totalDays:1,hoursPerWeek:8}) worker1.doWork().doWork(7).doWork(9).doWork(11).doWork(5) assert.deepEqual(worker1.stats,{totalDays:5,hoursPerWeek:40}) worker2.doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork() assert.deepEqual(worker2.stats,{totalDays:9,hoursPerWeek:24}) worker3.changeProfession('president') assert.strictEqual(worker3.profession, 'president') }) it('Error test', () => { let throwed = false, message, error try { worker0.changeProfession() } catch (err) { [error, message] = [err, err.message] } expect( error ).to.be.an.instanceof(Error, 'Throwed error should be instance of "Error" constructor!') assert.strictEqual( message, 'The profession was not transferred!' ) }) it('TypeError test', () => { let throwed = false, message, error try { worker1.changeProfession(1234) } catch (err) { [error, message] = [err, err.message] } expect( error ).to.be.an.instanceof(TypeError, 'Throwed error should be instance of "TypeError" constructor!') assert.strictEqual( message, 'Incorrect new profession type!' ) }) })
- const { config, assert, expect } = require('chai')
- config.truncateThreshold = 0
- const user0 = new Human(),
user1 = new Human('Anatoly', 'Wasserman'),user2 = new Human('Vladimir', 'Zelensky')- user1 = new Human( 'Anatoly', 'Wasserman', '1952-12-09' ),
- user2 = new Human( 'Vladimir', 'Zelensky', '1978-01-25' )
- describe('Humans tests:', () => {
- it('Creation tests', () => {
- assert.strictEqual( user0.name, 'Jhon' )
- assert.strictEqual( user0.surname, 'Doe' )
- assert.strictEqual( user0.birthday, new Date().toISOString().split`T`[0] )
- assert.strictEqual( user1.name, 'Anatoly' )
- assert.strictEqual( user1.surname, 'Wasserman' )
- assert.strictEqual( user1.birthday, '1952-12-09')
- assert.strictEqual( user2.name, 'Vladimir' )
- assert.strictEqual( user2.surname, 'Zelensky' )
- assert.strictEqual( user2.birthday, '1978-01-25' )
- })
- it('Methods tests', () => {
- assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' )
- assert.strictEqual( user0.getAge(), `I'm 0 years old` )
- assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' )
- assert.strictEqual( user1.getAge(), `I'm 69 years old` )
- assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' )
- assert.strictEqual( user2.getAge(), `I'm 44 years old` )
- })
- it('Mutation tests', () => {
- user0.name = 'Nils'
- assert.strictEqual( user0.name, 'Nils' )
- assert.deepEqual( user0, {} )
- user1.name = 'Albert'
- assert.strictEqual( user1.name, 'Albert' )
- assert.deepEqual( user1, {} )
- user2.name = 'Johann'
- assert.strictEqual( user2.name, 'Johann' )
- assert.deepEqual( user2, {} )
- })
- })
- const worker0 = new Worker('Nils', 'Bor', 'scientist'),
- worker1 = new Worker('Albert', 'Einstein','scientist'),
- worker2 = new Worker('Anatoly'),
- worker3 = new Worker('Vladimir', 'Zelensky', 'comedian')
- describe('Wokers tests', () => {
- it('Creation tests', () => {
- assert.strictEqual( worker0.name, 'Nils' )
- assert.strictEqual( worker0.surname, 'Bor' )
- assert.strictEqual( worker0.profession, 'scientist')
- assert.strictEqual( worker1.name, 'Albert' )
- assert.strictEqual( worker1.surname, 'Einstein' )
- assert.strictEqual( worker1.profession, 'scientist')
- })
- it('Methods tests', () => {
- worker0.doWork()
- assert.deepEqual(worker0.stats,{totalDays:1,hoursPerWeek:8})
- worker1.doWork().doWork(7).doWork(9).doWork(11).doWork(5)
- assert.deepEqual(worker1.stats,{totalDays:5,hoursPerWeek:40})
- worker2.doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork()
- assert.deepEqual(worker2.stats,{totalDays:9,hoursPerWeek:24})
- worker3.changeProfession('president')
- assert.strictEqual(worker3.profession, 'president')
- })
- it('Error test', () => {
- let throwed = false, message, error
- try {
- worker0.changeProfession()
- } catch (err) {
- [error, message] = [err, err.message]
- }
- expect( error ).to.be.an.instanceof(Error, 'Throwed error should be instance of "Error" constructor!')
- assert.strictEqual( message, 'The profession was not transferred!' )
- })
- it('TypeError test', () => {
- let throwed = false, message, error
- try {
- worker1.changeProfession(1234)
- } catch (err) {
- [error, message] = [err, err.message]
- }
- expect( error ).to.be.an.instanceof(TypeError, 'Throwed error should be instance of "TypeError" constructor!')
- assert.strictEqual( message, 'Incorrect new profession type!' )
- })
- })
class Human { #name; #surname; constructor ( name = 'Jhon', surname = 'Doe' ) { this.#name = name this.#surname = surname } get name () { return this.#name } get surname () { return this.#surname } set name ( newName = 'Jhon' ) { this.#name = newName } set surname ( newSurname = 'Doe' ) { this.#surname = newSurname } greeting () { return `Hello, my name is ${this.#name} ${this.#surname}` } } class Worker extends Human { #totalDays = 0 #hoursPerWeek = 0 constructor( name, surname, profession = 'Developer' ){ super() super.name = name super.surname = surname this.profession = profession } get stats () { return { totalDays: this.#totalDays, hoursPerWeek: this.#hoursPerWeek } } doWork (hours = 8) { if (!(this.#totalDays % 7) && this.#totalDays) this.#hoursPerWeek = hours this.#hoursPerWeek += hours this.#totalDays += 1 return this } }
class User {#name;#surname;constructor ( name = 'Jhon', surname = 'Doe' ) {this.#name = namethis.#surname = surname}get name () {return this.#name}get surname () {return this.#surname}greeting () {return `Hello, my name is ${this.#name} ${this.#surname}`}- class Human {
- #name;
- #surname;
- constructor ( name = 'Jhon', surname = 'Doe' ) {
- this.#name = name
- this.#surname = surname
- }
- get name () {
- return this.#name
- }
- get surname () {
- return this.#surname
- }
- set name ( newName = 'Jhon' ) {
- this.#name = newName
- }
- set surname ( newSurname = 'Doe' ) {
- this.#surname = newSurname
- }
- greeting () {
- return `Hello, my name is ${this.#name} ${this.#surname}`
- }
- }
- class Worker extends Human {
- #totalDays = 0
- #hoursPerWeek = 0
- constructor( name, surname, profession = 'Developer' ){
- super()
- super.name = name
- super.surname = surname
- this.profession = profession
- }
- get stats () {
- return {
- totalDays: this.#totalDays,
- hoursPerWeek: this.#hoursPerWeek
- }
- }
- doWork (hours = 8) {
- if (!(this.#totalDays % 7) && this.#totalDays)
- this.#hoursPerWeek = hours
- this.#hoursPerWeek += hours
- this.#totalDays += 1
- return this
- }
- }
const { config, assert } = require('chai') config.truncateThreshold = 0 const user0 = new Human(), user1 = new Human('Anatoly', 'Wasserman'), user2 = new Human('Vladimir', 'Zelensky') describe('Humans tests:', () => { it('Creation tests', () => { assert.strictEqual( user0.name, 'Jhon' ) assert.strictEqual( user0.surname, 'Doe' ) assert.strictEqual( user1.name, 'Anatoly' ) assert.strictEqual( user1.surname, 'Wasserman' ) assert.strictEqual( user2.name, 'Vladimir' ) assert.strictEqual( user2.surname, 'Zelensky' ) }) it('Methods tests', () => { assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' ) assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' ) assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' ) }) it('Mutation tests', () => { user0.name = 'Nils' assert.strictEqual( user0.name, 'Nils' ) assert.deepEqual( user0, {} ) user1.name = 'Albert' assert.strictEqual( user1.name, 'Albert' ) assert.deepEqual( user1, {} ) user2.name = 'Johann' assert.strictEqual( user2.name, 'Johann' ) assert.deepEqual( user2, {} ) }) }) const worker0 = new Worker('Nils', 'Bor', 'scientist'), worker1 = new Worker('Albert', 'Einstein','scientist'), worker2 = new Worker('Anatoly') describe('Wokers tests', () => { it('Creation tests', () => { assert.strictEqual( worker0.name, 'Nils' ) assert.strictEqual( worker0.surname, 'Bor' ) assert.strictEqual( worker0.profession, 'scientist') assert.strictEqual( worker1.name, 'Albert' ) assert.strictEqual( worker1.surname, 'Einstein' ) assert.strictEqual( worker1.profession, 'scientist') }) it('Methods tests', () => { worker0.doWork() assert.deepEqual(worker0.stats,{totalDays:1,hoursPerWeek:8}) worker1.doWork().doWork(7).doWork(9).doWork(11).doWork(5) assert.deepEqual(worker1.stats,{totalDays:5,hoursPerWeek:40}) worker2.doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork() assert.deepEqual(worker2.stats,{totalDays:9,hoursPerWeek:24}) }) })
- const { config, assert } = require('chai')
- config.truncateThreshold = 0
const user0 = new User(),user1 = new User('Anatoly', 'Wasserman'),user2 = new User('Vladimir', 'Zelensky')- const user0 = new Human(),
- user1 = new Human('Anatoly', 'Wasserman'),
- user2 = new Human('Vladimir', 'Zelensky')
describe("Base tests:", () => {- describe('Humans tests:', () => {
- it('Creation tests', () => {
- assert.strictEqual( user0.name, 'Jhon' )
- assert.strictEqual( user0.surname, 'Doe' )
- assert.strictEqual( user1.name, 'Anatoly' )
- assert.strictEqual( user1.surname, 'Wasserman' )
- assert.strictEqual( user2.name, 'Vladimir' )
- assert.strictEqual( user2.surname, 'Zelensky' )
- })
- it('Methods tests', () => {
- assert.strictEqual( user0.greeting(), 'Hello, my name is Jhon Doe' )
- assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' )
- assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' )
- })
- it('Mutation tests', () => {
- user0.name = 'Nils'
assert.strictEqual( user0.name, 'Jhon' )- assert.strictEqual( user0.name, 'Nils' )
- assert.deepEqual( user0, {} )
- user1.name = 'Albert'
assert.strictEqual( user1.name, 'Anatoly' )- assert.strictEqual( user1.name, 'Albert' )
- assert.deepEqual( user1, {} )
- user2.name = 'Johann'
assert.strictEqual( user2.name, 'Vladimir' )- assert.strictEqual( user2.name, 'Johann' )
- assert.deepEqual( user2, {} )
- })
- })
- const worker0 = new Worker('Nils', 'Bor', 'scientist'),
- worker1 = new Worker('Albert', 'Einstein','scientist'),
- worker2 = new Worker('Anatoly')
- describe('Wokers tests', () => {
- it('Creation tests', () => {
- assert.strictEqual( worker0.name, 'Nils' )
- assert.strictEqual( worker0.surname, 'Bor' )
- assert.strictEqual( worker0.profession, 'scientist')
- assert.strictEqual( worker1.name, 'Albert' )
- assert.strictEqual( worker1.surname, 'Einstein' )
- assert.strictEqual( worker1.profession, 'scientist')
- })
- it('Methods tests', () => {
- worker0.doWork()
- assert.deepEqual(worker0.stats,{totalDays:1,hoursPerWeek:8})
- worker1.doWork().doWork(7).doWork(9).doWork(11).doWork(5)
- assert.deepEqual(worker1.stats,{totalDays:5,hoursPerWeek:40})
- worker2.doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork().doWork()
- assert.deepEqual(worker2.stats,{totalDays:9,hoursPerWeek:24})
- })
- })
// why not ? power = ( a, b ) => eval([...Array(b)].fill(a).join`*`)??1
- // why not ?
add = x = ( a, b ) => b ? x(a ^ b, (a & b) << 1) : amul = y = ( a, b, c = 0 ) => !b ? c : y(a << 1, b >>> 1, b & 1 ? add(c, a) : c)power = f = ( a, b ) => b ? f( mul(a, 2), --b ) : a>>1- power = ( a, b ) => eval([...Array(b)].fill(a).join`*`)??1
class User { constructor (name, surname) { this.name = name this.surname = surname } greeting () { return `Hello, my name is ${this.name} ${this.surname}` } }
function User(name, surname){- class User {
- constructor (name, surname) {
- this.name = name
- this.surname = surname
- }
- greeting () {
- return `Hello, my name is ${this.name} ${this.surname}`
- }
- }
const { config, assert } = require('chai') config.truncateThreshold = 0 const user1 = new User('Anatoly', 'Wasserman'), user2 = new User('Vladimir', 'Zelensky') describe("Base tests:", () => { it('Creation tests', () => { assert.deepEqual( user1, { name: 'Anatoly', surname: 'Wasserman' } ) assert.deepEqual( user2, { name: 'Vladimir', surname: 'Zelensky' } ) }) it('Methods tests', () => { assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' ) assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' ) }) })
const { config, assert } = require("chai")- const { config, assert } = require('chai')
- config.truncateThreshold = 0
describe("Base tests:", function() {it(":^)", function() {assert.deepEqual( new User('Anatoly', 'Wasserman'), { name: 'Anatoly', surname: 'Wasserman' } )assert.deepEqual( new User('React', 'Developer'), { name: 'React', surname: 'Developer' } )- const user1 = new User('Anatoly', 'Wasserman'),
- user2 = new User('Vladimir', 'Zelensky')
- describe("Base tests:", () => {
- it('Creation tests', () => {
- assert.deepEqual( user1, { name: 'Anatoly', surname: 'Wasserman' } )
- assert.deepEqual( user2, { name: 'Vladimir', surname: 'Zelensky' } )
- })
- it('Methods tests', () => {
- assert.strictEqual( user1.greeting(), 'Hello, my name is Anatoly Wasserman' )
- assert.strictEqual( user2.greeting(), 'Hello, my name is Vladimir Zelensky' )
- })
- })