Here is a mini version of problem
a = [[1,2,3][0,0,0]]
b = [[1,0,1][0,0,0]]
c = [[0,0,0][1,0,1]]
so if level 1 is [] and level 2 is [[]], then what i'm trying to do is test ever list to see if there level 2's match (regardless of order) so in this case b,c are equivalent.
i'm using unittesting and nosetests to run them If i wanted to just test one table against another i would do something like:
the function truth() creates my tables
def test_table1_table2(self):
for row in truth(1,3):
self.assertIn(row,truth(2,4))
but My goal is to test all tables against all other tables i have created (about 20 and growing). Some issues i can't work out (i'm not sure if i need to read unittest docs or nosetests or don't even need them!)
my guess is to just use more for loops to pull out ever possibility. But using
>>> nosetest
with a
assertIn
just stops at the first error, which isn't what i want. i need to scan and collect info on which lists are equivalent at (regardless of order or the nested lists). maybe i should just create something and forget about unittests?
so my preferred output would be something like
table1 and table2 are not equivalent
table1 and table2 are not equivalent
or probable more useful and shorter would just be
table1 and table10 are equivalent
Here is the code i have currently, almost everything is just a integer there expect truth() which makes the truth table (nested list):
114 def test_all(self):$ |~
115 ''' will test all tables'''$ |~
116 for expression in range(self.count_expressions()):$ |~
117 num_var = count_vars(exp_choose(expression))$ |~
118 for row in truth(expression, num_var):$ |~
119 for expression2 in range(self.count_expressions()):$ |~
120 num_var2 = count_vars(exp_choose(expression2))$ |~
121 for row2 in truth(expression2, num_var2):$ |~
122 self.assertIn(row, truth(expression2,num_var2))
A simpler approach would be to use unittest's assertItemsEqual, which is designed for exactly this purpose. Given O.P.'s a, b, & c nested lists:
class CheckingEqualityIgnoreOrder(unittest.TestCase):
def testAB(self):
self.assertItemsEqual(a, b)
#fails
def testBC(self):
self.assertItemsEqual(b, c)
#passes
def testAC(self):
self.assertItemsEqual(a, c)
#fails