《笨办法学python》(《learn python the hard way 3thrd》)习题48(ex48)的代码实现
生活随笔
收集整理的這篇文章主要介紹了
《笨办法学python》(《learn python the hard way 3thrd》)习题48(ex48)的代码实现
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
目標(biāo):利用測(cè)試程序來(lái)寫(xiě)函數(shù)。
體會(huì):一步一步來(lái),完成后開(kāi)森~
測(cè)試用例的代碼如下(原書(shū)提供):
from nose.tools import * from ex48 import lexicondef test_directions():assert_equal(lexicon.scan("north"), [('direction', 'north')])result = lexicon.scan("north south east")assert_equal(result, [('direction', 'north'),('direction', 'south'),('direction', 'east')])def test_verbs():assert_equal(lexicon.scan("go"), [('verb', 'go')])result = lexicon.scan("go kill eat")assert_equal(result, [('verb', 'go'),('verb', 'kill'),('verb', 'eat')])def test_stops():assert_equal(lexicon.scan("the"), [('stop', 'the')])result = lexicon.scan("the in of")assert_equal(result, [('stop', 'the'),('stop', 'in'),('stop', 'of')])def test_nouns():assert_equal(lexicon.scan("bear"), [('noun', 'bear')])result = lexicon.scan("bear princess")assert_equal(result, [('noun', 'bear'),('noun', 'princess')]) def test_numbers():assert_equal(lexicon.scan("1234"), [('number', 1234)])result = lexicon.scan("3 91234")assert_equal(result, [('number', 3),('number', 91234)]) def test_errors():assert_equal(lexicon.scan("ASDFASDFASDF"), [('error', 'ASDFASDFASDF')])result = lexicon.scan("bear IAS princess")assert_equal(result, [('noun', 'bear'),('error', 'IAS'),('noun', 'princess')])總結(jié)
以上是生活随笔為你收集整理的《笨办法学python》(《learn python the hard way 3thrd》)习题48(ex48)的代码实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Python】编程笔记11
- 下一篇: 金融贷款逾期的模型构建5——数据预处理