Skip to content
Snippets Groups Projects
Commit 69c181aa authored by Kevin Zatloukal's avatar Kevin Zatloukal
Browse files

Starter code

parents
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
{
"name": "cse331-sec-levels",
"version": "0.0.1",
"description": "CSE 331 Levels Section",
"main": "",
"scripts": {
"test": "ts-mocha -p tsconfig.json src/**/*_test.ts"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/assert": "^1.5.6",
"@types/mocha": "^5.2.7",
"assert": "^2.0.0",
"mocha": "^10.1.0",
"ts-loader": "^9.4.1",
"ts-mocha": "^10.0.0",
"typescript": "^4.8.4"
}
}
/** Calculates (incorrectly) the value (n-1)^2. */
export function quadratic3(n: number): number {
return 0; // TODO: replace this
}
/** Calculates (incorrectly) the value |x|. */
export function abs_value3(x: number): number {
return 0; // TODO: replace this
}
/** Calculates (incorrectly) the value |x|. */
export function abs_value4(x: number): number|undefined {
return 0; // TODO: replace this
}
/**
* Returns the number of pairs we can get from n items, where n is a
* non-negative integer.
*/
export function count_pairs(n: number): number {
return 0; // TODO: replace this
}
/**
* Returns the number of pairs we can get from n items, where n is a
* non-negative integer.
*/
export function count_pairs2(n: number): number {
return 0; // TODO: replace this
}
\ No newline at end of file
import * as assert from 'assert';
import { quadratic3, abs_value3, abs_value4, count_pairs, count_pairs2 } from './funcs';
describe('funcs', function() {
it('quadratic3', function() {
assert.strictEqual(quadratic3(1), 0); // check that (1 - 1)^2 = 0
assert.strictEqual(quadratic3(2), 1); // check that (2 - 1)^2 = 1
assert.notStrictEqual(quadratic3(3), 4); // check that (3 - 1)^2 = 4 fails
});
it('abs_value3', function() {
assert.strictEqual(abs_value3(2), 2); // check that |2| = 2
assert.strictEqual(abs_value3(-2), 2); // check that |-2| = 2
assert.notStrictEqual(abs_value3(-1), 1); // check that |-1| = 1 fails
});
it('abs_value4', function() {
assert.strictEqual(abs_value4(5), 5);
assert.strictEqual(abs_value4(4), 4);
assert.strictEqual(abs_value4(3), 3);
assert.strictEqual(abs_value4(2), 2);
assert.strictEqual(abs_value4(1), 1);
assert.strictEqual(abs_value4(-1), 1);
assert.strictEqual(abs_value4(-2), 2);
assert.strictEqual(abs_value4(-3), 3);
assert.strictEqual(abs_value4(-4), 4);
assert.strictEqual(abs_value4(-5), 5);
assert.strictEqual(abs_value4(0), undefined); // check that |0| fails
});
it('count_pairs', function() {
assert.strictEqual(count_pairs(0), 0);
assert.strictEqual(count_pairs(2), 1);
assert.strictEqual(count_pairs(4), 2);
assert.strictEqual(count_pairs(6), 3);
assert.strictEqual(count_pairs(8), 4);
assert.strictEqual(count_pairs(10), 5);
assert.strictEqual(count_pairs(1), 0);
assert.notStrictEqual(count_pairs(3), 1);
});
it('count_pairs2', function() {
assert.strictEqual(count_pairs2(0), 0);
assert.strictEqual(count_pairs2(2), 1);
assert.strictEqual(count_pairs2(4), 2);
assert.strictEqual(count_pairs2(6), 3);
assert.strictEqual(count_pairs2(8), 4);
assert.strictEqual(count_pairs2(10), 5);
assert.strictEqual(count_pairs2(1), 0);
assert.strictEqual(count_pairs2(3), 1);
assert.notStrictEqual(count_pairs2(5), 2);
});
});
\ No newline at end of file
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es5",
"moduleResolution": "node",
"outDir": "dist",
"rootDir": "src",
"lib": [ "es2016", "dom" ],
"allowJs": true,
"jsx": "react",
"strict": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"inlineSourceMap": true,
"downlevelIteration": true
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment