2.0.0 • Published 5 years ago

@working-sloth/data-matrix v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Data Matrix

npm version Build Status Codacy Badge codecov MIT License

DataMatrix

日本語

Diligent developer, is it your work to crete many lengthy code for unit tests? Let's be lazy.

What?

Data list creator for JavaScript and TypeScript.

Why?

  • Less code: you don't have to write lengthy code any more for unit test
  • Readable: less code helps you to understand test cases and find mistake
  • Learning cost: basic takes only 1 step, full function takes 5 only steps to learn

Quick start

import { buildDataMatrix } from '@working-sloth/data-matrix';

// define test param
type Test = { time: string, isMale: boolean; age: number, expect: number, label: string };
// buildDataMatrix<T> convert the matrix to test list
const tests = buildDataMatrix<Test>(
    [
        ['time',        'isMale',   'age',  'expect',   'label'] // Header
    ], [//-------------------------------------------------------
        // Lacking values will be filled from LEFT to RIGHT with previous value
        ['morning',     true,       10,     -0.5,   '[morning] boy (max): discount 50%'],
        [/*morning*/    /*true*/    11,     0.0,    '[morning] boy (above): no discount'],
        [                           64,     0.0,    '[morning] senior man (under): no discount'],
        [                           65,     -0.5,   '[morning] senior man (min): discount 50%'],
        [               false,      10,     -0.5,   '[morning] girl (max): discount 50%'],
        [               /*false*/   11,     0.0,    '[morning] girl (above): no discount'],
        ...
    ]
);

// Test loop
for (const test of tests) {
    it(test.label, () => {
        // Given
        const service = new FooService();
        // When
        const discount = service.calcDiscount(test.time, test.isMale, test.age);
        // Then
        expect(discount).toEqual(test.expect);
    });
}

Other samples

I have a truly marvelous sample of this case which this margin is too narrow to contain. See samples

Schedule

  • Crate docs: someday
  • Extension for VS Code (matrix formatter & header generator): someday
  • Rest: every day
  • Sleep: every day
  • Be clever and lazy: soon
  • Be stupid and diligent: never

If you aren't satisfied

  • Open an issue such as "question" or "enhancement"
  • e-mail: koba.work.work1127@gmail.com
2.0.0

5 years ago

1.0.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago