All files / src/sources generator.ts

91.3% Statements 21/23
44.44% Branches 4/9
83.33% Functions 5/6
90.9% Lines 20/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 61 62 63 64 65 66 678x 8x       1x 1x         4x     1x 1x 1x         1x   1x         1x 1x           1x 9x 9x       9x   1x                           1x         1x     8x  
import {stde} from '../stde';
import * as lle from '@ldamle/lle';
 
class Generator extends stde {
    constructor(freq: number, beginWith: lle.Types.signal.it = 0) {
        let beginWiths = lle.Types.signal.__getArrayIt(beginWith);
        super(
            '%<svg width="100" height="40" viewBox="0 0 200 50" xmlns="http://www.w3.org/2000/svg" stroke="currentColor"><path d="M0 50L60 50L60 20" stroke="currentColor" stroke-width="3" fill="none"/><path d="M60 20L140 20" stroke="currentColor" stroke-width="3" fill="none"/><path d="M140 20L140 50L200 50" stroke="currentColor" stroke-width="3" fill="none"/></svg>',
            ['in'],
            ['out'],
            (a) => {
                return 'z';
            }
        );
        this.props['freq'] = freq;
        let tf = 1 / freq;
        this.props['unstableState'] = (
            beginTime: number,
            endTime: number,
            state: lle.Types.signal.array
        ): lle.Types.signal.timeTable => {
            if (state == '1') {
                let curst =
                    Math.floor(beginTime / tf) % 2 == 0
                        ? beginWiths
                        : beginWiths === '0'
                        ? '1'
                        : '0';
                let curtf = Math.floor(beginTime / tf) * tf + tf;
                let res: lle.Types.signal.timeTable = [
                    {
                        time: beginTime,
                        state: curst
                    }
                ];
                while (curtf < endTime) {
                    curst = curst === '0' ? '1' : '0';
                    res.push({
                        time: curtf,
                        state: curst
                    });
                    curtf += tf;
                }
                return res;
            }
            return [
                {
                    time: beginTime,
                    state: '0'
                }
            ];
        };
    }
    sout(){
        return this.out('out');
    }
    sin(connection: lle.Connection){
        return this.in('in', connection);
    }
}
 
function generator(freq: number, beginWith: lle.Types.signal.it = 0) {
    return new Generator(freq, beginWith);
}
 
export {Generator, generator};