2.1.0 • Published 7 years ago

transparent-tank v2.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Transparent Tank Build Status

Read the API Documentation.

Npm

npm install transparent-tank

Usage

The following is an example of building a model and assigning values to its variables.

    import {Model, Relation, Variable, Value, Domain} from 'transparent-tank';

    let model = new Model( 'CountryCodes' );

    // Variable1: Country
    let country = new Variable( 'Country' );
    let countries = new Domain();
    countries.createValue( 'Denmark' );
    countries.createValue( 'United States' );
    countries.createValue( 'United Kingdom' );
    countries.createValue( 'Canada' );
    country.setDomain( countries );
    model.addVariable( country );

    // Variable2: Country Code
    let countryCode = new Variable( 'CountryCode' );
    let codes = new Domain();
    codes.createValue( '+45' );
    codes.createValue( '+1' );
    codes.createValue( '+44' );
    countryCode.setDomain( codes );
    model.addVariable( countryCode );

    // Rule: Danish Phone Numbers begin with +45
    let relation = new Relation( 'DanishPhone',     'Country',     [ new Value( 'Denmark' ) ],
                                                    'CountryCode', [ new Value( '+45' ) ] );
    model.addRelation( relation );

    // Now, Start Configuring:
    let configuration = new Configuration( model );
    configuration.assign( 'Country', 'Denmark' );
    configuration.solve();

    let countryCode = configuration.getVariable( 'CountryCode' );

    // assigned by the system because of the relation:
    assert.isTrue( countryCode.getValue( '+45' ).isSystemAssigned() );

Instead of relations, you can use table rules:

    let table = new Table( 'CountryAndPhone' );

    // Give the table some cols that it will recognize from variable names
    table.setCols( 'Country', 'PhoneCountryCode' );

    // Add rows where each row is a value from the variable Country or CountryCode
    table.addRow( 'Denmark', '+45' );
    table.addRow( 'United Kingdom', '+44' );
    table.addRow( 'United States', '+1' );
    table.addRow( 'Canada', '+1' );

    model.addTable( table );

Build

To build this project:

npm install
npm run build

To run unit tests:

npm run test

Unit testing is performed with Mocha+Chai. To run a single test, postfix it with .only. To exclude a test, postfix it with .skip.

For example:

describe.only(function () {
  // these tests will run
});
2.1.0

7 years ago

2.0.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.1.2

7 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago