helloShen / leetcode-helper

Save your time from building scaffolding for each leetcode problem.
345 stars 43 forks source link

How to test with leetcode data structure? #9

Open jinniw43805 opened 5 years ago

jinniw43805 commented 5 years ago

Since I've created an solution1 class to implement solution interface which takes TreeNode class param, but when I went to Tester.java part tried to write test case with TreeNode, how do I declare the TreeNode structure

For example, if I want to give a binary tree [3,9,20,null,null,15,7] as input () /** Initialize test cases */ @Parameters public static Collection<Object[]> testcases() { return Arrays.asList(new Object[][]{ {[3,9,20,null,null,15,7], 3} // test case 1 (init parameters below: {para1, para2, expected}) }); }

This shows error: illegal start of expression exception

How do you guys deal with leetcode structure in Tester.java

jinniw43805 commented 5 years ago

Just look TreeNode unit test part in source file https://github.com/helloShen/leetcode-helper/blob/master/src/test/java/com/ciaoshen/leetcode/util/TreeNodeTest.java Seems you establish the tree structure in setUpBeforeClass() function, do we have to use the same idea to deal this one?