some code samples, various examples of simple modeling ideas and some minor algorithms.

AccountTest.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class AccountTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class AccountTest
  12. {
  13. /**
  14. * Default constructor for test class AccountTest
  15. */
  16. public AccountTest()
  17. {
  18. }
  19. /**
  20. * Sets up the test fixture.
  21. *
  22. * Called before every test case method.
  23. */
  24. @Before
  25. public void setUp()
  26. {
  27. }
  28. /**
  29. * Tears down the test fixture.
  30. *
  31. * Called after every test case method.
  32. */
  33. @After
  34. public void tearDown()
  35. {
  36. }
  37. @Test
  38. public void testdeposit(){
  39. int expected = 50;
  40. Account ac = new Account(40);
  41. ac.deposit(10);
  42. int actual = ac.balance();
  43. assertEquals(expected, actual);
  44. }
  45. @Test
  46. public void testtransfer(){
  47. int expected_myAc = 30;
  48. int expected_friendAc = 40;
  49. Account myAc = new Account(40);
  50. Account friendAcc = new Account(30);
  51. myAc.transfer(friendAcc, 10);
  52. int actual_myAc = myAc.balance();
  53. int actual_friendAc = friendAcc.balance();
  54. assertEquals(expected_myAc, actual_myAc);
  55. assertEquals(expected_friendAc, actual_friendAc);
  56. }
  57. @Test
  58. public void testbalance(){
  59. int expected = 30;
  60. Account ac = new Account(30);
  61. int actual = ac.balance();
  62. assertEquals(expected, actual);
  63. }
  64. }