test_framework.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:lang2program 作者: kelvinguu 项目源码 文件源码
def assert_array_collections_equal(correct, test, decimal=7):
    """Assert that two collections of numpy arrays have the same values.

    Collections can be either a Sequence or a Mapping.
    """
    if type(correct) != type(test):
        raise ValueError('correct ({}) and test ({}) must have the same type.'.format(type(correct), type(test)))

    assert_equal = lambda c, t: assert_array_almost_equal(c, t, decimal=decimal)

    if isinstance(correct, Sequence):
        assert len(correct) == len(test)
        for c, t in izip(correct, test):
            assert_equal(c, t)
    elif isinstance(correct, Mapping):
        # same keys
        assert set(test.keys()) == set(correct.keys())
        # same values
        for key in test:
            assert_equal(correct[key], test[key])
    else:
        raise TypeError('Inputs must be of type Mapping or Sequence, not {}.'.format(type(correct)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号