all files / src/ observation.js

93.62% Statements 44/47
100% Branches 30/30
100% Functions 14/14
85.71% Lines 18/21
3 statements, 4 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60  35× 35× 35×   35× 35× 35× 29×         35×                                                         17×               14×    
export default class Observation {
    constructor(experimentIn, behaviourName, block, dateTimeProvider) {
        this._experiment = experimentIn;
        this._name = behaviourName;
        this._dateTimeProvider = dateTimeProvider;
 
        var now = this._dateTimeProvider.now();
        try {
            this._result = block();
            this._error = null;
        }
        catch (err) {
            this._error = err;
        }
 
        this._duration = (this._dateTimeProvider.now() - now) / 1000; //total seconds
        //console.log(`[Observation] duration ${this._duration}`);
    }
 
 
    /**
     *
     * @param other
     * @type {Observation}
     */
    isEquivalentTo(other) {
        var bothRaisedExceptions = (other.error !== null && this._error !== null);
        var neitherRaisedExceptions = (other.error === null && this._error === null);
 
        var valuesAreEqual = other.result === this._result;
 
        var exceptionsAreEquivalent = (bothRaisedExceptions &&
        typeof other.error === typeof this._error &&
        other.error.message === this._error.message);
 
        //console.log(`(${neitherRaisedExceptions} && ${valuesAreEqual}) || (${bothRaisedExceptions} && ${exceptionsAreEquivalent})`);
        return (neitherRaisedExceptions && valuesAreEqual) || (bothRaisedExceptions && exceptionsAreEquivalent);
    }
 
 
    get experiment() {
        return this._experiment;
    }
 
    get name() {
        return this._name;
    }
 
    get result() {
        return this._result;
    }
 
    get duration() {
        return this._duration;
    }
 
    get error() {
        return this._error;
    }
}