def ztest_uniqueness_of_lettercolumns_addition_recursive(self): ''' NOT PASSING this by now. The nonrecursive is working. The recursive is not yet working. :return: ''' # 1 from a to 0 should raise IndexError cell_letters = 'a'; ncolumns = -1 self.assertRaises(IndexError, tblfs.move_columns_by, cell_letters, ncolumns, True) # 2 from z to 0 should raise IndexError cell_letters = 'z'; ncolumns = -26 self.assertRaises(IndexError, tblfs.move_columns_by, cell_letters, ncolumns, True) # 3 z plus 1 should be aa cell_letters = 'z'; ncolumns = 1 expected_cellref = 'aa'.upper() returned_cellref = tblfs.move_columns_by(cell_letters, ncolumns, True) self.assertEqual(expected_cellref, returned_cellref) # 4 aa minus 1 should be z (commutative to the above operation) cell_letters = 'aa'; ncolumns = -1 expected_cellref = 'z'.upper() returned_cellref = tblfs.move_columns_by(cell_letters, ncolumns, True) self.assertEqual(expected_cellref, returned_cellref)
def generate_random_numbers( innerlooprun): # innerlooprun = innerloopruns[decimalplace] ongoing_conv_letters = 'a' baknumber = 0 total = 0 parcelcounter = 0 positnumcount = 0 negatnumcount = 0 for decimalplace in range(3, -1, -1): for nsubparcel in range(innerlooprun): parcelcounter += 1 sign_n = random.randint(0, 1) sign = 1 if sign_n else -1 if sign == 1: positnumcount += 1 else: negatnumcount += 1 parcel = sign * (random.randint(0, tblfs.NSYSTEM27SIZE) * tblfs.NSYSTEM27SIZE**decimalplace) if total + parcel < 1: # print (' => throwing away parcel %d | total %d' %(parcel, total)) continue total += parcel ongoing_conv_letters = tblfs.move_columns_by( ongoing_conv_letters, parcel) #print(parcelcounter, 'total %d | parcel %d | decimalplace %d ' %(total, parcel, decimalplace)) #print ('positnumcount', positnumcount, 'negatnumcount', negatnumcount, positnumcount+negatnumcount) #print('ongoing_conv_letters', ongoing_conv_letters) baknumber = tblfs.convert_columnletters_to_number_nonrecursively( ongoing_conv_letters) #print('baknumber', baknumber) quad = total, baknumber, total - baknumber, innerlooprun quad_totalint_totalcells_nparcels.append(quad)
def test_uniqueness_of_lettercolumns_addition_nonrecursive(self): # 1 from a to 0 should raise IndexError cell_letters = 'a'; ncolumns = -1 self.assertRaises(IndexError, tblfs.move_columns_by, cell_letters, ncolumns) # 2 from z to 0 should raise IndexError cell_letters = 'z'; ncolumns = -26 self.assertRaises(IndexError, tblfs.move_columns_by, cell_letters, ncolumns) # 3 z plus 1 should be aa cell_letters = 'z'; ncolumns = 1 expected_cellref = 'aa'.upper() returned_cellref = tblfs.move_columns_by(cell_letters, ncolumns) self.assertEqual(expected_cellref, returned_cellref) # 4 aa minus 1 should be z (commutative to the above operation) cell_letters = 'aa'; ncolumns = -1 expected_cellref = 'z'.upper() returned_cellref = tblfs.move_columns_by(cell_letters, ncolumns) self.assertEqual(expected_cellref, returned_cellref)
def adhoc_test6(): # 1 foward cell_letters = 'z' ncolumns = 26 * 26**3 + 26 mid_letters = tblfs.move_columns_by(cell_letters, ncolumns) ncolumns = 26 * 26**5 + 26 * 26**2 + 26 * 26**1 next_cell_letters = tblfs.move_columns_by(mid_letters, ncolumns) print('1 forward', cell_letters, '| mid =', mid_letters, '| next_cellref =>', next_cell_letters) # 1 backward cell_letters = 'UODRTA' ncolumns = 26 * 26**5 + 26 * 26**2 + 26 * 26**1 ncolumns = (-1) * ncolumns mid_letters = tblfs.move_columns_by(cell_letters, ncolumns) ncolumns = 26 * 26**3 + 26 ncolumns = (-1) * ncolumns next_cell_letters = tblfs.move_columns_by(mid_letters, ncolumns) print('1 backward', cell_letters, '| mid =', mid_letters, '| next_cellref =>', next_cell_letters)
def lesser_number_test(nruns): ongoing_conv_letters = 'a' total = 0 baknumber = 0 for i in range(nruns): parcel = random.randint(-1000, 1000) if parcel == 0 or (total + parcel) <= 0: continue total += parcel ongoing_conv_letters = tblfs.move_columns_by(ongoing_conv_letters, parcel) baknumber = tblfs.convert_columnletters_to_number_nonrecursively( ongoing_conv_letters) # adjust baknumber with -1 for 'a' is 1 and algo the origin baknumber -= 1 print('nruns =', nruns, '| total =', total, '| baknumber =', baknumber, '| dif =', total - baknumber)