Sunday, 13 June 2010

The blogger html editor is wrong and has evil desires to follow compose mode actions.

Problem: blogger html/compose editor does not understand the css of the blog. So you can not preview your 'class' changes nor see the efects in Compose. Well, this is annoying by does not matter, I can use firebug for doing that and test the final look without publish it.

But where this 'feature' is annoying is in the <pre> vs css: white-space:pre;

If you have any text preformated but using a CSS class with "white-space:pre", that's ok and it works the first time. BUT.... if you try to edit it, it does not see any <pre> tag so it reformats the text and you loose all indentation!!!!

Wednesday, 9 June 2010

Dr. Hadley Wickham, the creator the fantastic R library ggplot2 has created an online course at statistics.com:

http://www.statistics.com/ourcourses/ggplot2
price $500

Visualization in R with ggplot2

Aim of Course:

In this course, participants will learn how to use the ggplot R Project to make, format, label and adjust graphs using R. The ggplot2 Project, created by Hadley Wickham, is named after the term "Grammar of Graphics," which was coined by Leland Wilkinson (creator of Systat). This "grammar of graphics" is a system of describing and organizing the fundamental components of a graph and the process of creating a graph. Using ggplot2, participants will learn how to design and implement graphs in an efficient, elegant and systematic manner, following principles of general good graphing practice.

Who Should Take This Course:

Statistical analysts who use R and need to create or modify graphs.

The Instructor:

Dr. Hadley Wickham is the author of ggplot2: Elegant Graphics for Data Analysis (Use R) and a contributor to Cook & Swayne's Interactive and Dynamic Graphics for Data Analysis: Using R and GGobi (2007). His research interests include interactive and dynamic graphics, developing practical tools for data analysis, and in gaining better understanding of complex statistical models through visualization. An Assistant Professor at Rice University, Dr. Wickham has developed 15 R projects, and written numerous articles, chapters, and other papers and in 2006 he won the John Chambers Award for Statistical Computing for his work on the ggplot and reshape R packages.

More about testing: handling exceptions

Today I was updating some tests for my modules and I needed to test the exception handling. I was going to use 'eval{..}or do{..}' but decided to go for Try::Tiny, but once I entered in the path of using CPAN modules I decided to give a try (not pun intended) to Test::Exception.

I have read about some people complaining about Test::Exception using prototypes and talking about this would lead to some unexpected behaviors in very uncommon situations. The author of Test::Exception also implemented the methods without prototypes (they are less attractive) but I don't know if not using the prototyped methods are free of the edge cases errors. Any way chromatic explained in this blog entry how the prototyped methods in Test::Exception works.

Here I am playing with the test to see how can I handle the output of the tests:

* First try

Created a basic test "test_Test_Exception.t" to see if my method die

use strict;
#use warnings;
#use Data::Dumper;
use Test::More;
use Test::Exception;

This is even better: test2 now fails if the exception text is not the expected one.

* third try

A more complicated case:
I have a subrutine, and I test for one of the arguments but I tested for lowercase 'a' instead uppercase 'A'. But this subrutine has another exception and dies when second argument is 'B'

#
## more about throws_ok
#

# testing an exception but obtaining other
# error in the method: testing a instead A
# - it should die when passing 'A' but does not die because that
$ok1 = dies_ok (sub {die3('A', 'B')}
, 'testing faulty method die3 with dies_ok: it should die BUT does it because another reason'
);

$ok2 = throws_ok (sub {die3('A', 'B')}
, qr/because A/
, 'testing faulty method die3 with throws_ok it should die BUT does it because another reason'
);

# with dies_ok wrong result, it is happy with the death (but by the wrong motives :-():

ok 1 - testing faulty method die3 with dies_ok: it should die BUT does it because another reason

# but the expected result (failed) with throws_ok

not ok 2 - testing faulty method die3 with throws_ok it should die BUT does it because another reason
# Failed test 'testing faulty method die3 with throws_ok it should die BUT does it because another reason'
# at /nfs/users/nfs_p/pg4/programming/perl/test_Test_Exception.t line 61.
# expecting: Regexp ((?-xism:because A))
# found: die because BLAH at /nfs/users/nfs_p/pg4/programming/perl/test_Test_Exception.t line 100.

#

ok 3 - testing faulty method die3 with throws_ok for another exception that works ok

# it fails because not die

not ok 4 - testing faulty test with dies_ok for die3: should die but it doesn't
# Failed test 'testing faulty test for die3: should die but it doesn't'
# at /nfs/users/nfs_p/pg4/programming/perl/test_Test_Exception.t line 73.

# It fails because does not die at all and tell you that: "found: normal exit"

The throws_ok is more informative and prevents to think that your test failed as expected when indeed was not "as expected" but because another reason.

This is fine, but if I want double check the output messages for the exceptions when debugging, I need to add the 'and diag($@)' or if I want to see if it failed because other exception or because it didn't die I need to do the following:

Next step is to explore the Test::Trap that seems that have better layers for handling and reporting the exceptions. But at the moment if you want a simple ok/fail for exceptions Test::Exception is very handy.