All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.it.unimi.dsi.util.ByteBufferLongBigListTest Maven / Gradle / Ivy

Go to download

The DSI utilities are a mishmash of classes accumulated during the last twenty years in projects developed at the DSI (Dipartimento di Scienze dell'Informazione, i.e., Information Sciences Department), now DI (Dipartimento di Informatica, i.e., Informatics Department), of the Universita` degli Studi di Milano.

There is a newer version: 2.7.3
Show newest version
package it.unimi.dsi.util;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel.MapMode;

import org.junit.Test;

import it.unimi.dsi.fastutil.io.BinIO;
import it.unimi.dsi.fastutil.longs.LongIterators;

public class ByteBufferLongBigListTest {

	@Test
	public void testSetGetSmall() {
		final ByteBufferLongBigList b = new ByteBufferLongBigList(ByteBuffer.allocate(1000));
		b.set(0, 10);
		assertEquals(10, b.getLong(0));
	}

	@Test
	public void testSetGetBig() throws IOException {
		final File f = File.createTempFile(ByteBufferLongBigListTest.class.getSimpleName(), "buffer");
		f.deleteOnExit();
		BinIO.storeLongs(LongIterators.fromTo(0, 200000000), f);
		final RandomAccessFile c = new RandomAccessFile(f.toString(), "rw");
		final ByteBufferLongBigList b = ByteBufferLongBigList.map(c.getChannel(), ByteOrder.BIG_ENDIAN, MapMode.READ_WRITE);
		b.set(1, 10);
		assertEquals(10, b.getLong(1));
		b.set(190000000, 10);
		assertEquals(10, b.getLong(190000000));
		c.close();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy