|
17 | 17 | # Functions
|
18 | 18 | #-----------------------------------------------------------------------------
|
19 | 19 |
|
| 20 | +def make_testlists(): |
| 21 | + listlist = [[0,1,2],[3,4,5],[6,7,8,9]] |
| 22 | + dictset = {val:set(item) for val, item in enumerate(listlist)} |
| 23 | + listset = [set(item) for item in listlist] |
| 24 | + return listlist, listset, dictset |
| 25 | + |
| 26 | +def test_dictset_to_listset(): |
| 27 | + _, listset, dictset = make_testlists() |
| 28 | + new_list_set = util.dictset_to_listset(dictset) |
| 29 | + npt.assert_equal(new_list_set, listset) |
| 30 | + with npt.assert_raises(ValueError): |
| 31 | + tmp = util.dictset_to_listset(listset) |
| 32 | + |
| 33 | +def test_listset_to_dictset(): |
| 34 | + _, listset, dictset = make_testlists() |
| 35 | + new_dict_set = util.listset_to_dictset(listset) |
| 36 | + npt.assert_equal(new_dict_set, dictset) |
| 37 | + # capture wrong input type |
| 38 | + with npt.assert_raises(ValueError): |
| 39 | + tmp = util.listset_to_dictset(dictset) |
| 40 | + |
| 41 | +def test_no_repeats_in_listlist(): |
| 42 | + jnk = [[0,1,2],[3,4,5]] # all unique |
| 43 | + nt.assert_true(util._no_repeats_in_listlist(jnk)) |
| 44 | + jnk = [[0,1,2], [0,1,2]] |
| 45 | + nt.assert_false(util._no_repeats_in_listlist(jnk)) |
| 46 | + with npt.assert_raises(ValueError): |
| 47 | + util._no_repeats_in_listlist({0:0}) |
| 48 | + with npt.assert_raises(ValueError): |
| 49 | + util._no_repeats_in_listlist([set([0,1,2])]) |
| 50 | + |
| 51 | +def test_listlist_to_listset(): |
| 52 | + listlist, listset, _ = make_testlists() |
| 53 | + new_listset = util.listlist_to_listset(listlist) |
| 54 | + npt.assert_equal(new_listset, listset) |
| 55 | + with npt.assert_raises(ValueError): |
| 56 | + util.listlist_to_listset([[0,1,2],[0,1,2]]) |
| 57 | + with npt.assert_raises(ValueError): |
| 58 | + util.listlist_to_listset({}) |
| 59 | + |
20 | 60 | def test_slice_data():
|
21 | 61 | subcond, blocks, subjects, nodes = 5, 10, 20, 4
|
22 | 62 | data_4d = np.ones((blocks, subjects, nodes, nodes))
|
|
0 commit comments