### Question:
Segments { long segmentId(long timestamp) { return timestamp / segmentInterval; } Segments(final String name, final long retentionPeriod, final int numSegments); void close();  }### Answer:
@Test public void shouldGetSegmentIdsFromTimestamp() throws Exception { assertEquals(0, segments.segmentId(0)); assertEquals(1, segments.segmentId(60000)); assertEquals(2, segments.segmentId(120000)); assertEquals(3, segments.segmentId(180000)); }
@Test public void shouldBaseSegmentIntervalOnRetentionAndNumSegments() throws Exception { final Segments segments = new Segments("test", 8 * 60 * 1000, 5); assertEquals(0, segments.segmentId(0)); assertEquals(0, segments.segmentId(60000)); assertEquals(1, segments.segmentId(120000)); }