<commit_before>package org.marc4j;

import java.io.InputStream;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.marc4j.marc.ControlField;
import org.marc4j.marc.Record;
import org.marc4j.marc.VariableField;

public class RecordTest extends TestCase {

    Record record = null;

    public void setUp() throws Exception {
        InputStream input = getClass().getResourceAsStream(
                "resources/summerland.mrc");
        MarcStreamReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            record = reader.next();
        }
        input.close();
    }

    public void testGetFields() {
        String cn = record.getControlNumber();
        assertEquals("12883376", cn);

        ControlField cf = record.getControlNumberField();
        assertEquals("001", cf.getTag());
        assertEquals("12883376", cf.getData());

        List fieldList = record.getVariableFields();
        assertEquals(15, fieldList.size());

        fieldList = record.getControlFields();
        assertEquals(3, fieldList.size());

        fieldList = record.getDataFields();
        assertEquals(12, fieldList.size());

        VariableField field = record.getVariableField("245");
        assertEquals("245", field.getTag());

        fieldList = record.getVariableFields("650");
        assertEquals(3, fieldList.size());

        String[] fields = { "245", "260", "300" };
        fieldList = record.getVariableFields(fields);
        assertEquals(3, fieldList.size());
    }

    public void testFind() throws Exception {
        VariableField field = record.getVariableField("245");
        assertEquals(true, field.find("Summerland"));
        assertEquals(true, field.find("Sum*erland"));
        assertEquals(true, field.find("[Cc]habo[a-z]"));

        field = record.getVariableField("008");
        assertEquals(true, field.find("eng"));

        List result = record.find("Summerland");
        assertEquals(1, result.size());
        field = (VariableField) result.get(0);
        assertEquals("245", field.getTag());

        result = record.find("Chabon");
        assertEquals(2, result.size());

        result = record.find("100", "Chabon");
        assertEquals(1, result.size());

        String[] tags = { "100", "260", "300" };
        result = record.find(tags, "Chabon");
        assertEquals(1, result.size());
    }

    public void tearDown() {
        record = null;
    }

    public static Test suite() {
        return new TestSuite(RecordTest.class);
    }

    public static void main(String args[]) {
        TestRunner.run(suite());
    }
}<commit_msg>Added a create record test<commit_after>package org.marc4j;

import java.io.InputStream;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.marc4j.marc.ControlField;
import org.marc4j.marc.DataField;
import org.marc4j.marc.MarcFactory;
import org.marc4j.marc.Record;
import org.marc4j.marc.VariableField;

public class RecordTest extends TestCase {

    Record record = null;

    public void setUp() throws Exception {
        InputStream input = getClass().getResourceAsStream(
                "resources/summerland.mrc");
        MarcStreamReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            record = reader.next();
        }
        input.close();
    }

    public void testGetFields() {
        String cn = record.getControlNumber();
        assertEquals("12883376", cn);

        ControlField cf = record.getControlNumberField();
        assertEquals("001", cf.getTag());
        assertEquals("12883376", cf.getData());

        List fieldList = record.getVariableFields();
        assertEquals(15, fieldList.size());

        fieldList = record.getControlFields();
        assertEquals(3, fieldList.size());

        fieldList = record.getDataFields();
        assertEquals(12, fieldList.size());

        VariableField field = record.getVariableField("245");
        assertEquals("245", field.getTag());

        fieldList = record.getVariableFields("650");
        assertEquals(3, fieldList.size());

        String[] fields = { "245", "260", "300" };
        fieldList = record.getVariableFields(fields);
        assertEquals(3, fieldList.size());
    }

    public void testFind() throws Exception {
        VariableField field = record.getVariableField("245");
        assertEquals(true, field.find("Summerland"));
        assertEquals(true, field.find("Sum*erland"));
        assertEquals(true, field.find("[Cc]habo[a-z]"));

        field = record.getVariableField("008");
        assertEquals(true, field.find("eng"));

        List result = record.find("Summerland");
        assertEquals(1, result.size());
        field = (VariableField) result.get(0);
        assertEquals("245", field.getTag());

        result = record.find("Chabon");
        assertEquals(2, result.size());

        result = record.find("100", "Chabon");
        assertEquals(1, result.size());

        String[] tags = { "100", "260", "300" };
        result = record.find(tags, "Chabon");
        assertEquals(1, result.size());
        
        result = record.find("040", "DLC");
        assertTrue(result.size() > 0);
        
        DataField df = (DataField)result.get(0);
        String agency = df.getSubfield('a').getData();
        assertTrue(agency.matches("DLC"));
        
    }
    
    public void testCreateRecord() throws Exception {
        MarcFactory factory = MarcFactory.newInstance();
        Record record = factory.newRecord("00000cam a2200000 a 4500");
        assertEquals("00000cam a2200000 a 4500", record.getLeader().marshal());

        record.addVariableField(factory.newControlField("001", "12883376"));
        
        DataField df = factory.newDataField("245", '1', '0');
        df.addSubfield(factory.newSubfield('a', "Summerland /"));
        df.addSubfield(factory.newSubfield('c', "<NAME>."));
        record.addVariableField(df);
    }

    public void tearDown() {
        record = null;
    }

    public static Test suite() {
        return new TestSuite(RecordTest.class);
    }

    public static void main(String args[]) {
        TestRunner.run(suite());
    }
}
{'fraction_non_alphanumeric': 0.14010644959298685, 'fraction_numerical': 0.03177833437695679, 'mean_word_length': 2.853437876960193, 'pattern_counts': {'":': 0, '<': 4, '<?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': '3722860', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1765, 'n_words': 365}