Monday, October 19, 2009

Quickie Questions for a Quicky "A".

Here are some questions that could help you study for the upcoming midterm.

1. In the "Getting Answers" guide, 10 strategies were given. List 3 of these strategies.
A. Explain what doesn't work
Provide Everything up-front
Post your code
Do your research beforehand
Do your research during
Do your research afterwards
Don't post the same question repeatedly
Follow up after you get an answer
Treat the list like people
Always consider the answer

2. Give one good and one bad example of a post to ask for answers. (include subject line and body).
A. (Bad)
Subject: Help, Code not working!!!
Body: Ahhhh... I cant get my code to work... Please help me ASAP

(Good)
Subject: Roboode Junit test error: "robocode home not set"
Body: I received this error while trying to run a Junit test on my robocode project.
I need to set the robocode home path but I dont know how to set it in Eclipse.
Could someone please tell me where i can set this path in Eclipse.
Thank you.
attached is my code and my file path.


3. what is the difference between foo.equals(bar) and foo == bar?
A. foo.equals(bar) is true when their values are the same but could be in different memory location
foo==bar is true only if they are in the same memory location

4. Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz"
instead of the number and for the multiples of five print "Buzz".
For numbers which are multiples of both three and five print "FizzBuzz".
A.
public class FizzBuzz{
public static void main(String [] args){
for (int i = 1; i <= 100; i++){
if (i % 15 == 0){
System.out.print("FizzBuzz");
}
else if (i % 3 == 0){
System.out.print("Fizz");
}
else if (i % 5 == 0){
System.out.print("Buzz");
}
else{
System.out.print(i);
}

}
}
}

5. Find a violation of checkstyle and findbug in the code below.

public void xFire(double robotDistance) {
if (robotDistance > 400) {
doNothing();
}
else if (robotDistance > 200)
fire(1);

else if (robotDistance > 100) {
fire(2)
}
else if (robotDistance > 50) {
fire(3);
}
}

A. Checkstyle: missing "{}" on first else if.
Findbug: missing ";" inside second else if.

6. Why did our RoboCode not follow the coding standard of being within the package hierachy "edu.hawaii" ?
A. this standard may be superceded by "adhere to the style of the original", as in the case of RoboCode.

7. In the antipattern article, what is the "Happy path test"?
A. A happy path test is a test within boundaries, pretty testing something that you know will pass.

8. What is the difference between white box testing and black box testing?
A. White box testing uses an internal perspective of the system to design test cases based on internal structure while Black box testing takes an external perspective of the test object to derive test cases.


9. What is the benefit of using a coverage tool?
A. It make sure that the program is performing normally; producing expected results with the smallest number of errors. Also shows you which line is being executed and if it contains errors or not.


10. What is the goal of GNU and what foundation did they create to help reach that goal?
A. The goal of GNU was to give users freedom, freedom to run the program, copy the program, modify the program, and distribute modified versions. They created the Free Software Foundation

Wednesday, October 14, 2009

Google hosting with express SVN checkout

For our final chapter in our robocode project, we got to create our own google project and discussion group. Yes, it might not sound like a fun thing to do, but rest assure that knowing how to do this will make collaboration on future projects a breeze.

Following the instructions from our professor, we managed to host our own project on google and create a discussion group to support our project. Being the owner of the project, we could select who to invite to be our members and give them access to our project. Couple that with a SVN program such as SmartSVN for Mac users or tortoiseSVN for PC, members can check out the project, make modifications to it, and upload it back to the project site with the new modifications. With this, everyone can work on the same project without having to be in the same place. Now isn't this a great thing to know.

With the instructions given, I didn't have much problem completing the tasks. The only hiccup that I ran into was adding codesite-noreply@google.com as a discussion list member. Following the link given by our instructor, I made a posting on googles support site and the moderator was able to give us a quick solution.
Please be sure that you understand that I am *not* adding 
codesite-noreply@google.com to your mailing list.
Instead, I am changing your project so that it send
email From: PROJECTNAME@googlecode.com.
It is then up to you to subscribe that email address
to your mailing list (if it only allows posts from members).


I've added our discussion list "robocode-aak-sidestep-discuss@googlegroups.com" to receive notification of any new changes/commits, but I didn't receive receive a notification email. Maybe I'm doing it wrong.

Something that I've learned from this is the usefulness of google project and SVN is. I've used google docs to share documents among group members before, but this is taking it to a different level.

Here are the links to my project page and my discussion group page.

Wednesday, October 7, 2009

Improved Junit testing With Help From Emma

So last week, we were introduced to Ant and Ivy which are great Quality Assurance tools. This week we go even further into QA by writing our own test cases and testing them with Junit. Why do test case, you asked? well, so far with Ant and Ivy, we're checked to see if our code is within a certain coding standard, that it'll compile with no error, and a simple test case to see if it'll beat SittingDuck. But we haven't test it to see if it does what its suppose to do. That's where you'll need the additional test case.

There were three types of test case that we have to write and test our robots with. They are acceptance (if the robot can consistently beat it's target), behavioral (verify that the robot satisfies a component of the strategy), and unit (verify that individual methods calculate the correct value) tests. The acceptance test were quite easy since our professor gave us an example of it which was tested against SittingDuck. By making a modification to the code changing the target robot name, I was able to create 2 new acceptance test case for my robot (SideStep) to go against Crazy and Walls. Both test passed via Eclipse and Ant, which was great considering that I had the hardest time getting Junit to work in Eclipse. ( After many fail attempts, I finally deleted Eclipse and reinstalled it and somehow Junit is working now with the same configuration that I used with the old one).

For the behavioral test, I created one that would test to see if my robot would fire only if the target is within 400 pixels. First off, writing test code was a lot harder than writing the actual code. I couldn't figure out how to call methods from other classes that I used in the actual code. After writing the test code by trail and error, it was able to pass the Junit test. Junit is still very new to me and I will probably need more time to look into it. But due to time constraints from my other classes (projects and exams) this week, I didn't have enough time into reading up on it, which I'll probably do over the remainder of this week.

Even with the help of Emma, I'm only about 50% sure that I'm testing the right thing. Emma is a great tool which outputs a html file that shows which line in the code it is testing and shows if the line fail or pass the test. I will continue this assignment through the rest of this week and will update this post with new test cases and discoveries.

Here is the code for my robot including its test cases.