@w1024020103
2017-02-25T14:53:13.000000Z
字数 2090
阅读 1043
CS61B
UCBerkeley
Error: 程序包org.junit不存在
Solution:确定已经加了External Library : javalib, 里面包括junit-4.12.jar,重启IntelliJ,不报错.
Write a reverse method, and rerun the tests until it passes. If you're stuck (this is a tricky problem with a very clever solution), see the week 3 discussion solutions.
discussion 3 reverse method for SLList
(iteratively)
reverse method for IntList
(iteratively)
/**
* Returns the reverse of the given IntList.
* This method is destructive. If given null
* as an input, returns null.
*/
public static IntList reverse(IntList A){
if( A == null){
return null;
}
IntList frontOfReversed = null;
IntList nextNodeToAdd = A;
while(nextNodeToAdd != null) {
IntList remainderOfOriginal = nextNodeToAdd.rest;
nextNodeToAdd.rest = frontOfReversed;
frontOfReversed = nextNodeToAdd;
nextNodeToAdd = remainderOfOriginal;
}
return frontOfReversed;
}
Using any combination of the following techniques, figure out whether the bug is in Horrible Steve's code or in Flik enterprise's library:
Refactoring Horrible Steve's code. Refactoring means changing the syntax without changing the functionality. This may be hard to do since HS's code uses lots of weird stuff.
HorribleSteve.java and Flik.java both use syntax we haven't covered in class. We do not expect you to fix the bug or even understand why it's happening once you have found it. Instead, your job is simply to find the bug.
Tip: JUnit provides methods assertTrue(boolean) and assertTrue(String, boolean) that you might find helpful.
Try to come up with a short explanation of the bug! Check in with your TA to see if your answer is right (not for a grade).
/** An Integer tester created by Flik Enterprises. */
public class Flik {
public static boolean isSameNumber(Integer a, Integer b) {
return a == b;
}
}
I somehow found out the bug to beInteger a, Integer b
, so I modified the code then the output were right.
/** An Integer tester created by Flik Enterprises. */
public class Flik {
public static boolean isSameNumber(int a, int b) {
return a == b;
}
}
Explanation: Integer type is diffrent form int.....
In this lab, we went over: