<small id="m3sh2"><menu id="m3sh2"><wbr id="m3sh2"></wbr></menu></small><thead id="m3sh2"><ul id="m3sh2"></ul></thead>
<ins id="m3sh2"><noframes id="m3sh2"></noframes></ins><pre id="m3sh2"><menu id="m3sh2"></menu></pre>
<thead id="m3sh2"><ul id="m3sh2"></ul></thead>
  • <kbd id="m3sh2"><strike id="m3sh2"></strike></kbd>
    <label id="m3sh2"><td id="m3sh2"></td></label>
    您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > junit
    使用clover為junit單元測(cè)試做覆蓋率分析
    作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/10/15 10:40:03 ] 推薦標(biāo)簽:

        這個(gè)接口實(shí)現(xiàn)了IMoney接口的方法,具體語(yǔ)法不講了,很簡(jiǎn)單!之后,我們又用另一個(gè)類(lèi)實(shí)現(xiàn)IMoney接口,為什么呢?你可以認(rèn)為我貪心,但你不可以這么說(shuō),因?yàn)橄矚g編程的人不是為了貪婪代碼!我們?cè)趕rc下建立另一個(gè)類(lèi)MoneyBag.java:

        import java.util.*; 
         
        class MoneyBag implements IMoney { 
         
        private Vector fMonies= new Vector(5); 
         
         
        static IMoney create(IMoney m1, IMoney m2) { 
         
        MoneyBag result= new MoneyBag(); 
         
        m1.appendTo(result); 
         
        m2.appendTo(result); 
         
        return result.simplify(); 
         
        } 
         
        public IMoney add(IMoney m) { 
         
        return m.addMoneyBag(this); 
         
        } 
         
        public IMoney addMoney(Money m) { 
         
        return MoneyBag.create(m, this); 
         
        } 
         
        public IMoney addMoneyBag(MoneyBag s) { 
         
        return MoneyBag.create(s, this); 
         
        } 
         
        void appendBag(MoneyBag aBag) { 
         
        for (Enumeration e= aBag.fMonies.elements(); e.hasMoreElements(); ) 
         
        appendMoney((Money)e.nextElement()); 
         
        } 
         
        void appendMoney(Money aMoney) { 
         
        if (aMoney.isZero()) return; 
         
        IMoney old= findMoney(aMoney.currency()); 
         
        if (old == null) { 
         
        fMonies.addElement(aMoney); 
         
        return; 
         
        } 
         
        fMonies.removeElement(old); 
         
        IMoney sum= old.add(aMoney); 
         
        if (sum.isZero()) 
         
        return; 
         
        fMonies.addElement(sum); 
         
        } 
         
        public boolean equals(Object anObject) { 
         
        if (isZero()) 
         
        if (anObject instanceof IMoney) 
         
        return ((IMoney)anObject).isZero(); 
         
         
        if (anObject instanceof MoneyBag) { 
         
        MoneyBag aMoneyBag= (MoneyBag)anObject; 
         
        if (aMoneyBag.fMonies.size() != fMonies.size()) 
         
        return false; 
         
         
        for (Enumeration e= fMonies.elements(); e.hasMoreElements(); ) { 
         
        Money m= (Money) e.nextElement(); 
         
        if (!aMoneyBag.contains(m)) 
         
        return false; 
         
        } 
         
        return true; 
         
        } 
         
        return false; 
         
        } 
         
        private Money findMoney(String currency) { 
         
        for (Enumeration e= fMonies.elements(); e.hasMoreElements(); ) { 
         
        Money m= (Money) e.nextElement(); 
         
        if (m.currency().equals(currency)) 
         
        return m; 
         
        } 
         
        return null; 
         
        } 
         
        private boolean contains(Money m) { 
         
        Money found= findMoney(m.currency()); 
         
        if (found == null) return false; 
         
        return found.amount() == m.amount(); 
         
        } 
         
        public int hashCode() { 
         
        int hash= 0; 
         
        for (Enumeration e= fMonies.elements(); e.hasMoreElements(); ) { 
         
        Object m= e.nextElement(); 
         
        hash^= m.hashCode(); 
         
        } 
         
        return hash; 
         
        } 
         
        public boolean isZero() { 
         
        return fMonies.size() == 0; 
         
        } 
         
        public IMoney multiply(int factor) { 
         
        MoneyBag result= new MoneyBag(); 
         
        if (factor != 0) { 
         
        for (Enumeration e= fMonies.elements(); e.hasMoreElements(); ) { 
         
        Money m= (Money) e.nextElement(); 
         
        result.appendMoney((Money)m.multiply(factor)); 
         
        } 
         
        } 
         
        return result; 
         
        } 
         
        public IMoney negate() { 
         
        MoneyBag result= new MoneyBag(); 
         
        for (Enumeration e= fMonies.elements(); e.hasMoreElements(); ) { 
         
        Money m= (Money) e.nextElement(); 
         
        result.appendMoney((Money)m.negate()); 
         
        } 
         
        return result; 
         
        } 
         
        private IMoney simplify() { 
         
        if (fMonies.size() == 1) 
         
        return (IMoney)fMonies.elements().nextElement(); 
         
        return this; 
         
        } 
         
        public IMoney subtract(IMoney m) { 
         
        return add(m.negate()); 
         
        } 
         
        public String toString() { 
         
        StringBuffer buffer = new StringBuffer(); 
         
        buffer.append("{"); 
         
        for (Enumeration e= fMonies.elements(); e.hasMoreElements(); ) 
         
        buffer.append(e.nextElement()); 
         
        buffer.append("}"); 
         
        return buffer.toString(); 
         
        } 
         
        public void appendTo(MoneyBag m) { 
         
        m.appendBag(this); 
         
        } 
         
        } 

    上一頁(yè)12345678下一頁(yè)
    軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
    滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd