Index
Overview


After we publish to npm, we want to make sure it works. This page provides a step-by-step on how to do it.

Steps


Initialize New Project
Add new empty project folder "try-js-common".

Then, open the console and run the init command shown.
> npm init
Configure Dependency to New Module
Add dependency as shown to "package.json".
	"dependencies": {
		"@garypeterson/js-common": "^1.0.0"
	}
Add Test Code
Add code that uses js-common, e.g. as shown at bottom of this page. Call the file 'play-js-common.js'.
Run It
In console, run commands shown
> npm install
> node play-js-common
# should see results in console


play-js-common.js


/*
matrix-tool-lab.js
*/

const
	{MinimalMatrix} = require('@garypeterson/js-common'),
	{Lab} = require('@garypeterson/js-common'),
	{MatrixTool} = require('@garypeterson/js-common'),
	{prn} = require('@garypeterson/js-common');

class MatrixToolLab extends Lab {

	static go() {
		const lab = new MatrixToolLab();
		lab.runSelector(lab.sample_core_1, 'sample_core_1');
		lab.runSelector(lab.sample_core_2, 'sample_core_2');
	}

	//-----------------------------------
	//Tests

	sample_core_1() {
		const
			mx = MinimalMatrix.fromMN(2, 4, null),
			tool = MatrixTool.fromMatrix(mx);
		tool.atPut(2, 2, 11);
		this.compare(11, tool.at(2, 2), '(2, 2)');
		this.compare(null, tool.at(2, 3), '(2, 3)');
	}

	sample_core_2() {
		const
			mx = MinimalMatrix.fromMN(2, 4, null),
			tool = MatrixTool.fromMatrix(mx);
		for (let i = 1; i <= tool.getM(); i++) {
			for (let j = 1; j <= tool.getN(); j++)
				tool.atPut(i, j, i + j);
		}
		for (let i = 1; i <= tool.getM(); i++) {
			for (let j = 1; j <= tool.getN(); j++)
				this.compare(i + j, tool.at(i, j), `(${i}, ${j})`);
		}
	}

	//-----------------------------------
	//Private Helpers

	runSelector(method, methodLabel) {
		prn(`Running test ${methodLabel}`);
		method.bind(this)();
	}

}

//-----------------------------------------------------
//Run Experiments

MatrixToolLab.go();