2014年4月20日 星期日

009 test coverage in python

  寫扣一起寫單元測試,就像炒菜要加鹽,接下來會問的問題就是,鹽加的夠不夠,會不會加太多,鈉含量會不會過高。

  • 鹽加的不夠,菜的鮮度提不上來;測試涵蓋率不高,扣的品質無人知道。
  • 鹽加的太多,傷腎傷胃血壓飆升;測試涵蓋度追高,傷肝傷心是否划算。
  • 鈉含量太高,影響智力骨質流失;搭謎測試衝業績,勝了比例輸了徵兆。
進一段廣告,讓我們來看看 python 怎麼做程式碼涵蓋率測試。

008 unittest in python

  寫扣不寫單元測試,感覺就像炒菜不加鹽,不是大問題,只是怪怪的。

  Let's have a try with unittest in python. There are threes examples mentioned below, one is for "__name__", another is by "import unittest", and the other is reserved for someone who would like to customize his/her unittest via command line.

2014年4月8日 星期二

007 Group Keyword and Counting for Top N

#!/usr/bin/env python

# http://katazen.blogspot.com/2014/04/006-python-cookbook-01-09-finding-common.html
# http://katazen.blogspot.com/2014/04/006-python-cookbook-01-12-most.html

# http://stackoverflow.com/questions/743806/split-string-into-a-list-in-python
# http://www.saltycrane.com/blog/2007/09/how-to-sort-python-dictionary-by-keys/

Requirements:

  • There is one text section and it needs to select Top 10 keywords, which occurs at least thrice.
  • Even there is two text sections, it is still easy to merge the meta statistic.
  • It should be friendly to redirect to formatted output, such as CSV for Weka.


006 Python Cookbook 01-12 Most Frequently Items

#!/usr/bin/env python

# http://chimera.labs.oreilly.com/books/1230000000393/ch01.html#_determining_the_most_frequently_occurring_items_in_a_sequence
# 1.12 determining the most frequently occurring items in a sequence

006 Python Cookbook 01-09 Finding Common

#/usr/bin/env python

# http://chimera.labs.oreilly.com/books/1230000000393/ch01.html#_finding_commonalities_in_two_dictionaries