@@ -177,11 +177,32 @@ mod test {
177177 ]
178178 }
179179
180+ /// The declared shapes of each family — what a program's schema would pin (a variant carries
181+ /// only its tag, so a family with sums cannot be pinned from a row).
182+ fn shapes_of ( name : & str ) -> ( corgi:: Shape , corgi:: Shape ) {
183+ use corgi:: Shape :: { List , Prim , Prod , Sum } ;
184+ let u = || Prim ( 64 ) ;
185+ let pair = || Prod ( vec ! [ u( ) , u( ) ] ) ;
186+ match name {
187+ "scalars" => ( u ( ) , u ( ) ) ,
188+ "tuples" => ( pair ( ) , Prod ( vec ! [ u( ) ] ) ) ,
189+ "lists" => ( u ( ) , List ( Box :: new ( u ( ) ) ) ) ,
190+ "variants" => ( Sum ( vec ! [ u( ) , pair( ) ] ) , u ( ) ) ,
191+ "nested" => ( Prod ( vec ! [ u( ) , Sum ( vec![ u( ) , pair( ) ] ) ] ) , List ( Box :: new ( u ( ) ) ) ) ,
192+ other => panic ! ( "no shapes for family {other}" ) ,
193+ }
194+ }
195+
196+ fn container_of ( name : & str , updates : Vec < ( ( DValue , DValue ) , Time , Diff ) > ) -> CorgiContainer < Time , Diff > {
197+ let ( k, v) = shapes_of ( name) ;
198+ CorgiContainer :: from_updates ( updates, & k, & v)
199+ }
200+
180201 /// Every update survives the round trip, with its time and diff, for every shape family.
181202 #[ test]
182203 fn round_trip_preserves_updates ( ) {
183204 for ( name, updates) in shape_families ( ) {
184- let c = CorgiContainer :: < Time , Diff > :: from_updates ( updates. clone ( ) ) ;
205+ let c = container_of ( name , updates. clone ( ) ) ;
185206 let back = round_trip ( & c) ;
186207 assert_eq ! ( back. into_updates( ) , updates, "{name} did not survive the round trip" ) ;
187208 }
@@ -202,7 +223,7 @@ mod test {
202223 #[ test]
203224 fn round_trip_preserves_column_hashes ( ) {
204225 for ( name, updates) in shape_families ( ) {
205- let c = CorgiContainer :: < Time , Diff > :: from_updates ( updates) ;
226+ let c = container_of ( name , updates) ;
206227 let ( keys, vals) = ( c. keys . clone ( ) , c. vals . clone ( ) ) ;
207228 let back = round_trip ( & c) ;
208229 assert_eq ! ( corgi:: arrange:: hash_rows( & back. keys) , corgi:: arrange:: hash_rows( & keys) , "{name} keys" ) ;
@@ -218,7 +239,7 @@ mod test {
218239 let updates: Vec < _ > = ( 0 ..1000i64 )
219240 . map ( |i| ( ( DValue :: Int ( i) , DValue :: Int ( i * 2 ) ) , time ( 0 , & [ ] ) , 1 ) )
220241 . collect ( ) ;
221- let c = CorgiContainer :: < Time , Diff > :: from_updates ( updates) ;
242+ let c = CorgiContainer :: < Time , Diff > :: from_updates_pinned ( updates) ;
222243 assert_eq ! ( corgi:: bytes:: length_in_bytes( & c. keys) , 24 + 8 * 1000 ) ;
223244 assert_eq ! ( corgi:: bytes:: length_in_bytes( & c. vals) , 24 + 8 * 1000 ) ;
224245 }
0 commit comments