<commit_before>package edu.ucdenver.ccp.parser.ncbi.gene;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.text.ParseException;
import java.util.Iterator;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class GenerifsBasicFileParserTest {

	@Rule
	public TemporaryFolder folder = new TemporaryFolder();

	private File generifsBasicFile;
	private File generifsBasicFileWithInvalidDateFormat;

	@Before
	public void setUp() throws Exception {
		populateSampleGenerifsBasicFile();
		populateSampleGenerifsBasicFileWithInvalidDateFormat();
	}

	private void populateSampleGenerifsBasicFileWithInvalidDateFormat() throws IOException {
		generifsBasicFileWithInvalidDateFormat = folder.newFile("generifs_basic_with_invalid_date");
		PrintStream ps = new PrintStream(generifsBasicFileWithInvalidDateFormat);
		ps.println("#Tax ID\tGene ID\tPubMed ID (PMID) list\tlast update timestamp\tGeneRIF text");
		ps.println("9606\t7040\t12858451,1234567\t03-13-2008 \tObservational study of gene-disease.");
		ps.close();
	}

	private void populateSampleGenerifsBasicFile() throws IOException {
		generifsBasicFile = folder.newFile("generifs_basic");
		PrintStream ps = new PrintStream(generifsBasicFile);
		ps.println("#Tax ID\tGene ID\tPubMed ID (PMID) list\tlast update timestamp\tGeneRIF text");
		ps
				.println("34\t4126706\t16689796\t2010-01-21 00:00\tData demonstrate that MrpC binds to at least eight sites in the upstream region of its promoter, and suggest a mechanism by which MrpC and FruA are regulated during the M. xanthus life cycle [MrpC]");
		ps
				.println("9606\t7040\t12858451,1234567\t2008-03-13 08:51\tObservational study of gene-disease association. (HuGE Navigator)");
		ps.close();
	}

	private GeneRIF getExpectedGeneRif1() throws ParseException {
		return new GeneRIF(
				34,
				4126706,
				new int[] { 16689796 },
				GenerifsBasicFileParser.getGeneRifDateFormat().parse("2010-01-21 00:00"),
				"Data demonstrate that MrpC binds to at least eight sites in the upstream region of its promoter, and suggest a mechanism by which MrpC and FruA are regulated during the M. xanthus life cycle [MrpC]");
	}

	private GeneRIF getExpectedGeneRif2() throws ParseException {
		return new GeneRIF(9606, 7040, new int[] { 12858451, 1234567 }, GenerifsBasicFileParser.getGeneRifDateFormat()
				.parse("2008-03-13 08:51"), "Observational study of gene-disease association. (HuGE Navigator)");
	}

	@Test
	public void testParse() throws Exception {
		Iterator<GeneRIF> generifIter = GenerifsBasicFileParser.parse(generifsBasicFile);<commit_msg>Organized imports, broke up some strings so they fit within the margins.<commit_after>package edu.ucdenver.ccp.parser.ncbi.gene;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.text.ParseException;
import java.util.Iterator;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class GenerifsBasicFileParserTest {

	@Rule
	public TemporaryFolder folder = new TemporaryFolder();

	private File generifsBasicFile;
	private File generifsBasicFileWithInvalidDateFormat;

	@Before
	public void setUp() throws Exception {
		populateSampleGenerifsBasicFile();
		populateSampleGenerifsBasicFileWithInvalidDateFormat();
	}

	private void populateSampleGenerifsBasicFileWithInvalidDateFormat() throws IOException {
		generifsBasicFileWithInvalidDateFormat = folder.newFile("generifs_basic_with_invalid_date");
		PrintStream ps = new PrintStream(generifsBasicFileWithInvalidDateFormat);
		ps.println("#Tax ID\tGene ID\tPubMed ID (PMID) list\tlast update timestamp\tGeneRIF text");
		ps.println("9606\t7040\t12858451,1234567\t03-13-2008 \tObservational study of gene-disease.");
		ps.close();
	}

	private void populateSampleGenerifsBasicFile() throws IOException {
		generifsBasicFile = folder.newFile("generifs_basic");
		PrintStream ps = new PrintStream(generifsBasicFile);
		ps.println("#Tax ID\tGene ID\tPubMed ID (PMID) list\tlast update timestamp\tGeneRIF text");
		ps.println("34\t4126706\t16689796\t2010-01-21 00:00\tData demonstrate that MrpC binds to "
				+ "at least eight sites in the upstream region of its promoter, and suggest a mechanism "
				+ "by which MrpC and FruA are regulated during the M. xanthus life cycle [MrpC]");
		ps.println("9606\t7040\t12858451,1234567\t2008-03-13 08:51\tObservational study of gene-disease "
				+ "association. (HuGE Navigator)");
		ps.close();
	}

	private GeneRIF getExpectedGeneRif1() throws ParseException {
		return new GeneRIF(34, 4126706, new int[] { 16689796 }, GenerifsBasicFileParser.getGeneRifDateFormat().parse(
				"2010-01-21 00:00"),
				"Data demonstrate that MrpC binds to at least eight sites in the upstream region of its "
						+ "promoter, and suggest a mechanism by which MrpC and FruA are regulated during the M. "
						+ "xanthus life cycle [MrpC]");
	}

	private GeneRIF getExpectedGeneRif2() throws ParseException {
		return new GeneRIF(9606, 7040, new int[] { 12858451, 1234567 }, GenerifsBasicFileParser.getGeneRifDateFormat()
				.parse("2008-03-13 08:51"), "Observational study of gene-disease association. (HuGE Navigator)");
	}

	@Test
	public void testParse() throws Exception {
		Iterator<GeneRIF> generifIter = GenerifsBasicFileParser.parse(generifsBasicFile);
{'fraction_non_alphanumeric': 0.09417199715707178, 'fraction_numerical': 0.05721393034825871, 'mean_word_length': 5.462686567164179, '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': '4334411', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1728, 'n_words': 459}