第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

遞歸 JUnit 測(cè)試

遞歸 JUnit 測(cè)試

炎炎設(shè)計(jì) 2021-05-31 17:16:22
因此,我正在嘗試編寫 3 個(gè)測(cè)試用例來查找我編寫的遞歸方法是否正確。我對(duì) JUnit 不太好,但這就是我到目前為止所得到的。如何證明我的遞歸方法在 JUnit 中是正確的(如果是)?這是我的班級(jí):public class Rhino {    private String co; //The country in which this Rhino was born. Not null    private Rhino parent; //null if this Rhino has no known parent    /** Constructor : an instance born in country c with parent p.     * Precondition : c is not null . */    public Rhino(String c, Rhino p) {        co = c;        parent = p;    }    /** Return the number of Rhinos in this Rhino 's family that    were     * born in country c. This Rhino 's family consists of this    Rhino , its     * parent , its parent 's parent , its parent 's parent 's parent ,    etc . */    public int numCountry(String c) {        if (parent == null){return co.equals(c) ? 1:0;}        return(co.equals(c) ? 1:0) + parent.numCountry(c);    }}到目前為止,這是我的 JUnit 測(cè)試:import static org.junit.Assert.assertEquals;import static org.junit.jupiter.api.Assertions.*;import org.junit.jupiter.api.Test;class RhinoTest {    @Test    public void testCountry() {        Rhino testCP = new Rhino("USA", null);        assertEquals("USA", testCP.numCountry(""));        assertNotEquals(testCP, null);    }}
查看完整描述

1 回答

?
冉冉說

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊

試試這個(gè)基本測(cè)試,讓你開始:


public void testCountry() {


    Rhino rA = new Rhino("USA", null);

    Rhino rB = new Rhino("USA", rA);

    Rhino rC = new Rhino("CANADA", rB);

    Rhino rD = new Rhino("USA", rC);


    int expectedResult = 3;

    assertEquals(expectedResult, rD.numCountry("USA"));

}



查看完整回答
反對(duì) 回復(fù) 2021-06-02
  • 1 回答
  • 0 關(guān)注
  • 161 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)