2011年7月26日火曜日

開発環境

  • Mac OS X Snow Leopard (OS)
  • WingIDE
  • Script言語: Python

『初めてのコンピュータサイエンス』(Jennifer Campbell, Paul Gries, Jason Montojo, Greg Wilson 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-463-7)の10章(アルゴリズム), 10.4(練習問題), 3を解いてみる。

 

3.

importでの関数名が被るとどうなるか、対処法等よく分かってないのでNoseテスト前に関数名を少し修正。

リスト[1, 2]でテスト

コード(関数)

import nose
from find_remove_find5 import find_two_smallest
from sort_then_find3 import find_two_smallest_1
from walk_through7 import find_two_smallest_2

def test_find_two_smallest():
    assert find_two_smallest([1,2])==(0,1)
    
def test_find_two_smallest_1():
    assert find_two_smallest_1([1,2])==(0,1)

def test_find_two_smallest_2():
    assert find_two_smallest_2([1,2])==(0,1)
    
if __name__=='__main__':
    nose.runmodule()

入出力結果(Python Shell)

負の数も加え、要素数も3以上のリスト[1, 2, -3]でテスト

コード(関数)

import nose
from find_remove_find5 import find_two_smallest
from sort_then_find3 import find_two_smallest_1
from walk_through7 import find_two_smallest_2

def test_find_two_smallest():
    assert find_two_smallest([1, 2, -3])==(2, 0)
    
def test_find_two_smallest_1():
    assert find_two_smallest_1([1, 2, -3])==(2, 0)

def test_find_two_smallest_2():
    assert find_two_smallest_2([1, 2, -3])==(2, 0)
    
if __name__=='__main__':
    nose.runmodule()

入出力結果(Python Shell)

テスト終了。

0 コメント:

コメントを投稿