11package org .janelia .saalfeldlab .n5 ;
22
3+ import static org .junit .Assert .assertArrayEquals ;
34import static org .junit .Assert .assertEquals ;
5+ import static org .junit .Assert .assertFalse ;
46import static org .junit .Assert .assertThrows ;
57import static org .junit .Assert .assertTrue ;
68
@@ -82,6 +84,39 @@ private static DatasetAttributes shardDatasetAttributes(
8284 return new DatasetAttributes (dimensions , shardSize , dataType , blockCodecInfo );
8385 }
8486
87+ @ Test
88+ public void builderTests () {
89+
90+ final long [] dims = new long []{100 , 200 , 300 };
91+ final int [] blk = new int []{32 , 32 , 32 };
92+
93+ // default blockSize uses defaultBlockSize, not full dimensions
94+ final DatasetAttributes defaultBlk = DatasetAttributes .builder (dims , DataType .FLOAT32 ).build ();
95+ assertArrayEquals (DatasetAttributes .defaultBlockSize (dims ), defaultBlk .getBlockSize ());
96+
97+ // blockSize is reflected in output
98+ final DatasetAttributes withBlk = DatasetAttributes .builder (dims , DataType .FLOAT32 )
99+ .blockSize (blk ).build ();
100+ assertArrayEquals (blk , withBlk .getBlockSize ());
101+ assertFalse (withBlk .isSharded ());
102+
103+ // compression sets a data codec; RawCompression is a no-op
104+ final DatasetAttributes withGzip = DatasetAttributes .builder (dims , DataType .FLOAT32 )
105+ .blockSize (blk ).compression (new GzipCompression ()).build ();
106+ assertEquals (1 , withGzip .getDataCodecInfos ().length );
107+
108+ final DatasetAttributes withRaw = DatasetAttributes .builder (dims , DataType .FLOAT32 )
109+ .blockSize (blk ).compression (new RawCompression ()).build ();
110+ assertEquals (0 , withRaw .getDataCodecInfos ().length );
111+
112+ // round-trip through Builder(DatasetAttributes)
113+ final DatasetAttributes roundTrip = DatasetAttributes .builder (withGzip ).build ();
114+ assertArrayEquals (withGzip .getDimensions (), roundTrip .getDimensions ());
115+ assertArrayEquals (withGzip .getBlockSize (), roundTrip .getBlockSize ());
116+ assertEquals (withGzip .getDataType (), roundTrip .getDataType ());
117+ assertEquals (withGzip .getDataCodecInfos ().length , roundTrip .getDataCodecInfos ().length );
118+ }
119+
85120 /**
86121 * Test that validateBlockShardSizes method rejects invalid shard and block size combinations.
87122 */
@@ -91,7 +126,7 @@ public void testValidateBlockShardSizesInvalid() {
91126 final long [] dimensions = new long []{100 , 200 , 300 };
92127 final DataType dataType = DataType .UINT8 ;
93128
94- // Block size too small
129+ // Block size too smallcompression != null && !(compression instanceof RawCompression)
95130 IllegalArgumentException ex0 = assertThrows (
96131 IllegalArgumentException .class ,
97132 () -> shardDatasetAttributes (dimensions , new int []{1 , 1 , 1 }, new int []{1 , 0 , -1 }, dataType ));
0 commit comments