Hi,
Just to make sure I have the precedence and so on right, I used a loaded
dice that always rolls it's number of sides to write some tests. Since
there's been some discussion over the precedence rules, I'll post them to
maybe compare with others and see if I'm on the right track. Hope that's
within the rules? I've left out broken input ones, since at the moment
mine just 'does it's best' but I might tighten that up yet...
@asserts = {
'1' => 1,
'1+2' => 3,
'1+3*4' => 13,
'1*2+4/8-1' => 1,
'd1' => 1,
'1d1' => 1,
'd10' => 10,
'1d10' => 10,
'10d10' => 100,
'd3*2' => 6,
'5d6d7' => 210, # left assoc
'2d3+8' => 14, # not 22
'(2d(3+8))' => 22, # not 14
'd3+d3' => 6,
'd2*2d4' => 16,
'd(2*2)+d4' => 8,
'd%' => 100,
'2d%' => 200,
'14+3*10d2' => 74,
'(5d5-4)d(16/d4)+3' => 87, #25d4 + 3
}
Cheers.