# Code coverage report for learning-istanbul/mischief.js

## Statements: 100% (27 / 27) Branches: 100% (4 / 4) Functions: 100% (5 / 5) Lines: 100% (27 / 27)

All files » learning-istanbul/ » mischief.js

    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
    511
    4

    4

    1
    3

    3

    1
    4

    4
    3
    8

    1

    4

    1
    2
    2
    2
    1
    1

    1
    1
    1

    1
    1
    1
    1

    1

     function creditAccount(account, amount, description) {
    	transaction = {
    		value : Math.abs(amount), // ensures the amount being added is positive
    		desc  : description
    	}
    	return account.push(transaction);
    }

    function debitAccount(account, amount, description) {
    	transaction = {
    		value : -Math.abs(amount), // ensures amount is negative
    		desc  : description
    	}
    	return account.push(transaction);
    }

    function getAccountBalance(account) {
    	var balance = 0;
    	// only add transactions if they exist
    	if (account.length > 0) {
    		account.forEach( function(entry) {
    	    	balance = balance + entry.value;
    		});
    	} else {
    		balance = 0;
    	}
    	return balance;
    }

    function transferMoney(fromAccount, toAccount, amount, description) {
    	debitAccount(fromAccount, amount, description);
    	creditAccount(toAccount, amount, description);
    	if(getAccountBalance(fromAccount)>10000) {
    		debitAccount(fromAccount, 0.1, 'Transaction Fee')
    		creditAccount(account3, 0.1, 'Transaction Fee')
    	} else { /* Nothing to See here. */ }
    }

    account1 = []
    account2 = []
    account3 = [] // rogue developer account

    console.log("Expect Account1 Opening Balance "+getAccountBalance(account1) +" === 0 \u2713 ")
    creditAccount(account1, 12000, 'Add Funds')
    transferMoney(account1,account2, 100, 'Give money to friend')
    transferMoney(account2,account1, 10, 'Transfer back 10')

    console.log("Expect Account1 Balance "+getAccountBalance(account1) +" === 11909.9 \u2713 \n")

    // console.log("Everything seems fine because my tests are passing... right? \n")
    // console.log("WRONG! our Rogue Developer Balance is : " +getAccountBalance(account3) +" === 0.1");