├── .gitignore ├── 00000-raw ├── 001-sum │ ├── sum.js │ └── sum.test.js ├── 002-calculator │ ├── calculator.js │ └── calculator.test.js ├── 003-fizz-buzz-fizzBuzz │ ├── fizzBuzz.js │ └── fizzBuzz.test.js ├── 004-reverse-string │ ├── reverseString.js │ └── reverseString.test.js ├── 005-reverse-integer │ ├── reverseInteger.js │ └── reverseInteger.test.js ├── 006-palindrome │ ├── palindrome.js │ └── palindrome.test.js ├── 007-palindrome-integer │ ├── palindromeInteger.js │ └── palindromeInteger.test.js ├── 008-factorial │ ├── factorial.js │ └── factorial.test.js ├── 009-factorial-with-exception │ ├── factorialWithException.js │ └── factorialWithException.test.js └── 010-array-factorial-with-exception │ ├── arrayFactorialWithException.js │ └── arrayFactorialWithException.test.js ├── 001-sum ├── README.md ├── sum.js └── sum.test.js ├── 002-calculator ├── README.md ├── calculator.js └── calculator.test.js ├── 003-fizz-buzz-fizzBuzz ├── README.md ├── fizzBuzz.js └── fizzBuzz.test.js ├── 004-reverse-string ├── README.md ├── reverseString.js └── reverseString.test.js ├── 005-reverse-integer ├── README.md ├── reverseInteger.js └── reverseInteger.test.js ├── 006-palindrome ├── README.md ├── palindrome.js └── palindrome.test.js ├── 007-palindrome-integer ├── README.md ├── palindromeInteger.js └── palindromeInteger.test.js ├── 008-factorial ├── README.md ├── factorial.js └── factorial.test.js ├── 009-factorial-with-exception ├── README.md ├── factorialWithException.js └── factorialWithException.test.js ├── 010-array-factorial-with-exception ├── README.md ├── arrayFactorialWithException.js └── arrayFactorialWithException.test.js ├── Doc.pdf ├── LICENSE.md ├── README.md ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /coverage 3 | /000-archive 4 | /.vscode 5 | /.idea 6 | *.pptx 7 | *.doc 8 | *.docx 9 | *.xls 10 | *.xlsx 11 | *.psd -------------------------------------------------------------------------------- /00000-raw/001-sum/sum.js: -------------------------------------------------------------------------------- 1 | function sum (a,b) { 2 | // 3 | } 4 | 5 | module.exports = sum; -------------------------------------------------------------------------------- /00000-raw/001-sum/sum.test.js: -------------------------------------------------------------------------------- 1 | const sum = require("./sum"); 2 | 3 | test("it returns 5 for sum(2,3)", () => { 4 | expect(sum(2,3)).toBe(5); 5 | }); 6 | 7 | test("it returns 8 for sum(5,3)", () => { 8 | expect(sum(5,3)).toBe(8); 9 | }); -------------------------------------------------------------------------------- /00000-raw/002-calculator/calculator.js: -------------------------------------------------------------------------------- 1 | class Calculator { 2 | // 3 | } 4 | 5 | module.exports = Calculator; -------------------------------------------------------------------------------- /00000-raw/002-calculator/calculator.test.js: -------------------------------------------------------------------------------- 1 | const Calculator = require("./calculator"); 2 | 3 | const myCalculator = new Calculator(); 4 | 5 | 6 | // گروه تست های مربوط به وجود داشتن توابع 7 | describe("existance of functions:", () => { 8 | test("Add", () => { 9 | expect(typeof myCalculator.Add).toBe("function"); 10 | }); 11 | 12 | test("Sub", () => { 13 | expect(typeof myCalculator.Sub).toBe("function"); 14 | }); 15 | 16 | test("Mul", () => { 17 | expect(typeof myCalculator.Mul).toBe("function"); 18 | }); 19 | 20 | test("Div", () => { 21 | expect(typeof myCalculator.Div).toBe("function"); 22 | }); 23 | }); 24 | 25 | 26 | // گروه تست های مربوط به عملکرد صحیح توابع 27 | describe("functionality", () => { 28 | test("Add function works properly", () => { 29 | expect(myCalculator.Add(8,3)).toBe(11); 30 | }); 31 | 32 | test("Sub function works properly", () => { 33 | expect(myCalculator.Sub(8,3)).toBe(5); 34 | }); 35 | 36 | test("Mul function works properly", () => { 37 | expect(myCalculator.Mul(8,3)).toBe(24); 38 | }); 39 | 40 | test("Div function works properly", () => { 41 | expect(myCalculator.Div(8,3)).toBe(2); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /00000-raw/003-fizz-buzz-fizzBuzz/fizzBuzz.js: -------------------------------------------------------------------------------- 1 | function fizzBuzz(num) { 2 | // 3 | } 4 | 5 | module.exports = fizzBuzz; 6 | -------------------------------------------------------------------------------- /00000-raw/003-fizz-buzz-fizzBuzz/fizzBuzz.test.js: -------------------------------------------------------------------------------- 1 | const fizzBuzz = require("./fizzBuzz"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(fizzBuzz).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof fizzBuzz).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // گروه تست های مربوط به عملکرد صحیح توابع 15 | describe("functionality", () => { 16 | // تست ورودی صفر 17 | it("returns 'zero' for input of 0", () => { 18 | expect(fizzBuzz(0)).toBe("zero"); 19 | }); 20 | 21 | // تست ورودی بخش پذیر بر 3 22 | it("returns fizz for numbers with multiply of 3", () => { 23 | expect(fizzBuzz(3)).toBe("fizz"); 24 | expect(fizzBuzz(18)).toBe("fizz"); 25 | expect(fizzBuzz(24)).toBe("fizz"); 26 | expect(fizzBuzz(48)).toBe("fizz"); 27 | expect(fizzBuzz(93)).toBe("fizz"); 28 | expect(fizzBuzz(1236)).toBe("fizz"); 29 | }); 30 | 31 | // تست ورودی بخش پذیر بر 5 32 | it("returns buzz for numbers with multiply of 5", () => { 33 | expect(fizzBuzz(5)).toBe("buzz"); 34 | expect(fizzBuzz(20)).toBe("buzz"); 35 | expect(fizzBuzz(50)).toBe("buzz"); 36 | expect(fizzBuzz(80)).toBe("buzz"); 37 | expect(fizzBuzz(200)).toBe("buzz"); 38 | expect(fizzBuzz(1000)).toBe("buzz"); 39 | }); 40 | 41 | // تست ورودی بخش پذیر بر 15 42 | it("returns fizzbuzz for numbers with multiply of 3 and 5", () => { 43 | expect(fizzBuzz(15)).toBe("fizzbuzz"); 44 | expect(fizzBuzz(30)).toBe("fizzbuzz"); 45 | expect(fizzBuzz(45)).toBe("fizzbuzz"); 46 | expect(fizzBuzz(600)).toBe("fizzbuzz"); 47 | expect(fizzBuzz(1500)).toBe("fizzbuzz"); 48 | expect(fizzBuzz(6000)).toBe("fizzbuzz"); 49 | }); 50 | 51 | // تست ورودی های دیگر 52 | it("returns input number for other inputs", () => { 53 | expect(fizzBuzz(4)).toBe(4); 54 | expect(fizzBuzz(1)).toBe(1); 55 | expect(fizzBuzz(17)).toBe(17); 56 | expect(fizzBuzz(442)).toBe(442); 57 | expect(fizzBuzz(13)).toBe(13); 58 | expect(fizzBuzz(148)).toBe(148); 59 | expect(fizzBuzz(202)).toBe(202); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /00000-raw/004-reverse-string/reverseString.js: -------------------------------------------------------------------------------- 1 | function reverseString(inputString) { 2 | // 3 | } 4 | 5 | 6 | module.exports = reverseString; 7 | -------------------------------------------------------------------------------- /00000-raw/004-reverse-string/reverseString.test.js: -------------------------------------------------------------------------------- 1 | const reverseString = require("./reverseString"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(reverseString).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof reverseString).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // گروه تست های مربوط به عملکرد صحیح توابع 15 | describe("functionality", () => { 16 | 17 | test('it should return dcba for input of abcd', () => { 18 | expect(reverseString('abcd')).toEqual('dcba'); 19 | }); 20 | 21 | it('should return damamila for input of alimamad', () => { 22 | expect(reverseString('alimamad')).toEqual('damamila'); 23 | }); 24 | 25 | it('should return aliali for input of ilaila', () => { 26 | expect(reverseString('ilaila')).toEqual('aliali'); 27 | }); 28 | 29 | it('should return دمحم for input of محمد', () => { 30 | expect(reverseString('محمد')).toEqual('دمحم'); 31 | }); 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /00000-raw/005-reverse-integer/reverseInteger.js: -------------------------------------------------------------------------------- 1 | function reverseInteger(inputNumber) { 2 | // 3 | } 4 | 5 | 6 | module.exports = reverseInteger; -------------------------------------------------------------------------------- /00000-raw/005-reverse-integer/reverseInteger.test.js: -------------------------------------------------------------------------------- 1 | const reverseInteger = require("./reverseInteger"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(reverseInteger).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof reverseInteger).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // گروه تست های مربوط به عملکرد صحیح توابع 15 | describe("functionality", () => { 16 | 17 | // عملکرد ورودی صفر 18 | it("handles 0 as an input", () => { 19 | expect(reverseInteger(0)).toEqual(0); 20 | }); 21 | 22 | // عملکرد ورودی مثبت 23 | it("reverse positive numbers", () => { 24 | expect(reverseInteger(3)).toEqual(3); 25 | expect(reverseInteger(1383)).toEqual(3831); 26 | expect(reverseInteger(1200)).toEqual(21); 27 | expect(reverseInteger(142)).toEqual(241); 28 | expect(reverseInteger(141)).toEqual(141); 29 | }); 30 | 31 | // عملکرد ورودی منفی 32 | it("reverse negative numbers", () => { 33 | expect(reverseInteger(-3)).toEqual(-3); 34 | expect(reverseInteger(-1383)).toEqual(-3831); 35 | expect(reverseInteger(-1200)).toEqual(-21); 36 | expect(reverseInteger(-142)).toEqual(-241); 37 | expect(reverseInteger(-141)).toEqual(-141); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /00000-raw/006-palindrome/palindrome.js: -------------------------------------------------------------------------------- 1 | function palindrome(inputString) { 2 | // 3 | } 4 | 5 | module.exports = palindrome; 6 | -------------------------------------------------------------------------------- /00000-raw/006-palindrome/palindrome.test.js: -------------------------------------------------------------------------------- 1 | const palindrome = require("./palindrome"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | 6 | it("defined", () => { 7 | expect(palindrome).toBeDefined(); 8 | }); 9 | 10 | it("is a function", () => { 11 | expect(typeof palindrome).toEqual("function"); 12 | }); 13 | }); 14 | 15 | // Functionality 16 | describe("functionality", () => { 17 | 18 | it('should return true for input of "mam" ', () => { 19 | expect(palindrome("mam")).toBe(true); 20 | }); 21 | 22 | it('should return false for input of "mama" ', () => { 23 | expect(palindrome("mama")).toBe(false); 24 | }); 25 | 26 | it('should return true for input of "Mammam" ', () => { 27 | expect(palindrome("Mammam")).toBe(true); 28 | }); 29 | 30 | it('should return false for input of "asdf" ', () => { 31 | expect(palindrome("asdf")).toBe(false); 32 | }); 33 | 34 | it('should return true for input of "asdfdsa" ', () => { 35 | expect(palindrome("asdfdsa")).toBe(true); 36 | }); 37 | 38 | }); 39 | -------------------------------------------------------------------------------- /00000-raw/007-palindrome-integer/palindromeInteger.js: -------------------------------------------------------------------------------- 1 | function palindromeInteger(inputNumber) { 2 | // 3 | } 4 | 5 | module.exports = palindromeInteger; 6 | -------------------------------------------------------------------------------- /00000-raw/007-palindrome-integer/palindromeInteger.test.js: -------------------------------------------------------------------------------- 1 | const palindromeInteger = require("./palindromeInteger"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | // General Tests 5 | describe("existance of functions:", () => { 6 | 7 | it("defined", () => { 8 | expect(palindromeInteger).toBeDefined(); 9 | }); 10 | 11 | it("is a function", () => { 12 | expect(typeof palindromeInteger).toEqual("function"); 13 | }); 14 | }); 15 | 16 | 17 | 18 | // گروه تست های مربوط به عملکرد صحیح توابع 19 | describe("functionality", () => { 20 | 21 | // عملکرد ورودی صفر 22 | it("handles 0 as an input", () => { 23 | expect(palindromeInteger(0)).toEqual(false); 24 | }); 25 | 26 | // عملکرد ورودی مثبت 27 | it("validates reverse positive numbers results", () => { 28 | expect(palindromeInteger(1)).toBe(true); 29 | expect(palindromeInteger(10)).toBe(false); 30 | expect(palindromeInteger(121)).toBe(true); 31 | expect(palindromeInteger(1221)).toBe(true); 32 | expect(palindromeInteger(12321)).toBe(true); 33 | expect(palindromeInteger(12322)).toBe(false); 34 | expect(palindromeInteger(1234321)).toBe(true); 35 | expect(palindromeInteger(12564321)).toBe(false); 36 | }); 37 | 38 | // عملکرد ورودی منفی 39 | it("validates reverse negative numbers results", () => { 40 | expect(palindromeInteger(-1)).toBe(true); 41 | expect(palindromeInteger(-10)).toBe(false); 42 | expect(palindromeInteger(-121)).toBe(true); 43 | expect(palindromeInteger(-1221)).toBe(true); 44 | expect(palindromeInteger(-12321)).toBe(true); 45 | expect(palindromeInteger(-12322)).toBe(false); 46 | expect(palindromeInteger(-1234321)).toBe(true); 47 | expect(palindromeInteger(-12564321)).toBe(false); 48 | }); 49 | }); -------------------------------------------------------------------------------- /00000-raw/008-factorial/factorial.js: -------------------------------------------------------------------------------- 1 | function factorial(inputNumber) { 2 | // 3 | } 4 | 5 | module.exports = factorial; 6 | -------------------------------------------------------------------------------- /00000-raw/008-factorial/factorial.test.js: -------------------------------------------------------------------------------- 1 | const factorial = require("./factorial"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(factorial).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof factorial).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // Functionality tests 15 | describe("functionality", () => { 16 | it("should return 1 for input of 0", () => { 17 | expect(factorial(0)).toBe(1); 18 | }); 19 | 20 | it("should return 1 for input of 1", () => { 21 | expect(factorial(1)).toBe(1); 22 | }); 23 | 24 | it("should return 2 for input of 2", () => { 25 | expect(factorial(2)).toBe(2); 26 | }); 27 | 28 | it("should return 6 for input of 3", () => { 29 | expect(factorial(3)).toBe(6); 30 | }); 31 | 32 | it("should return 24 for input of 4", () => { 33 | expect(factorial(4)).toBe(24); 34 | }); 35 | 36 | it("should return 120 for input of 5", () => { 37 | expect(factorial(5)).toBe(120); 38 | }); 39 | 40 | it("should return 720 for input of 6", () => { 41 | expect(factorial(6)).toBe(720); 42 | }); 43 | 44 | it("should return 5040 for input of 7", () => { 45 | expect(factorial(7)).toBe(5040); 46 | }); 47 | 48 | it("should return 40320 for input of 8", () => { 49 | expect(factorial(8)).toBe(40320); 50 | }); 51 | 52 | it("should return 362880 for input of 9", () => { 53 | expect(factorial(9)).toBe(362880); 54 | }); 55 | 56 | it("should return 3628800 for input of 10", () => { 57 | expect(factorial(10)).toBe(3628800); 58 | }); 59 | 60 | it("should return 39916800 for input of 11", () => { 61 | expect(factorial(11)).toBe(39916800); 62 | }); 63 | 64 | it("should return 479001600 for input of 12", () => { 65 | expect(factorial(12)).toBe(479001600); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /00000-raw/009-factorial-with-exception/factorialWithException.js: -------------------------------------------------------------------------------- 1 | function factorialWithException(inputNumber) { 2 | // 3 | } 4 | 5 | module.exports = factorialWithException; 6 | -------------------------------------------------------------------------------- /00000-raw/009-factorial-with-exception/factorialWithException.test.js: -------------------------------------------------------------------------------- 1 | const factorialWithException = require("./factorialWithException"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(factorialWithException).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof factorialWithException).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // Functionality tests 15 | describe("functionality", () => { 16 | it("should Throw an 'negative' Exception for input of -5", () => { 17 | expect(() => factorialWithException(-5)).toThrow("negative"); 18 | }); 19 | 20 | it("should Throw an 'zero' Exception for input of 0", () => { 21 | expect(() => factorialWithException(0)).toThrow("zero"); 22 | }); 23 | 24 | it("should return 1 for input of 1", () => { 25 | expect(factorialWithException(1)).toBe(1); 26 | }); 27 | 28 | it("should return 120 for input of 5", () => { 29 | expect(factorialWithException(5)).toBe(120); 30 | }); 31 | 32 | it("should return 3628800 for input of 10", () => { 33 | expect(factorialWithException(10)).toBe(3628800); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /00000-raw/010-array-factorial-with-exception/arrayFactorialWithException.js: -------------------------------------------------------------------------------- 1 | const arrayFactorialWithException = (inputArray) => { 2 | // 3 | }; 4 | 5 | module.exports = arrayFactorialWithException; 6 | -------------------------------------------------------------------------------- /00000-raw/010-array-factorial-with-exception/arrayFactorialWithException.test.js: -------------------------------------------------------------------------------- 1 | const arrayFactorialWithException = require("./arrayFactorialWithException"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(arrayFactorialWithException).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof arrayFactorialWithException).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // Functionality tests 15 | describe("functionality", () => { 16 | it("should return [6,120] for input [3,5] ", () => { 17 | expect(arrayFactorialWithException([3, 5])).toEqual([6, 120]); 18 | }); 19 | 20 | it("should return [6,24] for input [3,5] ", () => { 21 | expect(arrayFactorialWithException([3, 4])).toEqual([6, 24]); 22 | }); 23 | 24 | it("should return [6,40320,362880] for input [3,8,9]", () => { 25 | expect(arrayFactorialWithException([3, 8, 9])).toEqual([6, 40320, 362880]); 26 | }); 27 | 28 | it("Should throw an error for input of [3,-2]", () => { 29 | expect(() => arrayFactorialWithException([3, -2])).toThrow(); 30 | }); 31 | 32 | it("Should throw an error for input of [-4,18]", () => { 33 | expect(() => arrayFactorialWithException([-4, 18])).toThrow(); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /001-sum/README.md: -------------------------------------------------------------------------------- 1 | ## Task 001: 001-sum 2 | 3 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-frontend-activity-6922231875583266817-ThHe?utm_source=linkedin_share&utm_medium=member_desktop_web) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=JBWOHmSTpng) -------------------------------------------------------------------------------- /001-sum/sum.js: -------------------------------------------------------------------------------- 1 | function sum (a,b) { 2 | const sumOfInput = a + b; 3 | return sumOfInput; 4 | } 5 | 6 | module.exports = sum; -------------------------------------------------------------------------------- /001-sum/sum.test.js: -------------------------------------------------------------------------------- 1 | const sum = require("./sum"); 2 | 3 | test("it returns 5 for sum(2,3)", () => { 4 | expect(sum(2,3)).toBe(5); 5 | }); 6 | 7 | test("it returns 8 for sum(5,3)", () => { 8 | expect(sum(5,3)).toBe(8); 9 | }); -------------------------------------------------------------------------------- /002-calculator/README.md: -------------------------------------------------------------------------------- 1 | ## Task 002: 002-calculator 2 | 3 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-jest-activity-6923556425830965248-Ax8O?utm_source=linkedin_share&utm_medium=member_desktop_web) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=-0a2djndJeU) -------------------------------------------------------------------------------- /002-calculator/calculator.js: -------------------------------------------------------------------------------- 1 | class Calculator { 2 | Add(a, b) { 3 | return a + b; 4 | } 5 | Sub(a, b) { 6 | return a - b; 7 | } 8 | Mul(a, b) { 9 | return a * b; 10 | } 11 | Div(a, b) { 12 | return Math.floor(a / b); 13 | } 14 | } 15 | 16 | module.exports = Calculator; -------------------------------------------------------------------------------- /002-calculator/calculator.test.js: -------------------------------------------------------------------------------- 1 | const Calculator = require("./calculator"); 2 | 3 | const myCalculator = new Calculator(); 4 | 5 | 6 | // گروه تست های مربوط به وجود داشتن توابع 7 | describe("existance of functions:", () => { 8 | test("Add", () => { 9 | expect(typeof myCalculator.Add).toBe("function"); 10 | }); 11 | 12 | test("Sub", () => { 13 | expect(typeof myCalculator.Sub).toBe("function"); 14 | }); 15 | 16 | test("Mul", () => { 17 | expect(typeof myCalculator.Mul).toBe("function"); 18 | }); 19 | 20 | test("Div", () => { 21 | expect(typeof myCalculator.Div).toBe("function"); 22 | }); 23 | }); 24 | 25 | 26 | // گروه تست های مربوط به عملکرد صحیح توابع 27 | describe("functionality", () => { 28 | test("Add function works properly", () => { 29 | expect(myCalculator.Add(8,3)).toBe(11); 30 | }); 31 | 32 | test("Sub function works properly", () => { 33 | expect(myCalculator.Sub(8,3)).toBe(5); 34 | }); 35 | 36 | test("Mul function works properly", () => { 37 | expect(myCalculator.Mul(8,3)).toBe(24); 38 | }); 39 | 40 | test("Div function works properly", () => { 41 | expect(myCalculator.Div(8,3)).toBe(2); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /003-fizz-buzz-fizzBuzz/README.md: -------------------------------------------------------------------------------- 1 | ## Task 003: 003-fizz-buzz-fizzBuzz 2 | 3 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-jest-activity-6925803578406125568-1qRR?utm_source=linkedin_share&utm_medium=member_desktop_web) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=kMVgGN_vg5c) -------------------------------------------------------------------------------- /003-fizz-buzz-fizzBuzz/fizzBuzz.js: -------------------------------------------------------------------------------- 1 | function fizzBuzz(num) { 2 | if (num === 0) return "zero"; 3 | if ((num % 3 === 0) && (num % 5 === 0)) return "fizzbuzz"; 4 | if (num % 3 === 0) return "fizz"; 5 | if (num % 5 === 0) return "buzz"; 6 | return num; 7 | } 8 | 9 | module.exports = fizzBuzz; 10 | -------------------------------------------------------------------------------- /003-fizz-buzz-fizzBuzz/fizzBuzz.test.js: -------------------------------------------------------------------------------- 1 | const fizzBuzz = require("./fizzBuzz"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(fizzBuzz).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof fizzBuzz).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // گروه تست های مربوط به عملکرد صحیح توابع 15 | describe("functionality", () => { 16 | // تست ورودی صفر 17 | it("returns 'zero' for input of 0", () => { 18 | expect(fizzBuzz(0)).toBe("zero"); 19 | }); 20 | 21 | // تست ورودی بخش پذیر بر 3 22 | it("returns fizz for numbers with multiply of 3", () => { 23 | expect(fizzBuzz(3)).toBe("fizz"); 24 | expect(fizzBuzz(18)).toBe("fizz"); 25 | expect(fizzBuzz(24)).toBe("fizz"); 26 | expect(fizzBuzz(48)).toBe("fizz"); 27 | expect(fizzBuzz(93)).toBe("fizz"); 28 | expect(fizzBuzz(1236)).toBe("fizz"); 29 | }); 30 | 31 | // تست ورودی بخش پذیر بر 5 32 | it("returns buzz for numbers with multiply of 5", () => { 33 | expect(fizzBuzz(5)).toBe("buzz"); 34 | expect(fizzBuzz(20)).toBe("buzz"); 35 | expect(fizzBuzz(50)).toBe("buzz"); 36 | expect(fizzBuzz(80)).toBe("buzz"); 37 | expect(fizzBuzz(200)).toBe("buzz"); 38 | expect(fizzBuzz(1000)).toBe("buzz"); 39 | }); 40 | 41 | // تست ورودی بخش پذیر بر 15 42 | it("returns fizzbuzz for numbers with multiply of 3 and 5", () => { 43 | expect(fizzBuzz(15)).toBe("fizzbuzz"); 44 | expect(fizzBuzz(30)).toBe("fizzbuzz"); 45 | expect(fizzBuzz(45)).toBe("fizzbuzz"); 46 | expect(fizzBuzz(600)).toBe("fizzbuzz"); 47 | expect(fizzBuzz(1500)).toBe("fizzbuzz"); 48 | expect(fizzBuzz(6000)).toBe("fizzbuzz"); 49 | }); 50 | 51 | // تست ورودی های دیگر 52 | it("returns input number for other inputs", () => { 53 | expect(fizzBuzz(4)).toBe(4); 54 | expect(fizzBuzz(1)).toBe(1); 55 | expect(fizzBuzz(17)).toBe(17); 56 | expect(fizzBuzz(442)).toBe(442); 57 | expect(fizzBuzz(13)).toBe(13); 58 | expect(fizzBuzz(148)).toBe(148); 59 | expect(fizzBuzz(202)).toBe(202); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /004-reverse-string/README.md: -------------------------------------------------------------------------------- 1 | ## Task 004: 004-reverse-string 2 | 3 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-jest-activity-6927262347858231296-ffdn?utm_source=linkedin_share&utm_medium=member_desktop_web) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=prC7M7wUKg4) -------------------------------------------------------------------------------- /004-reverse-string/reverseString.js: -------------------------------------------------------------------------------- 1 | // # 1 2 | // function reverseString(inputString) { 3 | // let temp = ""; 4 | 5 | // for(let i = inputString.length - 1; i >= 0; i--) { 6 | // temp += inputString[i]; 7 | // } 8 | 9 | // return temp; 10 | // } 11 | 12 | // # 2 13 | // function reverseString(inputString) { 14 | // let temp = inputString.split(''); 15 | // temp = temp.reverse(); 16 | // return temp.join(''); 17 | // } 18 | 19 | // # 3 20 | function reverseString(inputString) { 21 | let temp = ""; 22 | 23 | for (let char of inputString) { 24 | temp = char + temp; 25 | } 26 | 27 | return temp; 28 | } 29 | 30 | 31 | module.exports = reverseString; 32 | -------------------------------------------------------------------------------- /004-reverse-string/reverseString.test.js: -------------------------------------------------------------------------------- 1 | const reverseString = require("./reverseString"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(reverseString).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof reverseString).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // گروه تست های مربوط به عملکرد صحیح توابع 15 | describe("functionality", () => { 16 | 17 | test('it should return dcba for input of abcd', () => { 18 | expect(reverseString('abcd')).toEqual('dcba'); 19 | }); 20 | 21 | it('should return damamila for input of alimamad', () => { 22 | expect(reverseString('alimamad')).toEqual('damamila'); 23 | }); 24 | 25 | it('should return aliali for input of ilaila', () => { 26 | expect(reverseString('ilaila')).toEqual('aliali'); 27 | }); 28 | 29 | it('should return دمحم for input of محمد', () => { 30 | expect(reverseString('محمد')).toEqual('دمحم'); 31 | }); 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /005-reverse-integer/README.md: -------------------------------------------------------------------------------- 1 | ## Task 005: 005-reverse-integer 2 | 3 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-jest-activity-6928282578672103424-X-cs?utm_source=linkedin_share&utm_medium=member_desktop_web) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=yRJCh_UA88g) -------------------------------------------------------------------------------- /005-reverse-integer/reverseInteger.js: -------------------------------------------------------------------------------- 1 | // # 1 2 | // function reverseInteger(inputNumber) { 3 | // temp = inputNumber.toString().split('').reverse().join(''); 4 | 5 | // return inputNumber >=0 ? parseInt(temp) : parseInt(temp) * -1; 6 | // } 7 | 8 | // # 2 9 | function reverseInteger(inputNumber) { 10 | temp = inputNumber.toString().split('').reverse().join(''); 11 | 12 | return parseInt(temp) * Math.sign(inputNumber); 13 | } 14 | 15 | 16 | module.exports = reverseInteger; -------------------------------------------------------------------------------- /005-reverse-integer/reverseInteger.test.js: -------------------------------------------------------------------------------- 1 | const reverseInteger = require("./reverseInteger"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(reverseInteger).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof reverseInteger).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // گروه تست های مربوط به عملکرد صحیح توابع 15 | describe("functionality", () => { 16 | 17 | // عملکرد ورودی صفر 18 | it("handles 0 as an input", () => { 19 | expect(reverseInteger(0)).toEqual(0); 20 | }); 21 | 22 | // عملکرد ورودی مثبت 23 | it("reverse positive numbers", () => { 24 | expect(reverseInteger(3)).toEqual(3); 25 | expect(reverseInteger(1383)).toEqual(3831); 26 | expect(reverseInteger(1200)).toEqual(21); 27 | expect(reverseInteger(142)).toEqual(241); 28 | expect(reverseInteger(141)).toEqual(141); 29 | }); 30 | 31 | // عملکرد ورودی منفی 32 | it("reverse negative numbers", () => { 33 | expect(reverseInteger(-3)).toEqual(-3); 34 | expect(reverseInteger(-1383)).toEqual(-3831); 35 | expect(reverseInteger(-1200)).toEqual(-21); 36 | expect(reverseInteger(-142)).toEqual(-241); 37 | expect(reverseInteger(-141)).toEqual(-141); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /006-palindrome/README.md: -------------------------------------------------------------------------------- 1 | ## Task 006: 006-palindrome 2 | 3 | ### Implementing Palindrome in JavaScript using TDD (Test Driven Developement) 4 | 5 | 6 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-jest-activity-6943574768415592449-y9vX?utm_source=linkedin_share&utm_medium=member_desktop_web) 7 | 8 | * [youtube video](https://www.youtube.com/watch?v=uLPbaEm2g6Y) -------------------------------------------------------------------------------- /006-palindrome/palindrome.js: -------------------------------------------------------------------------------- 1 | // Solution 1 2 | // function palindrome(inputString){ 3 | // //step 1 : reverse our input string 4 | // let reversedString = inputString.split('').reverse().join(''); 5 | 6 | // // step 2: check original and reverted string and return appropriate answer 7 | 8 | // if(inputString.toLowerCase() === reversedString.toLowerCase()) { 9 | // return true; 10 | // } else { 11 | // return false; 12 | // } 13 | // } 14 | 15 | // Solution 2 16 | // function palindrome(inputString){ 17 | // //step 1 : reverse out input string 18 | // let reversedString = inputString.split('').reverse().join(''); 19 | 20 | // // step 2: check original and reverted string and return appropriate answer 21 | 22 | // return (inputString.toLowerCase() === reversedString.toLowerCase()) ? true : false; 23 | // } 24 | 25 | // Solution 3 26 | function palindrome(inputString){ 27 | 28 | return (inputString.toLowerCase() === inputString.split('').reverse().join('').toLowerCase()) ? true : false; 29 | } 30 | 31 | module.exports = palindrome; -------------------------------------------------------------------------------- /006-palindrome/palindrome.test.js: -------------------------------------------------------------------------------- 1 | const palindrome = require("./palindrome"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | 6 | it("defined", () => { 7 | expect(palindrome).toBeDefined(); 8 | }); 9 | 10 | it("is a function", () => { 11 | expect(typeof palindrome).toEqual("function"); 12 | }); 13 | }); 14 | 15 | // Functionality 16 | describe("functionality", () => { 17 | 18 | it('should return true for input of "mam" ', () => { 19 | expect(palindrome("mam")).toBe(true); 20 | }); 21 | 22 | it('should return false for input of "mama" ', () => { 23 | expect(palindrome("mama")).toBe(false); 24 | }); 25 | 26 | it('should return true for input of "Mammam" ', () => { 27 | expect(palindrome("Mammam")).toBe(true); 28 | }); 29 | 30 | it('should return false for input of "asdf" ', () => { 31 | expect(palindrome("asdf")).toBe(false); 32 | }); 33 | 34 | it('should return true for input of "asdfdsa" ', () => { 35 | expect(palindrome("asdfdsa")).toBe(true); 36 | }); 37 | 38 | }); 39 | -------------------------------------------------------------------------------- /007-palindrome-integer/README.md: -------------------------------------------------------------------------------- 1 | ## Task 007: 007-palindrome-integer 2 | 3 | ### Implementing Palindrome Integer in JavaScript using TDD (Test Driven Developement) 4 | 5 | * [linkedin video](https://www.linkedin.com/posts/mohammad-taheri1_tdd-javascript-jest-activity-6956207636841127936-VUpE?utm_source=linkedin_share&utm_medium=member_desktop_web) 6 | 7 | * [youtube video](https://www.youtube.com/watch?v=L6aPf919WM8) -------------------------------------------------------------------------------- /007-palindrome-integer/palindromeInteger.js: -------------------------------------------------------------------------------- 1 | // Solution One -> with string convert and array helper functions 2 | // function palindromeInteger(inputNumber) { 3 | // // Step1: handle zero input 4 | // if(inputNumber === 0) return false; 5 | 6 | // // Step2: reverse input number 7 | // const reversedInput = inputNumber 8 | // .toString() 9 | // .split('') 10 | // .reverse() 11 | // .join(''); 12 | 13 | // // Step 3: return appropriate boolean value 14 | // // Dont forget the sign of input number 15 | // if( parseInt(inputNumber) === Math.sign(inputNumber) * parseInt(reversedInput)) { 16 | // return true; 17 | // } 18 | // return false; 19 | 20 | // } 21 | 22 | // Solution two -> just numbers operations 23 | function palindromeInteger(inputNumber) { 24 | if (inputNumber === 0) return false; 25 | 26 | let reversedNumber = 0; 27 | let originalNumber = inputNumber; 28 | 29 | if (inputNumber < 0) { 30 | originalNumber *= -1; 31 | } 32 | 33 | while (originalNumber > 0) { 34 | reversedNumber = reversedNumber * 10 + (originalNumber % 10); 35 | originalNumber = Math.floor(originalNumber / 10); 36 | console.log(`originalNumber: ${originalNumber} - rev : ${reversedNumber}`); 37 | } 38 | 39 | return reversedNumber * Math.sign(inputNumber) === inputNumber; 40 | } 41 | 42 | module.exports = palindromeInteger; 43 | -------------------------------------------------------------------------------- /007-palindrome-integer/palindromeInteger.test.js: -------------------------------------------------------------------------------- 1 | const palindromeInteger = require("./palindromeInteger"); 2 | 3 | // گروه تست های مربوط به وجود داشتن توابع 4 | // General Tests 5 | describe("existance of functions:", () => { 6 | 7 | it("defined", () => { 8 | expect(palindromeInteger).toBeDefined(); 9 | }); 10 | 11 | it("is a function", () => { 12 | expect(typeof palindromeInteger).toEqual("function"); 13 | }); 14 | }); 15 | 16 | 17 | 18 | // گروه تست های مربوط به عملکرد صحیح توابع 19 | describe("functionality", () => { 20 | 21 | // عملکرد ورودی صفر 22 | it("handles 0 as an input", () => { 23 | expect(palindromeInteger(0)).toEqual(false); 24 | }); 25 | 26 | // عملکرد ورودی مثبت 27 | it("validates reverse positive numbers results", () => { 28 | expect(palindromeInteger(1)).toBe(true); 29 | expect(palindromeInteger(10)).toBe(false); 30 | expect(palindromeInteger(121)).toBe(true); 31 | expect(palindromeInteger(1221)).toBe(true); 32 | expect(palindromeInteger(12321)).toBe(true); 33 | expect(palindromeInteger(12322)).toBe(false); 34 | expect(palindromeInteger(1234321)).toBe(true); 35 | expect(palindromeInteger(12564321)).toBe(false); 36 | }); 37 | 38 | // عملکرد ورودی منفی 39 | it("validates reverse negative numbers results", () => { 40 | expect(palindromeInteger(-1)).toBe(true); 41 | expect(palindromeInteger(-10)).toBe(false); 42 | expect(palindromeInteger(-121)).toBe(true); 43 | expect(palindromeInteger(-1221)).toBe(true); 44 | expect(palindromeInteger(-12321)).toBe(true); 45 | expect(palindromeInteger(-12322)).toBe(false); 46 | expect(palindromeInteger(-1234321)).toBe(true); 47 | expect(palindromeInteger(-12564321)).toBe(false); 48 | }); 49 | }); -------------------------------------------------------------------------------- /008-factorial/README.md: -------------------------------------------------------------------------------- 1 | ## Task 008: 008-factorial 2 | 3 | ### Implementing Factorial Function in JavaScript using TDD (Test Driven Developement) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=ZAitBqsWid4) -------------------------------------------------------------------------------- /008-factorial/factorial.js: -------------------------------------------------------------------------------- 1 | // hint 1: 2 | // 5! = 5 * 4 * 3 * 2 * 1 3 | 4 | // hint 2: 5 | // 5! 6 | // = 5 * 4! 7 | // = 5 * 4 * 3! 8 | // = 5 * 4 * 3 * 2! 9 | // = 5 * 4 * 3 * 2 * 1 10 | 11 | // Solution one 12 | // function factorial(inputNumber) { 13 | // let result = 1; 14 | 15 | // for (let i = inputNumber; i >= 1; i--) { 16 | // result *= i; 17 | // } 18 | 19 | // return result; 20 | // } 21 | 22 | // Solution Two 23 | function factorial(inputNumber) { 24 | if (inputNumber === 0) { 25 | return 1; 26 | } 27 | 28 | // = 5 * 4! 29 | return inputNumber * factorial(inputNumber - 1); 30 | } 31 | 32 | module.exports = factorial; 33 | -------------------------------------------------------------------------------- /008-factorial/factorial.test.js: -------------------------------------------------------------------------------- 1 | const factorial = require("./factorial"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(factorial).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof factorial).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // Functionality tests 15 | describe("functionality", () => { 16 | it("should return 1 for input of 0", () => { 17 | expect(factorial(0)).toBe(1); 18 | }); 19 | 20 | it("should return 1 for input of 1", () => { 21 | expect(factorial(1)).toBe(1); 22 | }); 23 | 24 | it("should return 2 for input of 2", () => { 25 | expect(factorial(2)).toBe(2); 26 | }); 27 | 28 | it("should return 6 for input of 3", () => { 29 | expect(factorial(3)).toBe(6); 30 | }); 31 | 32 | it("should return 24 for input of 4", () => { 33 | expect(factorial(4)).toBe(24); 34 | }); 35 | 36 | it("should return 120 for input of 5", () => { 37 | expect(factorial(5)).toBe(120); 38 | }); 39 | 40 | it("should return 720 for input of 6", () => { 41 | expect(factorial(6)).toBe(720); 42 | }); 43 | 44 | it("should return 5040 for input of 7", () => { 45 | expect(factorial(7)).toBe(5040); 46 | }); 47 | 48 | it("should return 40320 for input of 8", () => { 49 | expect(factorial(8)).toBe(40320); 50 | }); 51 | 52 | it("should return 362880 for input of 9", () => { 53 | expect(factorial(9)).toBe(362880); 54 | }); 55 | 56 | it("should return 3628800 for input of 10", () => { 57 | expect(factorial(10)).toBe(3628800); 58 | }); 59 | 60 | it("should return 39916800 for input of 11", () => { 61 | expect(factorial(11)).toBe(39916800); 62 | }); 63 | 64 | it("should return 479001600 for input of 12", () => { 65 | expect(factorial(12)).toBe(479001600); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /009-factorial-with-exception/README.md: -------------------------------------------------------------------------------- 1 | ## 009-factorial-with-exception 2 | 3 | ### Implementing Factorial with exception in JavaScript using TDD (Test Driven Developement) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=BJ2X98LbduY) -------------------------------------------------------------------------------- /009-factorial-with-exception/factorialWithException.js: -------------------------------------------------------------------------------- 1 | // Solution One 2 | // function factorialWithException(inputNumber) { 3 | // // negative check 4 | // if (inputNumber < 0) throw new Error("negative"); 5 | 6 | // // zero input 7 | // if (inputNumber === 0) throw new Error("zero"); 8 | 9 | // let result = 1; 10 | 11 | // for (let i = inputNumber; i >= 1; i--) { 12 | // result *= i; 13 | // } 14 | 15 | // return result; 16 | // } 17 | 18 | // Solution Two 19 | function factorialWithException(inputNumber) { 20 | // negative check 21 | if (inputNumber < 0) throw new Error("negative"); 22 | 23 | // zero input 24 | if (inputNumber === 0) throw new Error("zero"); 25 | 26 | if(inputNumber === 1) { 27 | return 1; 28 | } 29 | 30 | // 5! = 5 * 4! 31 | return inputNumber * factorialWithException(inputNumber - 1) 32 | 33 | 34 | } 35 | 36 | module.exports = factorialWithException; 37 | -------------------------------------------------------------------------------- /009-factorial-with-exception/factorialWithException.test.js: -------------------------------------------------------------------------------- 1 | const factorialWithException = require("./factorialWithException"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(factorialWithException).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof factorialWithException).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // Functionality tests 15 | describe("functionality", () => { 16 | it("should Throw an 'negative' Exception for input of -5", () => { 17 | expect(() => factorialWithException(-5)).toThrow("negative"); 18 | }); 19 | 20 | it("should Throw an 'zero' Exception for input of 0", () => { 21 | expect(() => factorialWithException(0)).toThrow("zero"); 22 | }); 23 | 24 | it("should return 1 for input of 1", () => { 25 | expect(factorialWithException(1)).toBe(1); 26 | }); 27 | 28 | it("should return 120 for input of 5", () => { 29 | expect(factorialWithException(5)).toBe(120); 30 | }); 31 | 32 | it("should return 3628800 for input of 10", () => { 33 | expect(factorialWithException(10)).toBe(3628800); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /010-array-factorial-with-exception/README.md: -------------------------------------------------------------------------------- 1 | ## 010-array-factorial-with-exception 2 | 3 | ### Implementing Factorial Of an array with exception in JavaScript using TDD (Test Driven Developement) 4 | 5 | * [youtube video](https://www.youtube.com/watch?v=-kWmtNTmf88) -------------------------------------------------------------------------------- /010-array-factorial-with-exception/arrayFactorialWithException.js: -------------------------------------------------------------------------------- 1 | // hint: 2 | 3 | // we must loop on our inputArray 4 | 5 | // if any item is negative, we will raise an exception. 6 | 7 | // else, we calculate the factorial of item 8 | 9 | // then, save the calculated factorial into an temp array 10 | 11 | // finally, return the temp array 12 | 13 | // Solution One 14 | // const arrayFactorialWithException = (inputArray) => { 15 | // let tempResultArray = []; 16 | 17 | // inputArray.forEach((item) => { 18 | // // 19 | // if (item < 0) throw new Error(); 20 | 21 | // let tempFactorialValue = 1; 22 | 23 | // for (let i = item; i >= 1; i--) { 24 | // tempFactorialValue *= i; 25 | // } 26 | 27 | // tempResultArray.push(tempFactorialValue); 28 | // }); 29 | 30 | // return tempResultArray; 31 | // }; 32 | 33 | // Solution Two 34 | const arrayFactorialWithException = (inputArray) => { 35 | let tempResultArray = []; 36 | 37 | inputArray.forEach((item) => { 38 | tempResultArray.push(factorial(item)); 39 | }); 40 | 41 | return tempResultArray; 42 | }; 43 | 44 | const factorial = (input) => { 45 | if (input < 0) throw new Error(); 46 | 47 | let tempFactorialValue = 1; 48 | 49 | for (let i = input; i >= 1; i--) { 50 | tempFactorialValue *= i; 51 | } 52 | 53 | return tempFactorialValue; 54 | }; 55 | 56 | module.exports = arrayFactorialWithException; 57 | -------------------------------------------------------------------------------- /010-array-factorial-with-exception/arrayFactorialWithException.test.js: -------------------------------------------------------------------------------- 1 | const arrayFactorialWithException = require("./arrayFactorialWithException"); 2 | 3 | // General Tests 4 | describe("existance of functions:", () => { 5 | it("defined", () => { 6 | expect(arrayFactorialWithException).toBeDefined(); 7 | }); 8 | 9 | it("is a function", () => { 10 | expect(typeof arrayFactorialWithException).toEqual("function"); 11 | }); 12 | }); 13 | 14 | // Functionality tests 15 | describe("functionality", () => { 16 | it("should return [6,120] for input [3,5] ", () => { 17 | expect(arrayFactorialWithException([3, 5])).toEqual([6, 120]); 18 | }); 19 | 20 | it("should return [6,24] for input [3,5] ", () => { 21 | expect(arrayFactorialWithException([3, 4])).toEqual([6, 24]); 22 | }); 23 | 24 | it("should return [6,40320,362880] for input [3,8,9]", () => { 25 | expect(arrayFactorialWithException([3, 8, 9])).toEqual([6, 40320, 362880]); 26 | }); 27 | 28 | it("Should throw an error for input of [3,-2]", () => { 29 | expect(() => arrayFactorialWithException([3, -2])).toThrow(); 30 | }); 31 | 32 | it("Should throw an error for input of [-4,18]", () => { 33 | expect(() => arrayFactorialWithException([-4, 18])).toThrow(); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /Doc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohammad-taheri1/TDD-Interview-JS/1b6418165c58d4df04a8f74b88c8ddd12ccb8112/Doc.pdf -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Mohammad Taheri 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Interview tasks with `test driven development` approach using JavaScript and Jest 2 | ![GitHub last commit](https://img.shields.io/github/last-commit/MamadTaheri/TDD-Interview-JS) 3 | ![GitHub Repo stars](https://img.shields.io/github/stars/MamadTaheri/TDD-Interview-JS?style=social) 4 | ![GitHub package.json version](https://img.shields.io/github/package-json/v/MamadTaheri/TDD-Interview-JS) 5 | ![GitHub](https://img.shields.io/github/license/MamadTaheri/TDD-Interview-JS) 6 | 7 | 8 | ## [Youtube Playlist of this repository](https://www.youtube.com/playlist?list=PLUX0GmrifrweqUwn0nHamSFEPc9L3zXF6) 9 | 10 | ## Content: 11 | ### Done 12 | - [X] 001- Summary 13 | - [X] 002- Calculator 14 | - [X] 003- Fizz-buzz-fizzBuzz 15 | - [X] 004- Reverse string 16 | - [X] 005- Reverse integer 17 | - [X] 006- Is palindrome 18 | - [X] 007- Integer is palindrome 19 | - [X] 008- Factorial 20 | - [X] 009- Factorial with exception 21 | - [X] 010- Array factorial with exception 22 | 23 | ### In progress 24 | - [ ] Fibonacci with exception 25 | - [ ] Valid parenthesis 26 | - [ ] Character counter 27 | - [ ] Maximum Characters 28 | - [ ] Anagrams 29 | - [ ] Stack 30 | - [ ] Queue 31 | 32 | 33 | ### How to download and install required libraries 34 | 35 | Run the following commands to start using this repository: 36 | 37 | 1- Clone the repository using the following command: 38 | 39 | ```bash 40 | git clone https://github.com/MamadTaheri68/TDD-Interview-JS.git 41 | ``` 42 | 43 | 2- Change directory to `TDD-Interview-JS` and run the following command: 44 | 45 | ```bash 46 | npm install 47 | ``` 48 | 49 | ### How to Run the tests 50 | 51 | Use one of the following commands to run your tests: 52 | 53 | ```bash 54 | npm run test 55 | npm run test:watch 56 | npm run test:watchAll 57 | npm run test:watchAll 58 | npm run test:cov 59 | npm run liveTest 60 | npm run fullTest 61 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tdd-interview-js", 3 | "version": "1.0.0", 4 | "description": "a simple repository for gathering some state-of-the-art interview questions and tasks along with related tests", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest", 8 | "liveTest": "jest --watchAll", 9 | "fullTest": "jest --coverage", 10 | "test:watch": "jest --watch", 11 | "test:watchAll": "jest --watchAll", 12 | "test:cov": "jest --coverage" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/MamadTaheri68/TDD-Interview-JS.git" 17 | }, 18 | "keywords": [], 19 | "author": "Mohammad Taheri(mamad.taheri.68@gmail.com)", 20 | "license": "ISC", 21 | "bugs": { 22 | "url": "https://github.com/MamadTaheri68/TDD-Interview-JS/issues" 23 | }, 24 | "homepage": "https://github.com/MamadTaheri68/TDD-Interview-JS#readme", 25 | "dependencies": { 26 | "@types/jest": "^27.4.1", 27 | "jest": "^27.5.1" 28 | } 29 | } 30 | --------------------------------------------------------------------------------