Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified test-case #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
13 changes: 6 additions & 7 deletions 2-write/1-function-design/exercises/easy/count-down.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
});
}

Expand Down
57 changes: 48 additions & 9 deletions 2-write/1-function-design/exercises/easy/count-up.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
// #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`
*/

// -------- 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]);
Expand All @@ -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; }
17 changes: 17 additions & 0 deletions 2-write/1-function-design/exercises/easy/countDown.test.js
Original file line number Diff line number Diff line change
@@ -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
}
}
14 changes: 14 additions & 0 deletions 2-write/1-function-design/exercises/easy/countUp.test.js
Original file line number Diff line number Diff line change
@@ -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;
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 ');
});
});
}

Expand Down