def test__split_dates(self): self.assertEqual(self.rows[0]._split_dates(), [datetime.date(1970, 1, 1)]) self.assertEqual(self.rows[2]._split_dates(), [datetime.date(1970, 1, 3)]) self.assertEqual(self.rows[4]._split_dates(), [ datetime.date(1972, 1, 29), datetime.date(1972, 2, 29), datetime.date(1972, 3, 29), datetime.date(1972, 4, 29), datetime.date(1972, 5, 29) ]) self.assertEqual(self.rows[5]._split_dates(), [ datetime.date(1972, 1, 31), datetime.date(1972, 2, 29), datetime.date(1972, 3, 31), datetime.date(1972, 4, 30), ]) obj = balance.Row("100", "1970-01-01", "!months") with self.assertRaises(ValueError): obj._split_dates() obj = balance.Row("100", "1970-01-01", "!months:1:2:3") with self.assertRaises(ValueError): obj._split_dates()
def test_value_init(self): """Test default Row object creation""" # 1. Create default claim object myrow = row.Row(number=4) # 2. Make sure it has the default values self.assertEqual(myrow.number, 4) self.assertEqual(len(myrow.counts), 0) # 3. Check methods claim1 = claim.Claim(text='#1 @ 1,3: 4x4') myrow.add_claim(claim1) self.assertEqual(len(myrow.counts), 4) self.assertEqual(myrow.claimed(), 4) self.assertEqual(myrow.overlap(), 0) claim2 = claim.Claim(text='#2 @ 3,1: 4x4') myrow.add_claim(claim2) self.assertEqual(len(myrow.counts), 6) self.assertEqual(myrow.claimed(), 6) self.assertEqual(myrow.overlap(), 2) claim3 = claim.Claim(text='#3 @ 5,5: 2x2') myrow.add_claim(claim3) self.assertEqual(len(myrow.counts), 6) self.assertEqual(myrow.claimed(), 6) self.assertEqual(myrow.overlap(), 2)
def test_hashtag(self): self.assertEqual(self.rows[0].hashtag, None) self.assertEqual(self.rows[3].hashtag, 'hashtag') with self.assertRaises(ValueError): balance.Row("100", "1970-01-01", "#two #hashtags")
def part_one(args, input_lines): "Process part one of the puzzle" # 1. Register the claims claims = register_claims(input_lines) if args.verbose: print("%d claimes filed" % len(claims)) # 2. Get the top most and bottom most row numbers of the claims first, last = first_and_last(claims) # 3. Start with no overlapping squares solution = 0 # 4. Loop from the first to last rows with a claim for number in range(first, last - 1): # 5. Create a row onerow = row.Row(number=number) # 6. Determine the claims on the squares in that row for c in claims: onerow.add_claim(c) # 7. Get the number of squares with overlapping claims squares = onerow.overlap() if args.verbose: print("%d overlapping squares in row %s" % (squares, number)) # 8. Accumulate the total number of overlapping squares solution += squares # 9. Return result print("The solution is %d" % (solution)) return solution is not None
def safe(self, rows): "Return the number of safe tiles given the number of rows" # 1. Start with nothing result = 0 # 2. Handle odd ball cases if not self.row or rows < 1: return None # 3. Start with the initial row the_row = row.Row(text=self.row.text) # 4. Loop for all of the rows for number in range(rows): if number > 0 and number % 1000 == 0: print(number, result, flush=True) # 5. Add it the safe tiles for this row result += the_row.count_safe() # 6. Advance to the next row the_row.tiles = the_row.next_tiles() # 7. Return the total number of safe tiles return result
def test_bangtag(self): self.assertEqual(self.rows[0].bangtag(), None) self.assertEqual(self.rows[2].bangtag(), 'bangtag') obj = balance.Row("100", "1970-01-01", "!two !bangtags") with self.assertRaises(ValueError): obj.bangtag()
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.row = None # 2. Process text (if any) if text is not None and len(text) > 0: self.row = row.Row(text=text[0], part2=part2)
def __init__(self, depth, length, fast_count): self.length = length self.fast_count = False if fast_count.lower().startswith("y") else True self.depth = depth self.total_pattern_count = 2**(self.length * self.depth) self.good_patterns = 0 self.partitions = self.generate_set_of_partition_sets() self.rows = [ r.Row(i, self.length, self.partitions) for i in range(0, 2**length) ] self.node_count = 0 for row in self.rows: self.node_count += len(row.nodes) # Make each subrow aware of all other subrows print("\n") with concurrent.futures.ThreadPoolExecutor() as executor: for top in self.rows: print( f"Mapping sub rows... {(top.seed / 2**self.length)*100:.2f}%", end="\r", ) for bottom in self.rows: if not top.forms_pool( bottom) and top.is_trivially_contiguous(bottom): executor.submit(r.build_tree, top, bottom).result() print("Sub row mapping complete!" + " " * 60 + "\n") # There's almost no reason to multithread this. It's already instantaneous. if self.fast_count: self.count_patterns_memoized() else: path = Path.cwd() / "debug" if not path.exists(): path.mkdir() with open(f"debug\\debug_[{self.depth}x{self.length}].txt", "w") as file: file.write( f"Puzzle Debug: Size: [{self.depth} x {self.length}]\n") file.write( f"Total Possible Pattern Count: {self.total_pattern_count}\n" ) file.write( f"Total Legal Patterns: Execution must be allowed to finish...\n" ) self.count_patterns() sys.stdout.write("\rCounting Complete!" + " " * 80 + "\n") print( f"\nThere are {self.good_patterns:,} legal patterns in a [{self.depth} x {self.length}] nurikabe game. There were {self.total_pattern_count:,} possible patterns.\n" ) print( f"{self.good_patterns / self.total_pattern_count:.{self.length - 2}%} were good patterns.\n" ) print(f"Nodes traversed: {self.rows[0].nodes[0].recursion_calls}\n")
def setUp(self): r = [None for x in range(7)] r[0] = balance.Row( "100", "1970-01-01", "incoming comment") # noqa r[1] = balance.Row("-100", "1970-01-02", "outgoing comment") r[2] = balance.Row( "10", "1970-01-03", "a !bangtag") # noqa r[3] = balance.Row( "100", "1970-01-04", "a #hashtag") # noqa r[4] = balance.Row( "100", "1972-02-29", "!months:-1:5") # noqa r[5] = balance.Row( "100", "1972-01-31", "!months:4") # noqa r[6] = balance.Row( "100", "1970-01-05", "!months:3") # noqa self.rows = r
def test_empty_init(self): "Test the default Row creation" # 1. Create default Row object myobj = row.Row() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.tiles, '') # 3. Check methods self.assertEqual(myobj.count_safe(), 0)
def test_ten_init(self): "Test the Row object creation from text with ten tiles" # 1. Create Row object from text myobj = row.Row(text=EXAMPLE_TEN) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 10) self.assertEqual(myobj.tiles, ":.^^.^.^^^^:") # 3. Check methods self.assertEqual(myobj.count_safe(), 3) self.assertEqual(myobj.next_tiles(), ':^^^...^..^:')
def deserialize_workbook(jsonData): try: decoded = json.loads(jsonData) workbook_name = decoded['workbook_name'] worksheets = [] for ws in decoded['worksheets']: worksheet_name = ws['worksheet_name'] rows = [] for jsonrow in ws['rows']: row_number = jsonrow['row_number'] cells = [] for cl in jsonrow['cells']: column_number = cl['column_number'] cellcontent_type = cl['cell_content']['cell_type'] value = None c_formula = None print('cell_type : ' + str(cellcontent_type)) if cellcontent_type is cell.CellContent.CELL_TYPE_VALUE: value = cl['cell_content']['value'] elif cellcontent_type is cell.CellContent.CELL_TYPE_FORMULA: formula_type = cl['cell_content']['formula']['type'] operands = [] for operand in cl['cell_content']['formula'][ 'operands']: operands.append(operand) c_formula = get_fomula_object(formula_type, operands) else: #REMOVE print('invalid content type') pass cell_content = cell.CellContent(value, c_formula) c_cell = cell.Cell(column_number, cell_content) cells.append(c_cell) c_row = row.Row(row_number, cells) rows.append(c_row) c_worksheet = worksheet.Worksheet(worksheet_name, rows) worksheets.append(c_worksheet) wb = workbook.Workbook(workbook_name, worksheets) return wb except (ValueError, KeyError, TypeError) as e: print(e) print("JSON format error")
def test_autosplit(self): self.assertEqual(self.rows[0].autosplit(), [self.rows[0]]) # showing we can have a leap day if it is the original row date self.assertEqual(self.rows[4].autosplit(), [ balance.Row("20", "1972-01-29", "!months:-1:5 !child"), balance.Row("20", "1972-02-29", "!months:-1:5 !child"), balance.Row("20", "1972-03-29", "!months:-1:5 !child"), balance.Row("20", "1972-04-29", "!months:-1:5 !child"), balance.Row("20", "1972-05-29", "!months:-1:5 !child"), ]) # showing the end of month clamping to different values self.assertEqual(self.rows[5].autosplit(), [ balance.Row("25", "1972-01-31", "!months:4 !child"), balance.Row("25", "1972-02-29", "!months:4 !child"), balance.Row("25", "1972-03-31", "!months:4 !child"), balance.Row("25", "1972-04-30", "!months:4 !child"), ]) # showing the rounding and kept remainder self.assertEqual(self.rows[6].autosplit(), [ balance.Row("34", "1970-01-05", "!months:3 !child"), balance.Row("33", "1970-02-05", "!months:3 !child"), balance.Row("33", "1970-03-05", "!months:3 !child"), ])
import json import JSONDeserializer import cell import worksheet import workbook import row sumFor = cell.SumFormula([5, 6]) cellCon = cell.CellContent(formula=sumFor) lsumcell = cell.Cell('A', cellCon) mulFor = cell.MultiplyFormula([2 * 1]) mulCellCon = cell.CellContent(formula=mulFor) lmulcell = cell.Cell('A', mulCellCon) row_1 = row.Row('1', [lsumcell, lmulcell]) sumForr2 = cell.SumFormula([5, 6]) cellConr2 = cell.CellContent(formula=sumForr2) lsumcellr2 = cell.Cell('A', cellConr2) mulForr2 = cell.MultiplyFormula([2 * 1]) mulCellConr2 = cell.CellContent(formula=mulForr2) lmulcellr2 = cell.Cell('A', mulCellConr2) row_2 = row.Row('2', [lsumcellr2, lmulcellr2]) worksheet1 = worksheet.Worksheet('somedata', [row_1, row_2]) sumFor3 = cell.SumFormula([5, 6]) cellCon3 = cell.CellContent(formula=sumFor3)
def __create_and_append_new_row_to_list(self): new_row_to_be_appended = row.Row(self._next_row_number) self.rows_list.add_to_list(new_row_to_be_appended, new_row_to_be_appended.row_number) self._next_row_number += 1 self.worksheet_to_process.rows.append(new_row_to_be_appended) return new_row_to_be_appended
def makeGuess(self, guessCode): self.__tries += 1 self.__board.addRow(row.Row(guessCode, self.getResult(guessCode)))
""" Created on Fri Sep 6 13:53:17 2019 @author: rosto """ import sys sys.path.append("..") import form import builder import row import container import column from size import Size cont = container.Container() riga = row.Row() colonna_form = column.Column() colonna_form.add_col_size(12, Size.PICCOLO) colonna_form.add_col_size(6, Size.MEDIO) riga.add_child(colonna_form) cont.add_child(riga) f = form.Form(action_url="/login") f.add_child( form.InputField("id_nome", label="Nome", inp_type=form.InputType.TEXT)) f.add_child( form.InputField("id_cognome", label="Email", inp_type=form.InputType.EMAIL)) f.add_child(