@@ -10,6 +10,8 @@ public class LongDivisionTests {
1010 static string CellText ( MathList cell ) => cell . Count == 0 ? "" : cell [ 0 ] switch {
1111 Number number => number . Nucleus ,
1212 Underline underline => CellText ( underline . InnerList ) ,
13+ Overline overline => CellText ( overline . InnerList ) ,
14+ Inner inner => CellText ( inner . InnerList ) ,
1315 _ => cell . DebugString
1416 } ;
1517 static LongDivision Parse ( string source ) {
@@ -101,19 +103,43 @@ public void LayoutHasBracketRuleAndOneFinalRemainder() {
101103 var layout = ( Table ) typeof ( LongDivision ) . GetMethod ( "CreateLayout" , BindingFlags . Instance | BindingFlags . NonPublic ) ! . Invoke ( atom , null ) ! ;
102104 var dividend = layout . Cells [ 1 ] [ 1 ] ;
103105 var inner = Assert . IsType < Inner > ( dividend [ 0 ] ) ;
104- Assert . Equal ( "⟌" , inner . LeftBoundary . Nucleus ) ;
105- Assert . IsType < Underline > ( inner . InnerList [ 0 ] ) ;
106+ Assert . Equal ( ")" , inner . LeftBoundary . Nucleus ) ;
107+ Assert . Equal ( Boundary . Empty , inner . RightBoundary ) ;
108+ Assert . IsType < Overline > ( inner . InnerList [ 0 ] ) ;
106109 Assert . Equal ( "949" , CellText ( layout . Cells [ 0 ] [ 1 ] ) ) ;
110+ Assert . Equal ( ColumnAlignment . Right , layout . GetAlignment ( 1 ) ) ;
107111 Assert . Equal ( 1 , layout . Cells . Count ( row => row . Any ( cell => CellText ( cell ) == atom . Remainder ) ) ) ;
108112 }
109113
114+ [ Fact ]
115+ public void LayoutPreservesProductPlaceValuesAndRunningTotals ( ) {
116+ var atom = new LongDivision ( "12345" , "13" ) ;
117+ var layout = ( Table ) typeof ( LongDivision ) . GetMethod ( "CreateLayout" , BindingFlags . Instance | BindingFlags . NonPublic ) ! . Invoke ( atom , null ) ! ;
118+ Assert . Equal ( new [ ] { "949" , "12345" , "11700" , "645" , "520" , "125" , "117" , "8" } ,
119+ layout . Cells . Select ( row => CellText ( row [ 1 ] ) ) ) ;
120+ }
121+
110122 [ Fact ]
111123 public void LayoutRetainsInternalZeroStepsWithoutRowsForZeroProducts ( ) {
112124 var atom = new LongDivision ( "1005" , "5" ) ;
113125 Assert . Contains ( atom . Steps , step => step . QuotientDigit == 0 ) ;
114126 var layout = ( Table ) typeof ( LongDivision ) . GetMethod ( "CreateLayout" , BindingFlags . Instance | BindingFlags . NonPublic ) ! . Invoke ( atom , null ) ! ;
115127 Assert . Equal ( "201" , CellText ( layout . Cells [ 0 ] [ 1 ] ) ) ;
128+ Assert . Equal ( new [ ] { "201" , "1005" , "1000" , "5" , "5" , "0" } ,
129+ layout . Cells . Select ( row => CellText ( row [ 1 ] ) ) ) ;
116130 Assert . Equal ( 1 , layout . Cells . Skip ( 2 ) . Count ( row => row . Any ( cell => CellText ( cell ) == "0" ) ) ) ;
117131 }
132+
133+ [ Theory ]
134+ [ InlineData ( "81" , "3" , new [ ] { "27" , "81" , "60" , "21" , "21" , "0" } ) ]
135+ [ InlineData ( "3" , "5" , new [ ] { "0" , "3" , "3" } ) ]
136+ [ InlineData ( "0" , "7" , new [ ] { "0" , "0" , "0" } ) ]
137+ [ InlineData ( "86491" , "94" , new [ ] { "920" , "86491" , "84600" , "1891" , "1880" , "11" } ) ]
138+ public void LayoutShowsExactlyOneFinalRemainder ( string numerator , string denominator , string [ ] expected ) {
139+ var atom = new LongDivision ( numerator , denominator ) ;
140+ var layout = ( Table ) typeof ( LongDivision ) . GetMethod ( "CreateLayout" , BindingFlags . Instance | BindingFlags . NonPublic ) ! . Invoke ( atom , null ) ! ;
141+ Assert . Equal ( expected , layout . Cells . Select ( row => CellText ( row [ 1 ] ) ) ) ;
142+ Assert . Equal ( atom . Remainder , CellText ( layout . Cells . Last ( ) [ 1 ] ) ) ;
143+ }
118144 }
119145}
0 commit comments