Monday, October 19, 2009

Make My Robocode Open Sourced

Most of the time when people try to accomplish a complicate task, they need collaborate with other people. For example, you may know exactly how to build an Egyptian Pyramid, but you can never finish it alone. Therefore, it is very important to learn the art of collaboration. In software development, the tool that help people to collaborate is called version control program. This time, I will share my experience of using subversion(SVN) and Google Project Hosting.

Google Project Hosting is a free place that you can use as a repository. To start creating a new project, you need to have a gmail account. Once you log in, you can create a project with a project name you specify. Then you can put some summary and description for your project. The description is formatted in Wiki markup format. It has some tutorial on line and it is pretty straight forward. Then you can start inviting your partners to this project.

You might realize that there is no source code for your project yet. Yes, you need to use an SVN client to export your code into the on line repository. What I did is I downloaded and installed the TortoiseSVN on my machine (I use Windows), then I restarted my computer. Because TortoiseSVN is integrated within the shell, you can just right click on the project folder and go to TortoiseSVN and choose "Export". Then you need to type in the URL of repository in the text box and click "OK". After authentication, SVN client is going to upload everything in that folder to the on line repository and you will find your code if you click "Browse" in the "Source" tab in the your google project. If you partners need to work on your project, they can do a SVN Checkout and they will have a copy of the project locally.

Now, the most important thing is done. Later, you may want to create a google group for discussion of your project and put some wiki pages in your project as documentation.

SVN is a really important tool that facilitates a large project development. People can check out the source and work on their own. After they finished their part, they can submit the change and SVN will help to merge them together. If there is a conflict occurred, SVN will point out the difference and ask developers to figure it out. I cannot imagine how much time and effort in project development are saved from version control.

Yichi's Quicky Quiz

Here are some quicky quiz questions that I think may be asked in the mid-term.

1. When you start software development, which editor you want to use, wordpad or Eclipse? Why you choose it?
- Use Eclipse because wordpad is not an IDE. IDE is very important in software development. It helps developers understand the system hierarchy better. It also shows syntax errors which saves lots of time locating the problem. It also supports for testing, debugging and refactoring.

2. Name two new features of Java 5 comparing with C?
- In Java, parameters are always passed by value.
- Java supports basic collections


3. Implement the FizzBuzz program in Java. FizzBuzz program should print out all of the numbers from 1 to 100, one per line, except that when the number is a multiple of 3, you print "Fizz", when a multiple of 5, you print "Buzz", and when a multiple of both 3 and 5, you print "FizzBuzz".
public class FizzBuzzClass {

public static void main(String[] args){
for(int i = 1; i <= 100; i++){
System.out.println(GetFizzBuzz(i));
}
}

static String GetFizzBuzz(int n){
if(n%3==0&&n%5==0){
return "FizzBuzz";
}
else if(n%3==0){
return "Fizz";
}
else if(n%5==0){
return "Buzz";
}
else{
return Integer.toString(n);
}
}
}



4. Design three unit test for the FizzBuzz program.
-Test 1: Make sure GetFizzBuzz(3) return "Fizz"
-Test 2: Make sure GetFizzBuzz(4) return "4"
-Test 3: Make sure GetFizzBuzz(5) return "Buzz"


5. Why coding standard is important for a program?
- Code standard is important because it improves the readability, understandability, and maintainability of the code.

6. When you create a class in Java why you want to override equals method and hashCode method most the time?
- Because the default implementation for equals method and hashCode method might not be correct for your class.

7. What is the advantage for using Ant? Briefly describe how would you write an Ant build system for a program.
Ant has a file-level dependency management and it has built-in support for Java and simplifies cross-platform Java development. To build a system, you need to define a default target which ant will run first. Then you may want to use IVY to get all the third party libraries that used in your system. Lastly, you need to include all the code that need to be compiled.

8. What are the advantages and disadvantages for manual quality assurance and static quality assurance?
-Manual QA can detect some logical problems, but it takes time to write lots of customized tests. Static QA is to use some existing tools such as FindBugs, they mostly check for some simple problems such as an unused variable.

9. Why configuration management is important for a project?
Configuration management helps developers back track the changes that made to the system.

10. In case you run into a problem in question 3 (For example, you don't know how to print "FizzBuzz"), and you want to ask other people for help. how would generate ask your question:)
Hi there, I am working on a FizzBuzz program(discribe FizzBuzz). I can print "Fizz" and "Buzz" but I cannot print "FizzBuzz" when the number has a factor of 15. Here is my code:
static String GetFizzBuzz(int n){
if(n%3==0andn%5==0){
return "FizzBuzz";
}
else if(n%3==0){
return "Fizz";
}
else if(n%5==0){
return "Buzz";
}
else{
return Integer.toString(n);
}
}

Any Comment?

Wednesday, October 7, 2009

Play around with Junit~~

After applied some automated QA tools (CheckStyle, PMD, FindBugs) to my robocode project, it is also important to write some tests manually to assure my robot works correctly. This time, I created total six tests for my project, including two acceptance tests, two behavioral tests, and two unit tests. Here is a list of my tests.

Acceptance tests:
1. check if my robot can beat SittingDuck 10 times out of 10 battles.
2. check if my robot can beat Walls more than 5 times out of 10 battles.

Behavioral tests:
1. check if my robot ever visited the four corners in the battlefield during 5 battles.
2. check if my robot ever fire at SittingDuck and hit SittingDuck during 5 battles.

Unit tests:
1. check if the calculation for robot heading given the start position and target position is correct.
2. check if the calculation for normalizing angles is correct.

In my case, acceptance test is the easiest test to create. It only checks the "strength" of the robot to make sure it fits in some requirements. Unit test is a little bit harder to create, because it depends on the complexity of the unit that need to be tested. If the unit is relatively big, it is nice to break it down to pieces and write unit test for each pieces. I think the behavioral test is the most challenging test to create. For example, I tried to write a detail test for my robot's firing strategy. The firing strategy is determined by the robot's sensor. However, in a battle, we cannot tell when, where, and how robots see another robot unless we set the initial positions for all the robots. Therefore, it is very hard to test a specific behavior at a certain point of time. The most we can do is track if the robot ever made certain movement during a period of time.
After creating the test, I used Emma to check the coverage of my tests. 59% of lines of code are tested which is a acceptable number since there is only 6 tests. However, I think, to be a solid test, more than 90% of lines of code should be tested. I think test case is an important way to ensure the quality of the project, especially for a large system. Test is like a documentation for the system. It helps developers to mentain the system in a more efficient way. Also, developers can even develop the system by writing tests.

Here is my latest code with all the tests:http://www2.hawaii.edu/~yichi/robocode-xyc-yichispecialbot-1.1.1007.zip