# Path: csc/divisi/util.py



from nose.tools import eq_, assert_almost_equal
from csc.divisi.util import nested_list_to_dict
            assert_almost_equal(abs(actual_val), abs(expected_val))
        else:
            assert_almost_equal(actual_val, expected_val)

    # Test the values() method
    specified_values = specified.values()
    if not absolute:
        for a, e in zip(sorted(actual.values()), sorted(specified_values)):
            assert_almost_equal(a, e)

    # Test that the length of the tensor is equal to the number of specified items
    eq_(len(actual), len(specified_keys))

    # Test the __contains__ method
    assert specified_keys[0] in actual
    # can't easily test the contrapositive, since we can't easily make up an index that's not in there.

def assertIterDimKeysCorrect(actual, expected):
    specified_indices = [k for k, v in expected.iteritems()
                         if v is not None]
    for dim in xrange(len(specified_indices[0])):
        expected_keys = set(key[dim] for key in specified_indices)
        dim_keys = list(actual.iter_dim_keys(dim))
        eq_(sorted(dim_keys), sorted(expected_keys))

def assertTensorEqual(actual, expected, abs=False):
    '''Takes an n-dimensional array 'expected' and runs several
    tests on the tensor 'actual'. For the test description, see
    assertTensorEqualCompleteDict.
    '''

# Path: csc/divisi/util.py



# Path: test/tensor_util.py
from nose.tools import eq_, assert_almost_equal
from csc.divisi.util import nested_list_to_dict

            assert_almost_equal(abs(actual_val), abs(expected_val))
        else:
            assert_almost_equal(actual_val, expected_val)

    # Test the values() method
    specified_values = specified.values()
    if not absolute:
        for a, e in zip(sorted(actual.values()), sorted(specified_values)):
            assert_almost_equal(a, e)

    # Test that the length of the tensor is equal to the number of specified items
    eq_(len(actual), len(specified_keys))

    # Test the __contains__ method
    assert specified_keys[0] in actual
    # can't easily test the contrapositive, since we can't easily make up an index that's not in there.

def assertIterDimKeysCorrect(actual, expected):
    specified_indices = [k for k, v in expected.iteritems()
                         if v is not None]
    for dim in xrange(len(specified_indices[0])):
        expected_keys = set(key[dim] for key in specified_indices)
        dim_keys = list(actual.iter_dim_keys(dim))
        eq_(sorted(dim_keys), sorted(expected_keys))

def assertTensorEqual(actual, expected, abs=False):
    '''Takes an n-dimensional array 'expected' and runs several
    tests on the tensor 'actual'. For the test description, see
    assertTensorEqualCompleteDict.
    '''

    expected_dict = nested_list_to_dict(expected)