November 2011 Archives

Blog 4 - Testing

| 4 Comments

Today, I'm going to talk about CxxTest. But before we start to explore this cool unit, I think I need to introduce testing first. Testing is a really important part in programming, because in a thousand lines code, you might do something wrong in somewhere, or just missing some statuses. Without testing, though codes still run, but no one sure that this code won't go something wrong in the future. So, the best way to make sure our code is good, we can use some tools to help us. CxxTest is one of the useful testing units for C/C++, and it use just similar to C, so it is easy to use. But there comes another problem, where should test? In my experience, each function in your code needs "tests". Why I use "tests", not "a test"? Because of a small function, may need to deal with many cases. For example, one day, I just finished a function that can read something through user's input, and I need to identify the kinds of input. So maybe user enters a path of file, a web site, or something else, it make sense that I already writing some format to figure out the types. When we start testing, we can type some weird format to destroy our program. Use "destroy" I think is a great word to describe what testing system work, because only we find something wrong that we can know where need to fix. After writing as much as you can think the types to input, CxxTest will automatically help you to find error and the reason. And it will also show the percentage you pass the test, programming is really painful, but now you have a clear goal right there, so fight with the number and let it become 100%!

There are some useful macros to use in your test.h. Such as TS_ASSERT() will check the statement is true or not, it makes sense that you can put your function into this macro. Then it will return a "." if success, and show error in which test and which line. And there are so many macros you can check on http://cxxtest.sourceforge.net/guide.html to see detailed. Makefile is a good way to help you manage your source.

Some people think testing is boring, but I really enjoy it! Because I dislike the buggy codes, I will use many way try to test my code before I knew CxxTest. It give me a new way and rule way to testing code, I guess I will feel more confidence on my code now.

Blog 3 - Subversion and Source Control

| 4 Comments

        This time, we talk about Subversion and Source Control.  Before start to talk these two tools, I guess I can introduce what is version control system and source control system first.  First of all, version control system, as the name suggests, it can help programmer to control the version of program.  Imaging that one day you finish some coding, it work very well.  However, next day, when you want to add something new functions into your code, the code become buggy and buggy, finally, you just can't go back to begin.  You also forget to make some backup or tags, so you starting coding the first part again, and feel painful.  Though it can be avoid by some good habits, such as diligent backup your code, or make tag when you finish a part of work.  But once you forget, something bad will happened.  Using version control system, you can easy go back to previous version, and you can also compare two version are different in which part.  Though coding still painful, but using version control can let you feel much better.  Secondly, sometimes we need to cooperate with people, and one case we can imaging is, if two or more people try to work on same code at the same time, what will happen?  First, we need to upload the code when we finish, but different content with same file name, so we may over write other people's code.  So we can image that finally only the last upload people's code will stay.  How to avoid this problem?  Source control system can solve this problem.  This system will tell user that someone already committed the newer version, and asking user want to overwrite or compare with two versions.  And after compare two different versions, user can edit each part that code is different.  Then commit again and overwrite.  It sound like source control system is really powerful, but it has some annoying part.  For example, last time I just committed a code and then I still working on the same code, but as the same time, my partner saw that code and found that the format he doesn't like, so he move all the curly parens, and mix some if-else into switch case.  Through the code still work the same, but when I want to commit, I will see almost the whole code change.  It sound really fun, but if it happen on you, it is not fun.  So using the source control system, if you want to make some big change, try to let your partner know.

 

        Subversion, I think this tool just have both version control and source control, because once you committed, it will be a new version.  And it also can let user compare where the different between two versions is.  Though I use this system only half semester, I still have some experience on using subversion.  To call Subversion, we need to use "#svn"and uses some function follow it.  <%svn checkout [URL]> or <%svn ct [URL]> is the first time you need to use, it can make your computer linked with the group space.  That makes sense after doing this, your computer become one of the working space.  You will see a .svn folder in your space, that's why Subversion can automatic update or commit to correct site.  <%svn update> or <%svn up>is a most frequently used command, if something updated, it will show "U ppp.cpp" this kind of message, because you never know when you partner will committed their code, so do this command every time.  <%svn add [file/dir]>this can add files or directories to workspace, but they will be uploaded only after you committed.  <%svn status> or <%svn st>can show you what file is not in your workspace, such as "? asd.cpp".  And show what files you edited this time, such as "M zxc.cpp".  <%svn commit -m "message for this version"> this is also one of the most important commands in the Subversion.  It can upload all your change to workspace.  And there are some useful commands like use <%svn mv oldname newname> to rename, <%svn revert [file/directory]> to undo all change in this time to last version, but this command only can work before you committed.  <%svn copy>can let you make your tags or branches, <%svn merge> can mix two version's codes.  <%svn info>will show up information about these versions, <%svn log>will let you know the history of version. Finally, there are some status will show up during you using some commands.  "?" is for file which not in workspace, "A" is for files that this time you add, "C" means that file has been change, so cannot be merge, you may need to edit first, "D" means this file will delete from your workspace, "M" is for files you modified this time, and "U" means this file is been updated to new version.

 

        Subversion let me feeling good during Iteration1 and Iteration2 working with my partner.  But I'm still not very good at creating tag or when should make branch.  Practice makes perfect, I will keep trying these command and one day I'll good at using Subversion.

About this Archive

This page is an archive of entries from November 2011 listed from newest to oldest.

October 2011 is the previous archive.

Find recent content on the main index or look in the archives to find all content.