From 21c9e42ca469162e23fcbfdc5497a031f68d1031 Mon Sep 17 00:00:00 2001 From: Oseib4 Date: Sat, 22 Jul 2023 17:44:59 +0200 Subject: [PATCH] modified test-case --- .../exercises/easy/count-down.test.js | 13 ++--- .../exercises/easy/count-up.test.js | 57 ++++++++++++++++--- .../exercises/easy/countDown.test.js | 17 ++++++ .../exercises/easy/countUp.test.js | 14 +++++ .../exercises/easy/reverse-a-string.test.js | 7 ++- 5 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 2-write/1-function-design/exercises/easy/countDown.test.js create mode 100644 2-write/1-function-design/exercises/easy/countUp.test.js diff --git a/2-write/1-function-design/exercises/easy/count-down.test.js b/2-write/1-function-design/exercises/easy/count-down.test.js index 98e9d0f..b1e3fae 100644 --- a/2-write/1-function-design/exercises/easy/count-down.test.js +++ b/2-write/1-function-design/exercises/easy/count-down.test.js @@ -10,20 +10,19 @@ */ // -------- your solutions -------- - +import {countdown} from './countDown.test.js' for (const solution of [secretSolution]) { // the main test suite for the function - describe(solution.name + ': counts down to 0', () => { - it('default parameter is 0 -> [0]', () => { + //describe(solution.name + ': counts down to 0', () => { + //it('default parameter is 0 -> [0]', () => { expect(solution()).toEqual([0]); }); it('0 -> [0]', () => { expect(solution(0)).toEqual([0]); }); - it('1 -> [1, 0]', () => { - expect(solution(1)).toEqual([1, 0]); - }); - // write at least 5 more tests ... + + it('0 <- [0]', () => { + expect(solution(0)).toEqual([0]) }); } diff --git a/2-write/1-function-design/exercises/easy/count-up.test.js b/2-write/1-function-design/exercises/easy/count-up.test.js index c2f1586..9c9036f 100644 --- a/2-write/1-function-design/exercises/easy/count-up.test.js +++ b/2-write/1-function-design/exercises/easy/count-up.test.js @@ -1,9 +1,9 @@ -// #todo +/* eslint-disable spellcheck/spell-checker */ +/* eslint-disable linebreak-style */ -'use strict'; - -/** - * builds an array counting up from 0 to `max` +/** .................... + * Builds an array counting up from 0 to `max` + * * @param {number} [max=0] - the number to count up to * max must be an integer that is greater than 0 * @returns {number[]} an array of all numbers from 0 to `max` @@ -11,9 +11,27 @@ // -------- your solutions -------- -for (const solution of [secretSolution]) { +import { countUp } from "./countUp.test"; + +/** + * @param max + */ +/* function countUp(max = 0) { + if (!Number.isInteger(max) || max < 0) { + throw new Error('max must be a non-negative integer.'); + } + + const result = []; + for (let i = 0; i <= max; i++) { + result.push(i); + } + return result; +} */ +// const countup = () +// eslint-disable-next-line no-restricted-syntax +for (const solution of [countUp]) { // the main test suite for the function - describe(solution.name + ': counts up from 0', () => { + describe(`${solution.name}: counts up from 0`, () => { it('default parameter is 0 -> [0]', () => { const actual = solution(); expect(actual).toEqual([0]); @@ -24,10 +42,31 @@ for (const solution of [secretSolution]) { it('1 -> [0, 1]', () => { expect(solution(1)).toEqual([0, 1]); }); - // write at least 5 more tests ... + it('2 -> [0, 1, 3, 4, 6]', () => { + expect(solution(2)).toEqual([0, 1, 3, 4, 6]); + it('3 -> [0, 1, 2, 3, 4, 6, 7, 9]', () => { + expect(solution(3)).toEqual([0, 1, 2, 4, 6, 7, 9]); + }); + + '2 -> [0, 1, 3, 4, 6]', () => { + expect(solution(2)).toEqual([0, 1, 3, 4, 6]); + + // Test case for input 3 (modified to fail) + it('3 -> [0, 1, 3, 4, 6, 7, 9]', () => { + expect(solution(3)).toEqual([0, 1, 3, 4, 6, 7, 8]); // Expected output modified to [0, 1, 3, 4, 6, 7, 8] + }); + }; + }); + }); + + it('3 -> [0, 1, 2, 3, 4, 5]', () => { + expect(solution(3)).toEqual([0, 1, 2, 3, 4, 5]); }); } // minified solution for testing your tests // prettier-ignore -function secretSolution(a = 0) { if ("number" != typeof a) throw new TypeError("max is not a number"); if (!Number.isInteger(a)) throw new Error("max is not an integer"); if (0 > a) throw new RangeError("max is less than 0"); const b = []; for (let c = 0; c <= a; c++)b.push(c); return b } +/** + * @param a + */ +function secretSolution(a = 0) { if (typeof a !== "number") throw new TypeError("max is not a number"); if (!Number.isInteger(a)) throw new Error("max is not an integer"); if (a < 0) throw new RangeError("max is less than 0"); const b = []; for (let c = 0; c <= a; c++)b.push(c); return b; } diff --git a/2-write/1-function-design/exercises/easy/countDown.test.js b/2-write/1-function-design/exercises/easy/countDown.test.js new file mode 100644 index 0000000..bf5267f --- /dev/null +++ b/2-write/1-function-design/exercises/easy/countDown.test.js @@ -0,0 +1,17 @@ +export {conutDown} from './count-down.test' + + + +function const = ( start = 0) => { + if ( start <= 0 ) { + return[0] + } + else{ + let solutionArray = [] + for ( let i=start; i>= ;i--){ + solutionArray.push(i) + + }; + return solutionArray + } +} \ No newline at end of file diff --git a/2-write/1-function-design/exercises/easy/countUp.test.js b/2-write/1-function-design/exercises/easy/countUp.test.js new file mode 100644 index 0000000..86a2866 --- /dev/null +++ b/2-write/1-function-design/exercises/easy/countUp.test.js @@ -0,0 +1,14 @@ +export {countUp} from './count-up.test' + +function countUp(max = 0) { + if (!Number.isInteger(max) || max < 0) { + throw new Error('max must be a non-negative integer.'); + } + + const result = []; + for (let i = 0; i <= max; i++) { + result.push(i); + } + return result; + } + diff --git a/2-write/1-function-design/exercises/easy/reverse-a-string.test.js b/2-write/1-function-design/exercises/easy/reverse-a-string.test.js index f74b041..755b1bf 100644 --- a/2-write/1-function-design/exercises/easy/reverse-a-string.test.js +++ b/2-write/1-function-design/exercises/easy/reverse-a-string.test.js @@ -22,7 +22,12 @@ for (const solution of [secretSolution]) { it('a string with all capital letters', () => { expect(solution('ASDF')).toEqual('FDSA'); }); - // write at least 5 more tests ... + it('a string with number', () => { + expect(solution('12345').toEqual('54321')); + }); + it('a string with whitespace', () => { + expect(solution(' Hello, World! ')).toEqual(' !dlroW, olleH '); + }); }); }