社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

有没有更有效/更好的方法用python编写测试用例?

Aria West • 3 年前 • 1432 次点击  

有没有更有效的方法用python编写测试用例?每当代码重复时,我的测试用例都会重复——有更好的方法来编写它,但有什么更好的方法呢? 这是我的代码:

def are_anagrams(s1, s2):
    if len(s1) != len(s2):
        return False
    elif sorted(s1) == sorted(s2):
        return True
    else:
        return False

    #all below I want to write in a better way
#Test cases
        s1 = "danger"
        s2 = "garden"
        print(are_anagrams(s1,s2))
        t1 = "nameless"
        t2 = "salesmen"
        print(are_anagrams(t1,t2))
        a1 = "name"
        a2 = "sale"
        print(are_anagrams(a1,a2))
        b1 = "n"
        b2 = "sa"
        print(are_anagrams(b1,b2))
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131988
 
1432 次点击  
文章 [ 2 ]  |  最新文章 3 年前