⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testbankaccount.java

📁 ssd3的教程 是我们老师给我们的 纯英文 有兴趣的可以
💻 JAVA
字号:
import  java.io.*;

/**
 * Test driver for class <code>BankAccount</code>.
 *
 * @author author name
 * @version  1.0.0
 */
public class TestBankAccount {

    /* Standard output stream */
    private static PrintWriter  stdOut =
        new  PrintWriter(System.out, true);

    /* Standard error stream */
    private static PrintWriter  stdErr =
        new  PrintWriter(System.err, true);

    /**
     * Test driver for class <code>BankAccount</code>.
     *
     * @param args  not used.
     */
    public static void  main(String[] args)  {

        boolean result;

        // Testing constructor and accessor
        BankAccount accountOne = new BankAccount();

        assertTrue("1: testing method getBalance()",
                   accountOne.getBalance() == 0);

        //Testing method deposit
        BankAccount accountTwo = new BankAccount();

        result = accountTwo.deposit(100);
        assertTrue("2: testing method deposit", result);
        assertTrue("3: testing method deposit",
                   accountTwo.getBalance() == 100);

        result = accountTwo.deposit(50);
        assertTrue("4: testing method deposit", result);
        assertTrue("5: testing method deposit",
                   accountTwo.getBalance() == 150);

        result = accountTwo.deposit(0);
        assertTrue("6: testing method deposit", ! result);
        assertTrue("7: testing method deposit",
                   accountTwo.getBalance() == 150);

        result = accountTwo.deposit(-25);
        assertTrue("8: testing method deposit", ! result);
        assertTrue("9: testing method deposit",
                   accountTwo.getBalance() == 150);

        //Testing method withdraw
        BankAccount accountThree = new BankAccount();

        accountThree.deposit(100);
        result = accountThree.withdraw(60);
        assertTrue("10: testing method withdraw", result);
        assertTrue("11: testing method withdraw",
                   accountThree.getBalance() == 40);

        result = accountThree.withdraw(50);
        assertTrue("12: testing method withdraw", ! result);
        assertTrue("13: testing method withdraw",
                   accountThree.getBalance() == 40);

        result = accountThree.withdraw(0);
        assertTrue("14: testing method withdraw", ! result);
        assertTrue("15: testing method withdraw",
                   accountThree.getBalance() == 40);

        result = accountThree.withdraw(-10);
        assertTrue("16: testing method withdraw", ! result);
        assertTrue("17: testing method withdraw",
                   accountThree.getBalance() == 40);

        stdOut.println("done");
    }

    /**
     * Displays a message in the standard error stream if the value
     * specified by argument <code>condition<code> is
     * <code>false</code>.
     *
     * @param message  the error message.
     * @param condition  the test condition.
     */
    public static void assertTrue(String message,
                                  boolean condition) {

        if (! condition) {
            stdErr.print("** Test failure ");
            stdErr.println(message);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -