<commit_before>/*
 * Copyright 2013 <NAME> 
 */
package com.gnahraf.io.store.ks;


import static org.junit.Assert.*;
import static com.gnahraf.test.TestHelper.method;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

import org.apache.log4j.Logger;
import org.junit.Test;

import com.gnahraf.io.store.ks.Keystone;
import com.gnahraf.io.store.ks.KeystoneImpl;
import com.gnahraf.test.TestDirs;


/**
 * 
 * @author Babak
 */
public class KeystoneImplTest {

  private final Logger log;

  private final File testDir;


  public KeystoneImplTest() {
    testDir = TestDirs.getTestDir(getClass());
    log = Logger.getLogger(getClass());
  }


  @Test
  public void testBadArgs() {
    verifyCreateKeystoneFails("testBadArgs", -1, 0);
  }


  @Test
  public void testBadArgs2() throws IOException {
    String filename = method(new Object() { });
    createKeystone(filename, 0, 0);
    verifyLoadKeystoneFails(filename, 5);
  }


  @Test
  public void testRoundtrip() throws IOException {
    String filename = method(new Object() { });
    long initValue = 5;
    Keystone keystone = createKeystone(filename, 0, initValue);
    assertEquals(initValue, keystone.get());
  }


  @Test
  public void testRoundtrip2() throws IOException {
    String filename = method(new Object() { });
    long initValue = 5;
    createKeystone(filename, 0, initValue);
    Keystone keystone = loadKeystone(filename, 0);
    assertEquals(initValue, keystone.get());
  }


  @Test
  public void testRoundtrip3() throws IOException {
    String filename = method(new Object() { });
    long value = 5;
    Keystone keystone = createKeystone(filename, 0, value);
    value = -9;
    keystone.set(value);
    keystone = loadKeystone(filename, 0);
    assertEquals(value, keystone.get());

  }


  @Test
  public void testRoundtrip4() throws IOException {
    String filename = method(new Object() { });
    long value = 5;
    Keystone keystone = createKeystone(filename, 0, value);
    value = -9;
    keystone.set(value);
    value = 11;
    keystone.set(value);
    keystone = loadKeystone(filename, 0);
    assertEquals(value, keystone.get());
  }


  @Test
  public void testIncrement() throws IOException {
    String filename = method(new Object() { });
    long value = 5;
    Keystone keystone = createKeystone(filename, 0, value);
    assertEquals(value, keystone.get());

    long incr = 10;
    value += incr;
    assertEquals(value, keystone.increment(incr));
    assertEquals(value, keystone.get());

    keystone = loadKeystone(filename, 0);
    assertEquals(value, keystone.get());
  }

<commit_msg>added test to KeystoneImplTest to get started<commit_after>/*
 * Copyright 2013 <NAME> 
 */
package com.gnahraf.io.store.ks;


import static org.junit.Assert.*;
import static com.gnahraf.test.TestHelper.method;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

import org.apache.log4j.Logger;
import org.junit.Test;

import com.gnahraf.io.store.ks.Keystone;
import com.gnahraf.io.store.ks.KeystoneImpl;
import com.gnahraf.test.TestDirs;


/**
 * 
 * @author Babak
 */
public class KeystoneImplTest {

  private final Logger log;

  private final File testDir;


  public KeystoneImplTest() {
    testDir = TestDirs.getTestDir(getClass());
    log = Logger.getLogger(getClass());
  }


  @Test
  public void testBadArgs() {
    verifyCreateKeystoneFails("testBadArgs", -1, 0);
  }


  @Test
  public void testBadArgs2() throws IOException {
    String filename = method(new Object() { });
    createKeystone(filename, 0, 0);
    verifyLoadKeystoneFails(filename, 5);
  }


  @Test
  public void testRoundtrip() throws IOException {
    String filename = method(new Object() { });
    long initValue = 5;
    Keystone keystone = createKeystone(filename, 0, initValue);
    assertEquals(initValue, keystone.get());
  }


  @Test
  public void testRoundtrip2() throws IOException {
    String filename = method(new Object() { });
    long initValue = 5;
    createKeystone(filename, 0, initValue);
    Keystone keystone = loadKeystone(filename, 0);
    assertEquals(initValue, keystone.get());
  }


  @Test
  public void testRoundtrip3() throws IOException {
    String filename = method(new Object() { });
    long value = 5;
    Keystone keystone = createKeystone(filename, 0, value);
    value = -9;
    keystone.set(value);
    keystone = loadKeystone(filename, 0);
    assertEquals(value, keystone.get());

  }


  @Test
  public void testRoundtrip4() throws IOException {
    String filename = method(new Object() { });
    long value = 5;
    Keystone keystone = createKeystone(filename, 0, value);
    value = -9;
    keystone.set(value);
    value = 11;
    keystone.set(value);
    keystone = loadKeystone(filename, 0);
    assertEquals(value, keystone.get());
  }

	@Test
	public void testOldValue() throws IOException {
		String filename = method(new Object() { });
		long oldvalue = 5;
		Keystone keystone = createKeystone(filename, 0, oldvalue);
		long newvalue = -9;
		assertEquals(oldvalue, keystone.set(newvalue));
	}


  @Test
  public void testIncrement() throws IOException {
    String filename = method(new Object() { });
    long value = 5;
    Keystone keystone = createKeystone(filename, 0, value);
    assertEquals(value, keystone.get());

    long incr = 10;
    value += incr;
    assertEquals(value, keystone.increment(incr));
    assertEquals(value, keystone.get());

    keystone = loadKeystone(filename, 0);
    assertEquals(value, keystone.get());
  }


{'fraction_non_alphanumeric': 0.12299750800996796, 'fraction_numerical': 0.012637949448202207, 'mean_word_length': 3.698160535117057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4890726', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1722, 'n_words': 433}