<commit_before>package io.github.programminglife2016.pl1_2016.parser;

import io.github.programminglife2016.pl1_2016.parser.nodes.Node;
import io.github.programminglife2016.pl1_2016.parser.nodes.NodeCollection;
import io.github.programminglife2016.pl1_2016.parser.nodes.SegmentParser;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
//CHECKSTYLE.OFF: MagicNumber

/**
 * Tests for the BasicServer class
 */
public class SegmentParserTest {
    private SegmentParser parser;

    /**
     * Create parser object.
     */
    @Before
    public void setUp() {
        parser = new SegmentParser();
    }

    /**
     * Test parsing a segment line to produce the correct segment.
     */
    @Test
    public void testSegmentLine() {
        parser.parse(stringToInputStream("S	1	TTGA	*	ORI:Z:MT_H37RV_BRD_V5.ref.fasta;"));
        NodeCollection segmentMap = parser.getSegmentCollection();
        Node node = segmentMap.get(1);
        assertEquals(1, node.getId());
        assertEquals("TTGA", node.getData());
    }

    /**
     * Test parsing a link line to produce the correct links.
     */
    @Test
    public void testLinkLine() {
        final String gfaFile = "H	VN:Z:1.0\n"
                               + "S 1 AGAT\n"
                               + "S 2 TTGC\n"
                               + "S 3 ATGC\n"
                               + "L	1	+	2	+	0M";
        parser.parse(stringToInputStream(gfaFile));
        NodeCollection segmentMap = parser.getSegmentCollection();
        Node segment1 = segmentMap.get(1);
        Node segment3 = segmentMap.get(3);
        assertEquals(2, segment1.getLinks().iterator().next().getId());
        assertTrue(segment3.getLinks().isEmpty());
    }

    /**
     * Test if the z-index of a segment is parsed correctly.
     */
    @Test
    public void testParseZIndex() {
        final String gfaFile = "H	VN:Z:1.0\n"
                + "S 1 AGAT\n"
                + "S 2 TTGC\n"
                + "S	3	C	*	ORI:Z:TKK_02_0008.fasta	CRD:Z:TKK_02_0008.fasta	CRDCTG:Z:NZ_KK"
                + "327777.1	CTG:Z:NZ_KK327777.1	START:Z:1451\n"
                + "L	1	+	2	+	0M";
        parser.parse(stringToInputStream(gfaFile));
        NodeCollection segmentMap = parser.getSegmentCollection();<commit_msg>Fix failing test<commit_after>package io.github.programminglife2016.pl1_2016.parser;

import io.github.programminglife2016.pl1_2016.parser.nodes.Node;
import io.github.programminglife2016.pl1_2016.parser.nodes.NodeCollection;
import io.github.programminglife2016.pl1_2016.parser.nodes.SegmentParser;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
//CHECKSTYLE.OFF: MagicNumber
//CHECKSTYLE.OFF: LineLength

/**
 * Tests for the BasicServer class
 */
public class SegmentParserTest {
    private SegmentParser parser;

    /**
     * Create parser object.
     */
    @Before
    public void setUp() {
        parser = new SegmentParser();
    }

    /**
     * Test parsing a segment line to produce the correct segment.
     */
    @Test
    public void testSegmentLine() {
        parser.parse(stringToInputStream("S	1	TTGA	*	ORI:Z:MT_H37RV_BRD_V5.ref.fasta;"));
        NodeCollection segmentMap = parser.getSegmentCollection();
        Node node = segmentMap.get(1);
        assertEquals(1, node.getId());
        assertEquals("TTGA", node.getData());
    }

    /**
     * Test parsing a link line to produce the correct links.
     */
    @Test
    public void testLinkLine() {
        final String gfaFile = "H	VN:Z:1.0\n"
                               + "S 1 AGAT *\tORI:Z:MT_H37RV_BRD_V5.ref.fasta;\n"
                               + "S 2 TTGC *\tORI:Z:MT_H37RV_BRD_V5.ref.fasta;\n"
                               + "S 3 ATGC *\tORI:Z:MT_H37RV_BRD_V5.ref.fasta;\n"
                               + "L	1	+	2	+	0M";
        parser.parse(stringToInputStream(gfaFile));
        NodeCollection segmentMap = parser.getSegmentCollection();
        Node segment1 = segmentMap.get(1);
        Node segment3 = segmentMap.get(3);
        assertEquals(2, segment1.getLinks().iterator().next().getId());
        assertTrue(segment3.getLinks().isEmpty());
    }

    /**
     * Test if the z-index of a segment is parsed correctly.
     */
    @Test
    public void testParseZIndex() {
        final String gfaFile = "H	VN:Z:1.0\n"
                + "S 1 AGAT * ORI:Z:TKK_02_0008.fasta\n"
                + "S 2 TTGC * ORI:Z:TKK_02_0008.fasta\n"
                + "S	3	C	*	ORI:Z:TKK_02_0008.fasta	CRD:Z:TKK_02_0008.fasta	CRDCTG:Z:NZ_KK327777.1	CTG:Z:NZ_KK327777.1	START:Z:1451\n"
                + "L	1	+	2	+	0M";
        parser.parse(stringToInputStream(gfaFile));
        NodeCollection segmentMap = parser.getSegmentCollection();
{'fraction_non_alphanumeric': 0.11686012197521149, 'fraction_numerical': 0.041510918748770415, 'mean_word_length': 2.3983957219251337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3144416', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1653, 'n_words': 331}