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

test.it.unimi.dsi.big.util.FrontCodedStringBigListTest 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
/*
 * DSI utilities
 *
 * Copyright (C) 2010-2020 Sebastiano Vigna
 *
 *  This library is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as published by the Free
 *  Software Foundation; either version 3 of the License, or (at your option)
 *  any later version.
 *
 *  This library is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, see .
 *
 */

package it.unimi.dsi.big.util;

import static org.junit.Assert.assertEquals;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.SplittableRandom;

import org.junit.Ignore;
import org.junit.Test;

import it.unimi.dsi.lang.MutableString;

public class FrontCodedStringBigListTest {

	@Test
	public void testLargeSet() {
		final List c = Arrays.asList(TernaryIntervalSearchTreeTest.WORDS.clone());
		final MutableString s = new MutableString();
		for(int p = 0; p < 2; p++) {
			for(final boolean utf8: new boolean[] { false, true })
				for(int ratio = 1; ratio < 8; ratio++) {
					final FrontCodedStringBigList fcl = new FrontCodedStringBigList(c.iterator(), ratio, utf8);
					for (int i = 0; i < fcl.size64(); i++) {
						assertEquals(Integer.toString(i), c.get(i), fcl.get(i).toString());
						fcl.get(i, s);
						assertEquals(Integer.toString(i), c.get(i), s.toString());
					}
				}

			Collections.sort(c);
		}
	}

	@Test
	public void testSurrogatePairs() {
		final List c = Arrays.asList(new String[] { "a", "AB\uE000AB", "\uD800\uDF02", "\uD800\uDF03", "b" });
		for(final boolean utf8: new boolean[] { false, true })
			for(int ratio = 1; ratio < 8; ratio++) {
				final FrontCodedStringBigList fcl = new FrontCodedStringBigList(c.iterator(), ratio, utf8);
				for (int i = 0; i < fcl.size64(); i++) {
					assertEquals(Integer.toString(i), c.get(i), fcl.get(i).toString());
				}
			}
	}

	@Ignore("Needs a lot of memory")
	@Test
	public void testbig() {
		final long size = (1L << 31) + 10000;
		final FrontCodedStringBigList byteArrayFrontCodedBigList = new FrontCodedStringBigList(new Iterator() {
			SplittableRandom r = new SplittableRandom(0);
			long i = 0;

			@Override
			public boolean hasNext() {
				return i < size;
			}

			@Override
			public String next() {
				i++;
				return new String(new byte[] { (byte)r.nextLong() }, StandardCharsets.ISO_8859_1);
			}
		}, 10, true);
		SplittableRandom r = new SplittableRandom(0);
		for (long i = 0; i < size; i++) {
			assertEquals(new String(new byte[] { (byte)r.nextLong() }, StandardCharsets.ISO_8859_1), byteArrayFrontCodedBigList.get(i));
		}
		r = new SplittableRandom(0);
		final MutableString s = new MutableString();
		for (long i = 0; i < size; i++) {
			byteArrayFrontCodedBigList.get(i, s);
			assertEquals(new String(new byte[] { (byte)r.nextLong() }, StandardCharsets.ISO_8859_1), s);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy