Code coverage report for src/storages/ArrayStorage.ts

# All files / src/storages ArrayStorage.ts

50% Statements 5/10
0% Branches 0/2
100% Functions 1/1
50% Lines 5/10

    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

    1x

    529x

    32626x

    7555x

    5983x

     import { IStorage } from '../interfaces/storages/IStorage';

    export abstract class ArrayStorage <T> implements IStorage <T> {
        /**
         * @type {T[]}
         */
        protected storage: T[] = [];

        /**
         * @param key
         * @returns {T}
         */
        public get (key: number): T {
            const value: T | undefined = this.storage[key];

            if (!value) {
                throw new Error(`No value found in array storage with key \`${key}\``);
            }

            return value;
        }

        /**
         * @param value
         * @returns {string | number}
         */
        public getKeyOf (value: T): string | number {
            return this.storage.indexOf(value);
        }

        /**
         * @returns {number}
         */
        public getLength (): number {
            return this.storage.length;
        }

        /**
         * @returns {T[]}
         */
        public getStorage (): T[] {
            return this.storage;
        }

        /**
         * @param args
         */
        public initialize (...args: any[]): void {}

        /**
         * @param key
         * @param value
         */
        public set (key: string | null, value: T): void {
            this.storage.push(value);
        }
    }