How to use better-assert - 10 common examples

To help you get started, we’ve selected a few better-assert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / lib / datamodel / base_node.js View on Github external
function dumpReferenceDescription(addressSpace, referenceDescription) {
  assert(addressSpace.constructor.name === "AddressSpace");
    // assert(addressSpace instanceof AddressSpace);
  assert(referenceDescription.referenceTypeId); // must be known;

  console.log("referenceDescription".red);
  console.log("    referenceTypeId : ", referenceTypeToString(addressSpace, referenceDescription.referenceTypeId));
  console.log("    isForward       : ", referenceDescription.isForward ? "true" : "false");
  console.log("    nodeId          : ", nodeIdInfo(addressSpace, referenceDescription.nodeId));
  console.log("    browseName      : ", referenceDescription.browseName.toString());
  console.log("    nodeClass       : ", referenceDescription.nodeClass.toString());
  console.log("    typeDefinition  : ", nodeIdInfo(addressSpace, referenceDescription.typeDefinition));
}
function dumpReferenceDescriptions(addressSpace, referenceDescriptions) {
github node-opcua / node-opcua / lib / address_space / ua-variable-type / initialize_properties_and_components.js View on Github external
function hasChildWithBrowseName(parent,childBrowseName) {
    assert(parent instanceof BaseNode);
    // extract children
    const children = parent.findReferencesAsObject("HasChild", true);

    return children.filter(child => child.browseName.name.toString()  === childBrowseName).length > 0;
}
github node-opcua / node-opcua / lib / address_space / ua-two-state-variable / install.js View on Github external
function _install_TwoStateVariable_machinery(node,options) {
    assert(node.dataTypeObj.browseName.toString() === "LocalizedText");
    assert(node.minimumSamplingInterval === 0);
    assert(node.typeDefinitionObj.browseName.toString() === "TwoStateVariableType");
    assert(node.dataTypeObj.browseName.toString() === "LocalizedText");
    assert(node.hasOwnProperty("valueRank") && (node.valueRank === -1 || node.valueRank === 0));
    assert(node.hasOwnProperty("id"));
    options = options || {};
    // promote node into a UATwoStateVariable
    Object.setPrototypeOf(node, UATwoStateVariable.prototype);
    node.initialize(options);
}
github node-opcua / node-opcua / lib / address_space / alarms_and_conditions / ConditionSnapshot.js View on Github external
function _install_condition_variable_type(node) {
    // from spec 1.03 : 5.3 condition variables
    // However,  a change in their value is considered important and supposed to trigger
    // an Event Notification. These information elements are called ConditionVariables.
    node.sourceTimestamp.accessLevel = makeAccessLevel("CurrentRead");
    node.accessLevel = makeAccessLevel("CurrentRead");

    // from spec 1.03 : 5.3 condition variables
    // a condition VariableType has a sourceTimeStamp exposed property
    // SourceTimestamp indicates the time of the last change of the Value of this ConditionVariable.
    // It shall be the same time that would be returned from the Read Service inside the DataValue
    // structure for the ConditionVariable Value Attribute.

    assert(node.typeDefinitionObj.browseName.toString() === "ConditionVariableType");
    assert(node.sourceTimestamp.browseName.toString() == "SourceTimestamp");
    node.on("value_changed", _update_sourceTimestamp);
}
github zhujinxuan / redux-declare / test / index.js View on Github external
it("Counter test, not nested Obj", () => {
    let action = { type: "sub", status: "success", count: 1 };
    let newCounter = reducers(counter, action);
    assert(newCounter.count === 0, "Problem in status test of success");
    action = { type: "sub", status: "error", count: 1 };
    newCounter = reducers(counter, action);
    assert(newCounter.count === 0.5, "Problem in status test of error");
  });
});
github welch / tdigest / specs / tdigest.spec.js View on Github external
it('reports undefined when given no points', function(){
        var tdigest = new TDigest();
        var p = [0, 0.5, 1.0];
        assert.deepEqual(tdigest.percentile(0.5), undefined);
        assert.deepEqual(tdigest.percentile(p), [undefined,undefined,undefined]);
    });
    it('from a single point', function(){
github welch / tdigest / specs / digest.spec.js View on Github external
it('preserves a discrete distribution', function(){
        var digest = new Digest(); 
        var i, ntimes = 1000, nvals=100;
        for (i = 0 ; i < ntimes ; i++) {
            for (j = 0 ; j < nvals ; j++) {
                digest.push(j);
            }
        }
        var result = digest.toArray();
        for (i = 0 ; i < nvals ; i++) {
            assert.deepEqual(result[i], {mean:i, n:ntimes});
        }
    }); 
    it('compresses a continuous distribution', function(){
github welch / tdigest / specs / discrete.spec.js View on Github external
it('consumes nonnumeric points', function(){
        var tdigest = new TDigest(false); 
        tdigest.push("foo");
        tdigest.push("bar");
        tdigest.push("baz");
        tdigest.push("foo");
        tdigest.push("freen");
        tdigest.push("bork");
        tdigest.push("bork");
        tdigest.push("bork");
        tdigest.push("books");
        var points = tdigest.toArray();
        assert.deepEqual(points, [
            {mean:"bar", n:1},
            {mean:"baz", n:1},
            {mean:"books", n:1},
            {mean:"bork", n:3}, 
            {mean:"foo", n:2},
            {mean:"freen", n:1},
        ]);
    });
    it('consumes same-valued points into a single point', function(){
github node-opcua / node-opcua / lib / datamodel / base_node.js View on Github external
getFolderElementByName(browseName) {
    assert(typeof browseName === "string");
    const elements = this.getFolderElements();
    const select = elements.filter(c => c.browseName.toString() === browseName);
    return select.length === 1 ? select[0] : null;
  }
github node-opcua / node-opcua / lib / datamodel / base_node.js View on Github external
function dumpReferenceDescriptions(addressSpace, referenceDescriptions) {
  assert(addressSpace);
  assert(addressSpace.constructor.name === "AddressSpace");
  assert(_.isArray(referenceDescriptions));
  referenceDescriptions.forEach((r) => {
    dumpReferenceDescription(addressSpace, r);
  });
}
export { dumpReferenceDescription };

better-assert

Better assertions for node, reporting the expr, filename, lineno etc

MIT
Latest version published 10 years ago

Package Health Score

71 / 100
Full package analysis

Popular better-assert functions