from research import *
s=begin(1351,'Verify the printed Moses block table','Does every displayed block match the source path?',{},['draft/05a_Moses_blocks.md','model/Moses_five_source_blocks.json'])
t=(ROOT/'draft/05a_Moses_blocks.md').read_text();rows=[]
for line in t.splitlines():
 cells=[x.strip() for x in line.split('|')[1:-1]]
 if len(cells)==4 and cells[1].isdigit():
  rows.append({'segment':cells[0],'exact':int(cells[1]),'rounded':int(cells[2]),'residual':int(cells[3].replace('−','-'))})
d=json.loads((ROOT/'model/Moses_five_source_blocks.json').read_text())
a=artifact('model/main_Moses_table_check.json',json.dumps(rows,indent=2)+'\n')
finish(s,{'check':a},'All five block sums match the complete source path and all residuals have the right sign. The accumulated six is preserved rather than normalized to a single rounding cell.','Verify the four inverse word rows and their domain statement.',{'five':len(rows)==5,'rounded':[x['rounded'] for x in rows]==[x['span'] for x in d['blocks']],'residuals':all(x['exact']-x['rounded']==x['residual'] for x in rows),'totals':sum(x['rounded'] for x in rows)==2580 and sum(x['residual'] for x in rows)==6})
