小芳便利店 源代码 java写的
ackage account;
import junit.framework.TestCase;
public class AccountTest extends TestCase {
private Account AccountA;
private Account AccountB;
public AccountTest(String name) {
super(name);
}
public void setUp(){
AccountA=new Account("notyy",100);
AccountB=new Account("bricks",200);
}
public static void main(String args[]) {
junit.textui.TestRunner.run(AccountTest.class);
}
public void testAccount(){
AccountA=new Account("notyy",100);
AccountB=new Account("bricks",200);
//assertEquals("notyy",AccountA.Owner);
//assertEquals(100,AccountA.Balance,2);
//assertEquals("bricks",AccountB.Owner);
//assertEquals(200,AccountB.Balance,2);
assertEquals("notyy",AccountA.getOwner());
}
public void testCredit(){
AccountA=new Account("notyy",100);
AccountB=new Account("bricks",200);
AccountA.credit(100);
//100+100=200
assertEquals(200,AccountA.getBalance(),2);
AccountB.credit(150);
//200+150=350
assertEquals(350,AccountB.getBalance(),2);
}
public void testDiscount(){
AccountA=new Account("notyy",100);
AccountB=new Account("bricks",200);
AccountA.discount(50);
//100-50=50
assertEquals(50.00,AccountA.getBalance(),2);
AccountB.discount(120);
//200-120=80
assertEquals(80,AccountB.getBalance(),2);
}
public void testTransfer(){
AccountA.transfer(AccountB,80.00);
//100-80=20
//200+80=280
assertEquals(20.00,AccountA.getBalance(),2);
assertEquals(280.00,AccountB.getBalance(),2);
}
}
1