<commit_before>package de.dlopes.stocks.facilitator.data.util;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class YahooSymbolIsinMappingTest {

    YahooSymbolIsinMapping _classUnderTest;
    List<Map<String,String>> stocks;
    
    @Before
    public void setup() {
        _classUnderTest = new YahooSymbolIsinMapping();
        _classUnderTest.query = _classUnderTest.new Query();
        stocks = new ArrayList<Map<String,String>>();
        
        Map<String, List<Map<String,String>>> results = new HashMap<String, List<Map<String,String>>>();
        results.put("stock", stocks);
        
        _classUnderTest.query.results = results;

    }
    
    @Test
    public void testConvertToMap() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"DE000BAY0017","Isin":"BAYN.DE"},
        //                          {"symbol":"DE000PSM7770","Isin":"PSM.DE"},
        //                          {"symbol":"DE0006231004","Isin":"DTB.DE"},
        //                          {"symbol":"DE000CBK1001","Isin":"DBK.DE"},
        //                          {"symbol":"DE000A1ML7J1","Isin":"VON.DE"}
        //                      ]}}}        
        String[] isins = new String[] { "DE0005785802", "DE000BAY0017", "DE000PSM7770", "DE0006231004", 
                                        "DE000CBK1001", "DE000A1ML7J1"};
        String[] symbols = new String[] { "FME.DE", "BAYN.DE", "PSM.DE", "DTB.DE", "DBK.DE", "VON.DE" };
        for (int i = 0; i < isins.length; i++) {
            createTestDataEntry(isins[i], symbols[i]);
        }

        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap();
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", isins.length, map.size());
        
        // assert only all mappings have been transfered
        for (int i = 0; i < isins.length; i++) {
            assertEquals("Wrong ISIN for symbol " + symbols[i] + " found!", isins[i], map.get(symbols[i]));
        }
        
    }
    
    @Test
    public void testConvertToMapWithDummyISIN() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"XX0000000000","Isin":null}
        //                      ]}}}        
        createTestDataEntry("DE0005785802", "FME.DE");
        createTestDataEntry(YahooSymbolIsinMapping.DUMMY_ISIN, null);
        
        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap();
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", 1, map.size());
        
        // assert only the mapping for the valid ISIN is in the list => that means the dummy ISIN was 
        // neglected
        assertEquals("Mapping for valid ISIN was not found in the result!", "DE0005785802", map.get("FME.DE"));
        
    }
    
    @Test
    public void testGetIsinsWithoutMapping() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"DE000BAY0017","Isin":null},
        //                          {"symbol":"DE000PSM7770","Isin":"PSM.DE"},
        //                          {"symbol":"DE0006231004","Isin":null"},
        //                          {"symbol":"DE000CBK1001","Isin":null"},
        //                          {"symbol":"DE000A1ML7J1","Isin":"VON.DE"}
        //                      ]}}}        
        String[] isins = new String[] { "DE0005785802", "DE000BAY0017", "DE000PSM7770", "DE0006231004", 
                                        "DE000CBK1001", "DE000A1ML7J1"};
        String[] symbols = new String[] { "FME.DE", null, "PSM.DE", null, null, "VON.DE" };
        int nullValues = 0;
        for (int i = 0; i < isins.length; i++) {
            createTestDataEntry(isins[i], symbols[i]);
            nullValues += symbols[i] == null ? 1 : 0; // count the null values in the symbols
        }

        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap();
        List<String> list = _classUnderTest.getIsinsWithoutMapping();
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", isins.length - nullValues, map.size());<commit_msg>a few more testcases for YahooSymbilIsinMapping.java<commit_after>package de.dlopes.stocks.facilitator.data.util;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class YahooSymbolIsinMappingTest {

    YahooSymbolIsinMapping _classUnderTest;
    List<Map<String,String>> stocks;
    
    @Before
    public void setup() {
        _classUnderTest = new YahooSymbolIsinMapping();
        _classUnderTest.query = _classUnderTest.new Query();
        stocks = new ArrayList<Map<String,String>>();
        
        Map<String, List<Map<String,String>>> results = new HashMap<String, List<Map<String,String>>>();
        results.put("stock", stocks);
        
        _classUnderTest.query.results = results;

    }
    
    @Test
    public void testConvertToMap() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"DE000BAY0017","Isin":"BAYN.DE"},
        //                          {"symbol":"DE000PSM7770","Isin":"PSM.DE"},
        //                          {"symbol":"DE0006231004","Isin":"DTB.DE"},
        //                          {"symbol":"DE000CBK1001","Isin":"DBK.DE"},
        //                          {"symbol":"DE000A1ML7J1","Isin":"VON.DE"}
        //                      ]}}}        
        String[] isins = new String[] { "DE0005785802", "DE000BAY0017", "DE000PSM7770", "DE0006231004", 
                                        "DE000CBK1001", "DE000A1ML7J1"};
        String[] symbols = new String[] { "FME.DE", "BAYN.DE", "PSM.DE", "DTB.DE", "DBK.DE", "VON.DE" };
        for (int i = 0; i < isins.length; i++) {
            createTestDataEntry(isins[i], symbols[i]);
        }

        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap();
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", isins.length, map.size());
        
        // assert only all mappings have been transfered
        for (int i = 0; i < isins.length; i++) {
            assertEquals("Wrong ISIN for symbol " + symbols[i] + " found!", isins[i], map.get(symbols[i]));
        }
        
    }
    
    @Test
    public void testConvertToMapWithDummyISIN() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"XX0000000000","Isin":null}
        //                      ]}}}        
        createTestDataEntry("DE0005785802", "FME.DE");
        createTestDataEntry(YahooSymbolIsinMapping.DUMMY_ISIN, null);
        
        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap();
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", 1, map.size());
        
        // assert only the mapping for the valid ISIN is in the list => that means the dummy ISIN was 
        // neglected
        assertEquals("Mapping for valid ISIN was not found in the result!", "DE0005785802", map.get("FME.DE"));
        
    }
    
    @Test
    public void testConvertToMapWithoutMapping() {
        
        // test data is not given on purpose!
       
        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap(false);
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", 0, map.size());
        
    }

    
    @Test
    public void testConvertToMapWithISIN2Symbol() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"DE000BAY0017","Isin":"BAYN.DE"},
        //                      ]}}}        
        createTestDataEntry("DE0005785802", "FME.DE");
        createTestDataEntry("DE000BAY0017", "BAYN.DE");
        
        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap(false);
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", 2, map.size());
        
        // assert only the mapping for the valid ISIN is in the list => that means the dummy ISIN was 
        // neglected
        assertEquals("Mapping for Symbol was not found in the result!", "FME.DE", map.get("DE0005785802"));
        assertEquals("Mapping for Symbol was not found in the result!", "BAYN.DE", map.get("DE000BAY0017"));        
        
    }
    
    @Test
    public void testGetIsinsWithoutMapping() {
        
        // setup test data: 
        //   ... "results":{"stock":
        //                      [
        //                          {"symbol":"DE0005785802","Isin":"FME.DE"},
        //                          {"symbol":"DE000BAY0017","Isin":null},
        //                          {"symbol":"DE000PSM7770","Isin":"PSM.DE"},
        //                          {"symbol":"DE0006231004","Isin":null"},
        //                          {"symbol":"DE000CBK1001","Isin":null"},
        //                          {"symbol":"DE000A1ML7J1","Isin":"VON.DE"}
        //                      ]}}}        
        String[] isins = new String[] { "DE0005785802", "DE000BAY0017", "DE000PSM7770", "DE0006231004", 
                                        "DE000CBK1001", "DE000A1ML7J1"};
        String[] symbols = new String[] { "FME.DE", null, "PSM.DE", null, null, "VON.DE" };
        int nullValues = 0;
        for (int i = 0; i < isins.length; i++) {
            createTestDataEntry(isins[i], symbols[i]);
            nullValues += symbols[i] == null ? 1 : 0; // count the null values in the symbols
        }

        // run the test:
        Map<String,String> map = _classUnderTest.covertToMap();
        List<String> list = _classUnderTest.getIsinsWithoutMapping();
        
        // assert there is only one value in the list
        assertEquals("unexpected amount of results!", isins.length - nullValues, map.size());
{'fraction_non_alphanumeric': 0.14057015666466913, 'fraction_numerical': 0.04537282766886397, 'mean_word_length': 1.7029153169828783, 'pattern_counts': {'":': 74, '<': 39, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2773807', 'n_tokens_mistral': 3698, 'n_tokens_neox': 3302, 'n_words': 692}