无法将结果返回到字符串列表中

时间:2016-02-03 22:06:25

标签: java binary-tree binary-search-tree junit4

在下面的代码中,我必须以字符串列表的形式返回结果,以便在Junit测试中进行比较。但它只返回中间元素。

public List<String> reverseOrderTr()
    {
    List<String> treeElements1 = this.reverseOrderT(root);            
        return treeElements1;
    }

private  List<String>  reverseOrderT(BinaryTreeNode t)
    {
    List <String> treeElements=new ArrayList<String>();
        if (t != null)
            {

                String v = t.nodeData;
                char tav = (Character.toUpperCase(v.charAt(0)));

                        reverseOrderT(t.rightNode);

                    //reverseOrderT(t.leftNode);
                if(tav=='A' ||
                   tav=='E' ||
                   tav=='I' ||
                   tav=='O' ||
                   tav=='U')
                {
                    System.out.print(t.nodeData + " ");
                    treeElements.add(t.nodeData);
                    }
                    reverseOrderT(t.leftNode);

            }
        return treeElements;

     }

测试代码如下: -

public class BinaryTreeTest {

private List <String> result = new ArrayList<String>();;

@Test
public void testTreeResult() {



              String[] months = {"Ian","ueb","Mar","Aay","Uun",
                        "Jul","Aug","oep","Act","Eov","Dec"};
                    Tree tree = new Tree();

                    for (int i = 0; i < months.length; i++)
                        tree.insert(months[i]);
                //expectedResult="ueb oep Uun Ian Eov Aug Act Aay  ";
                List <String> expectedOutput=new ArrayList<String>();

                expectedOutput.add("ueb");
                expectedOutput.add("oep");
                expectedOutput.add("Eov");
                expectedOutput.add("Uun");
                expectedOutput.add("Ian");
                expectedOutput.add("Aay");
                expectedOutput.add("Aug");                  
                expectedOutput.add("Act");

               result = tree.reverseOrderTr();
               System.out.println("Alphabetically ordered Tree Elements:  " + result);
               assertEquals(expectedOutput, result);

}

}

请帮忙。测试一次又一次失败。结果只有Ian正在插入。

0 个答案:

没有答案