<commit_before>package lua.value;

import junit.framework.TestCase;

public class LTableTest extends TestCase {
	
	public void testInOrderIntegerKeyInsertion() {
		LTable t = new LTable();
		
		for ( int i = 1; i <= 32; ++i ) {
			t.put( i, new LString( "Test Value! "+i ) );
		}
		
		// Ensure capacities make sense
		assertEquals( 0, t.getHashCapacity() );
		
		assertTrue( t.getArrayCapacity() >= 32 );
		assertTrue( t.getArrayCapacity() <= 64 );
		
		// Ensure all keys are still there.
		for ( int i = 1; i <= 32; ++i ) {
			assertEquals( "Test Value! " + i, t.get( i ).luaAsString() );
		}
	}
	
	public void testOutOfOrderIntegerKeyInsertion() {
		LTable t = new LTable();
		
		for ( int i = 32; i > 0; --i ) {
			t.put( i, new LString( "Test Value! "+i ) );
		}
		
		// Ensure capacities make sense
		assertEquals( 0, t.getHashCapacity() );
		
		assertTrue( t.getArrayCapacity() >= 32 );
		assertTrue( t.getArrayCapacity() <= 64 );
		
		// Ensure all keys are still there.
		for ( int i = 1; i <= 32; ++i ) {
			assertEquals( "Test Value! " + i, t.get( i ).luaAsString() );
		}
	}
	
	public void testStringAndIntegerKeys() {
		LTable t = new LTable();
		
		for ( int i = 0; i < 10; ++i ) {
			LString str = new LString( String.valueOf( i ) );
			t.put( i, str );
			t.put( str, new LInteger( i ) );
		}
		
		assertTrue( t.getArrayCapacity() >= 9 ); // 1, 2, ..., 9
		assertTrue( t.getArrayCapacity() <= 18 );
		assertTrue( t.getHashCapacity() >= 11 ); // 0, "0", "1", ..., "9"
		assertTrue( t.getHashCapacity() <= 33 );
		
		LValue[] keys = t.getKeys();
		
		int intKeys = 0;
		int stringKeys = 0;
		
		assertEquals( 20, keys.length );
		for ( int i = 0; i < keys.length; ++i ) {
			LValue k = keys[i];
			
			if ( k instanceof LInteger ) {
				final int ik = k.luaAsInt();
				assertTrue( ik >= 0 && ik < 10 );
				final int mask = 1 << ik;
				assertTrue( ( intKeys & mask ) == 0 );
				intKeys |= mask;
			} else if ( k instanceof LString ) {
				final int ik = Integer.parseInt( k.luaAsString().toJavaString() );
				assertEquals( String.valueOf( ik ), k.luaAsString() );
				assertTrue( ik >= 0 && ik < 10 );
				final int mask = 1 << ik;
				assertTrue( "Key \""+ik+"\" found more than once", ( stringKeys & mask ) == 0 );
				stringKeys |= mask;
			} else {
				fail( "Unexpected type of key found" );
			}<commit_msg>Fix broken LTable test case.<commit_after>package lua.value;

import junit.framework.TestCase;

public class LTableTest extends TestCase {
	
	public void testInOrderIntegerKeyInsertion() {
		LTable t = new LTable();
		
		for ( int i = 1; i <= 32; ++i ) {
			t.put( i, new LString( "Test Value! "+i ) );
		}
		
		// Ensure capacities make sense
		assertEquals( 0, t.getHashCapacity() );
		
		assertTrue( t.getArrayCapacity() >= 32 );
		assertTrue( t.getArrayCapacity() <= 64 );
		
		// Ensure all keys are still there.
		for ( int i = 1; i <= 32; ++i ) {
			assertEquals( "Test Value! " + i, t.get( i ).luaAsString().toJavaString() );
		}
	}
	
	public void testOutOfOrderIntegerKeyInsertion() {
		LTable t = new LTable();
		
		for ( int i = 32; i > 0; --i ) {
			t.put( i, new LString( "Test Value! "+i ) );
		}
		
		// Ensure capacities make sense
		assertEquals( 0, t.getHashCapacity() );
		
		assertTrue( t.getArrayCapacity() >= 32 );
		assertTrue( t.getArrayCapacity() <= 64 );
		
		// Ensure all keys are still there.
		for ( int i = 1; i <= 32; ++i ) {
			assertEquals( "Test Value! " + i, t.get( i ).luaAsString() );
		}
	}
	
	public void testStringAndIntegerKeys() {
		LTable t = new LTable();
		
		for ( int i = 0; i < 10; ++i ) {
			LString str = new LString( String.valueOf( i ) );
			t.put( i, str );
			t.put( str, new LInteger( i ) );
		}
		
		assertTrue( t.getArrayCapacity() >= 9 ); // 1, 2, ..., 9
		assertTrue( t.getArrayCapacity() <= 18 );
		assertTrue( t.getHashCapacity() >= 11 ); // 0, "0", "1", ..., "9"
		assertTrue( t.getHashCapacity() <= 33 );
		
		LValue[] keys = t.getKeys();
		
		int intKeys = 0;
		int stringKeys = 0;
		
		assertEquals( 20, keys.length );
		for ( int i = 0; i < keys.length; ++i ) {
			LValue k = keys[i];
			
			if ( k instanceof LInteger ) {
				final int ik = k.luaAsInt();
				assertTrue( ik >= 0 && ik < 10 );
				final int mask = 1 << ik;
				assertTrue( ( intKeys & mask ) == 0 );
				intKeys |= mask;
			} else if ( k instanceof LString ) {
				final int ik = Integer.parseInt( k.luaAsString().toJavaString() );
				assertEquals( String.valueOf( ik ), k.luaAsString().toJavaString() );
				assertTrue( ik >= 0 && ik < 10 );
				final int mask = 1 << ik;
				assertTrue( "Key \""+ik+"\" found more than once", ( stringKeys & mask ) == 0 );
				stringKeys |= mask;
			} else {
				fail( "Unexpected type of key found" );
			}
{'fraction_non_alphanumeric': 0.16840093438097262, 'fraction_numerical': 0.02293480569122956, 'mean_word_length': 2.6455108359133126, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5987657', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1600, 'n_words': 510}