Interesting post. I'm in my first years practicing unit testing too. Won't miss leaving a long comment here!It seems the very problem about unit testing for you is about maintainability of the test cases. It was a question for me too about how many tests to write for particular class. The lower number of tests you write, the lower maintainance problems, right?There are some occassions I avoid writing tests for. I am not claiming these are right or wrong but it seems to work for me.#1: During our undergrad years, I was introduced to unit testing (with JUnit.) What I remembered are that we are encouraged to write tests for as many methods as possible. We even generated the tests for plain getter/setters. Come to think of it now, that was totally unpractical!So now I just skip the simple methods I am sure there are only silly test cases for it.#2: Another thing is about writing test for private methods. When you design a class, you are giving your users some kind of contract by providng public methods. These are something that should be broken or be changed often. If you need to change these often, you may have to admit the class is incorrectly designed and thus rewrite/add the tests.However, I do not test private methods. This give me some room of flexiblity where I can change/optimize/organize the inner working of the class. I can change the signature/working of private methods any way I would like to, but I just need to make sure the public methods do pass the tests.#3: I do have some tests you referred to as 'small acceptance tests.' However, to perform 'unit' testing, you test one and only one class. If the class depends on some other concrete classes then you have to change them to abstract/interface instead. If you are testing more than one classes than that may be considered as 'integration' testing, or some other names.That was quite hard core! While I know this, I don't mock out some dependencies for small classes. That would require some efforts. But still, I would write integration tests for it.Clearly, innovations in our world do not start with requirements from users. So all these models starting from requirement gathering are all WRONG. If you want to introduce something now, use whatever you like and do whatever you want to. But if you are building something big, you must also need to look into the rear mirrors and you do need some confidence going forward. Unit tests, test coverage, etc. are some of the answers to that.
Sunday, September 25, 2011
Sunday, July 10, 2011
I got hit by an interesting problem of “Zebra Puzzle” the other day. It is a well known logic puzzle believed to be first invented by Albert Einstein.
The question here is, how do we use our favorite programming language to solve this problem?
Wikipedia suggests the following algorithm for generating all permutation systematically.
The following algorithm generates the next permutation lexicographically after a given permutation. It changes the given permutation in-place.
- Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
- Find the largest index l such that a[k] < a[l]. Since k + 1 is such an index, l is well defined and satisfies k < l.
- Swap a[k] with a[l].
- Reverse the sequence from a[k + 1] up to and including the final element a[n].
I have put the working example on http://www.solidskill.net/ZebraPuzzle.htm. There are other parts of code that search through the solution space, setup the constraints for Zebra puzzle. But they are not discussed here.
There are some things to note about this implementation though. First, it is not very efficient. You can see in the getNextSequence(..) loop that there are loops used to search for k and l that satisfy the conditions.
Hope this helps those who are looking for permutation generation code.
Sunday, January 9, 2011
I just recently got my hands on Seagate’s GoFlex TV. In combination with my existing 32” LG TV, this device would allow the playbacks of the movie files, in so many supported formats, from the USB storage device directly to my 1080p TV. This sounds very perfect to me as I often find it’s not very easy to turn on my desktop PC just to watch movies. The device comes with LAN adapter which allows it to connect to your home network, and view YouTube, Picasa, or playback from network’s shared folder. Moreover, to my surprise, it also supports USB keyboard! This was beyond my expectation.
Enough for the introduction.
Playing back from USB storage was fine and good, and it works nicely with my Buffalo portable HDD out of the box. The real pain kicks in when I tried to play my *.mkv file sitting on my Windows 7 PC’s shared folder. The GoFlex keeps asking for username and password which I entered numerous times over few hours, and without success. It keep showing “Logon Failed” message on the screen! This is pretty annoying.
Search from Google didn’t give much help, but the search on Seagate’s user forums itself revealed a thread containg instructions which fix the problem! Original post at http://forums.seagate.com/t5/FreeAgent-Theater/FREEAGENT-A-Guide-to-get-the-most-out-of-your-FAT/td-p/48382
WINDOWS 7, NETWORK PROBLEMS:
So, you have Windows 7, but you can't get your FAT+ to log on to the network. Well here's some instructions to help you get around that:
First go to the Control Panel, then select Network & Sharing Center, then on the left pane select "Change advanced sharing settings".
- Then select in the settings:
- Turn on network discovery
- Turn on file & printer sharing
- Turn on sharing so anyone with network access can read & write files in the Public folders
- on Media Streaming (I'll come back to that)
- Enable file sharing for devices that use 40 -or 56-bit encryption
- Turn off password protected sharing
- Now make sure you have the same setting for both Home or Work & Public profiles
- For the Media Streaming, select "Chose media streaming options...", the on the "Show devices on:" dropdown box select "All networks". You should then see something that says "Unknown Device", make sure that it has "Allow" beside it.
IF that doesn't work, try this:
Click Start and type Regedit in the search and click Regedit.exe
Navigate to the following location in the registry editor.
1. On the right side Double Click on everyoneincludesanonymous and in the window that pops up, change the value data from a 0 value to a 1
2. Double Click on NoLmHash and in the window that pops up, change the Value Data from a 1 value to a 0
3. Now navigate to the following location in the registry editor
Double Click on restrictnullsessaccess and change the 1 value to a 0
Reboot your pc and you should now be able to connect to your pc from you Freeagent Theater+
This works for me, I also have my drives shared with full access on my LAN
You will still see the Login screen just click OK and you should have access to your drives.
(Originally submited by ColinK)
This should also work with Vista.
Here a link for WINDOWS XP network problems. (Give a few Kudos to bodhi78 for this one)
This took so much time from me that I would like to share this with other GoFlex TV users. I lived happily, enjoyed 1080p, the last 12 hours ever since the fix :)